PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/static/script/app.js

https://github.com/cnhans/TeamToy
JavaScript | 2144 lines | 1684 code | 379 blank | 81 comment | 215 complexity | 637bc55ffbdc720dff9af28b802dc364 MD5 | raw file
Possible License(s): AGPL-1.0
  1. $.ajaxSetup
  2. ({
  3. dataType: "text"
  4. });
  5. /*
  6. send form data via ajax and return the data to callback function
  7. */
  8. function send_form( name , func )
  9. {
  10. var url = $('#'+name).attr('action');
  11. var params = {};
  12. $.each( $('#'+name).serializeArray(), function(index,value)
  13. {
  14. params[value.name] = value.value;
  15. });
  16. $.post( url , params , func );
  17. }
  18. /*
  19. send form data via ajax and show the return content to pop div
  20. */
  21. function send_form_pop( name )
  22. {
  23. return send_form( name , function( data ){ show_pop_box( data ); } );
  24. }
  25. /*
  26. send form data via ajax and show the return content in front of the form
  27. */
  28. function send_form_in( name )
  29. {
  30. return send_form( name , function( data ){ set_form_notice( name , data ) } );
  31. }
  32. function set_form_notice( name , data )
  33. {
  34. data = '<span class="label label-important">' + data + '</span>';
  35. if( $('#form_'+name+'_notice').length != 0 )
  36. {
  37. $('#form_'+name+'_notice').html(data);
  38. }
  39. else
  40. {
  41. var odiv = $( "<div class='form_notice'></div>" );
  42. odiv.attr( 'id' , 'form_'+name+'_notice' );
  43. odiv.html(data);
  44. $('#'+name).prepend( odiv );
  45. }
  46. }
  47. function show_pop_box( data , popid )
  48. {
  49. if( popid == undefined ) popid = 'lp_pop_box'
  50. //console.log($('#' + popid) );
  51. if( $('#' + popid).length == 0 )
  52. {
  53. var did = $('<div><div id="' + 'lp_pop_container' + '"></div></div>');
  54. did.attr( 'id' , popid );
  55. did.css( 'display','none' );
  56. $('body').prepend(did);
  57. }
  58. if( data != '' )
  59. $('#lp_pop_container').html(data);
  60. var left = ($(window).width() - $('#' + popid ).width())/2;
  61. $('#' + popid ).css('left',left);
  62. $('#' + popid ).css('display','block');
  63. }
  64. function hide_pop_box( popid )
  65. {
  66. if( popid == undefined ) popid = 'lp_pop_box'
  67. $('#' + popid ).css('display','none');
  68. }
  69. function remember()
  70. {
  71. $("input.remember").each( function()
  72. {
  73. // read cookie
  74. if( $.cookie( 'tt2-'+$(this).attr('name')) == 1)
  75. {
  76. $(this).attr('checked','true');
  77. }
  78. // save cookie
  79. $(this).unbind('click');
  80. $(this).bind('click',function(evt)
  81. {
  82. if( $(this).is(':checked') )
  83. $.cookie( 'tt2-'+$(this).attr('name') , 1 );
  84. else
  85. $.cookie( 'tt2-'+$(this).attr('name') , 0 );
  86. });
  87. });
  88. }
  89. function namecard()
  90. {
  91. $('.namecard').tooltipster
  92. ({
  93. 'interactive':true,
  94. 'functionBefore':load_user_tooltips
  95. });
  96. /*
  97. $("a.namecard").each( function()
  98. {
  99. });*/
  100. }
  101. function load_user_tooltips( origin , continueTooltip )
  102. {
  103. $.ajax(
  104. {
  105. type: 'POST',
  106. url: '?c=dashboard&a=user_tooltips&uid='+origin.data('uid'),
  107. success: function(data)
  108. {
  109. origin.data('tooltipsterContent', data);
  110. continueTooltip();
  111. }
  112. });
  113. }
  114. function load_buddy()
  115. {
  116. var url = '?c=buddy&a=data' ;
  117. var params = { };
  118. $.post( url , params , function( data )
  119. {
  120. // add content to list
  121. $('#buddy_list').html(data);
  122. //buddy_click();
  123. //bind_feed();
  124. done();
  125. } );
  126. doing();
  127. }
  128. function load_feed( max_id )
  129. {
  130. var url = '?c=feed&a=data' ;
  131. var params = { 'max_id':max_id };
  132. $.post( url , params , function( data )
  133. {
  134. // add content to list
  135. $('#feed_list li.more').remove();
  136. $('#feed_list').append(data);
  137. bind_feed();
  138. namecard();
  139. done();
  140. } );
  141. doing();
  142. }
  143. function load_inbox( max_id )
  144. {
  145. var url = '?c=inbox&a=data' ;
  146. var params = { 'max_id':max_id };
  147. $.post( url , params , function( data )
  148. {
  149. // add content to list
  150. $('#notice_list li.more').remove();
  151. $('#notice_list').append(data);
  152. bind_notice();
  153. namecard();
  154. done();
  155. $.post( '?c=inbox&a=mark_read' , {} );
  156. } );
  157. doing();
  158. }
  159. function load_todo( type )
  160. {
  161. var url = '?c=dashboard&a=todo_data&type=' + type ;
  162. var params = {};
  163. $.post( url , params , function( data )
  164. {
  165. // add content to list
  166. $('#todo_list_'+type).html(data);
  167. // bind event
  168. if( type != 'follow' )
  169. bind_todo();
  170. else
  171. bind_follow_todo();
  172. done();
  173. } );
  174. doing();
  175. }
  176. function todo_add( text , private , star , uid )
  177. {
  178. var url = '?c=dashboard&a=todo_add' ;
  179. if( private == 1 ) is_public = 0 ;
  180. else is_public = 1;
  181. if( star == 1 ) is_star = 1 ;
  182. else is_star = 0;
  183. var params = { 'text' : text , 'is_public' : is_public , 'is_star' : is_star , 'uid' : uid };
  184. $.post( url , params , function( data )
  185. {
  186. var data_obj = $.parseJSON( data );
  187. if( data_obj.err_code == 0 )
  188. {
  189. if( data_obj.data.other != 1 )
  190. {
  191. if( is_star == 0 )
  192. $('#todo_list_normal').prepend( $(data_obj.data.html) );
  193. else
  194. $('#todo_list_star').prepend( $(data_obj.data.html) );
  195. bind_todo();
  196. }
  197. $('#todo_form [name=content]').val('');
  198. }
  199. else
  200. {
  201. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  202. }
  203. done();
  204. } );
  205. doing();
  206. }
  207. function todo_public( tid , type )
  208. {
  209. var url = '?c=dashboard&a=todo_public' ;
  210. var params = { 'tid' : tid , 'type' : type };
  211. $.post( url , params , function( data )
  212. {
  213. var data_obj = $.parseJSON( data );
  214. if( data_obj.err_code == 0 )
  215. {
  216. if( type == 'public' )
  217. {
  218. $("ul.gbox li.private").removeClass('private').addClass('public');
  219. bind_gbox( tid );
  220. $("#t-"+tid).removeClass('red').addClass('blue');
  221. }
  222. else
  223. {
  224. $("ul.gbox li.public").removeClass('public').addClass('private');
  225. bind_gbox( tid );
  226. $("#t-"+tid).removeClass('blue').addClass('red');
  227. }
  228. }
  229. else
  230. {
  231. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  232. }
  233. done();
  234. } );
  235. doing();
  236. }
  237. function todo_forward( tid , url )
  238. {
  239. if( $('#t-'+tid).hasClass('red') ) return alert('私有TODO不能转让哦~');
  240. else
  241. {
  242. show_float_box( '选择要转让的同事' , url );
  243. // $('#people_box').modal({ 'show':true,'remote':url });
  244. }
  245. }
  246. // bind evt
  247. function bind_gbox( tid , is_public )
  248. {
  249. $(".gbox li.public a").unbind('click');
  250. $(".gbox li.public a").bind('click',function(evt)
  251. {
  252. todo_public( tid , 'private' );
  253. });
  254. $(".gbox li.private a").unbind('click');
  255. $(".gbox li.private a").bind('click',function(evt)
  256. {
  257. todo_public( tid , 'public' );
  258. });
  259. $(".gbox li.star.public a").unbind('click');
  260. $(".gbox li.star.public a").bind('click',function(evt)
  261. {
  262. todo_star( tid , 'remove' , 1 );
  263. });
  264. $(".gbox li.star.private a").unbind('click');
  265. $(".gbox li.star.private a").bind('click',function(evt)
  266. {
  267. todo_star( tid , 'remove' , 0 );
  268. });
  269. $(".gbox li.nostar.pri a").unbind('click');
  270. $(".gbox li.nostar.pri a").bind('click',function(evt)
  271. {
  272. todo_star( tid , 'add' , 0 );
  273. });
  274. $(".gbox li.nostar.pub a").unbind('click');
  275. $(".gbox li.nostar.pub a").bind('click',function(evt)
  276. {
  277. todo_star( tid , 'add' , 1 );
  278. });
  279. $(".gbox li.follow a").unbind('click');
  280. $(".gbox li.follow a").bind('click',function(evt)
  281. {
  282. todo_unfollow( tid );
  283. });
  284. $(".gbox li.nofollow a").unbind('click');
  285. $(".gbox li.nofollow a").bind('click',function(evt)
  286. {
  287. todo_follow( tid );
  288. });
  289. }
  290. function todo_star( tid , type , is_public )
  291. {
  292. var url = '?c=dashboard&a=todo_star' ;
  293. var params = { 'tid' : tid , 'type' : type };
  294. $.post( url , params , function( data )
  295. {
  296. done();
  297. var data_obj = $.parseJSON( data );
  298. if( data_obj.err_code == 0 )
  299. {
  300. if( type == 'add' )
  301. {
  302. if( is_public == 1 )
  303. $("ul.gbox li.nostar").removeClass('nostar pub pri').addClass('star public');
  304. else
  305. $("ul.gbox li.nostar").removeClass('nostar pub pri').addClass('star private');
  306. $('#todo_list_star').prepend( $("#t-"+tid) );
  307. bind_todo();
  308. bind_gbox( tid );
  309. }
  310. else
  311. {
  312. if( is_public == 1 )
  313. $("ul.gbox li.star").removeClass('public private star').addClass('nostar pub');
  314. else
  315. $("ul.gbox li.star").removeClass('public private star').addClass('nostar pri');
  316. $('#todo_list_normal').prepend( $("#t-"+tid) );
  317. bind_todo();
  318. bind_gbox( tid );
  319. }
  320. }
  321. else
  322. {
  323. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  324. }
  325. } );
  326. doing();
  327. }
  328. function todo_all_done()
  329. {
  330. if( confirm( '确定要将所有TODO都标记为完成么?不准偷懒哦!' ) )
  331. {
  332. var url = '?c=dashboard&a=todo_all_done' ;
  333. var params = { };
  334. $.post( url , params , function( data )
  335. {
  336. var data_obj = $.parseJSON( data );
  337. if( data_obj.err_code == 0 )
  338. {
  339. load_todo('normal');
  340. load_todo('star');
  341. load_todo('done');
  342. }
  343. else
  344. {
  345. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  346. }
  347. done();
  348. } );
  349. doing();
  350. }
  351. }
  352. function todo_clean()
  353. {
  354. if( confirm( '确定清除所有已完成的TODO?' ) )
  355. {
  356. var url = '?c=dashboard&a=todo_clean' ;
  357. var params = { };
  358. $.post( url , params , function( data )
  359. {
  360. var data_obj = $.parseJSON( data );
  361. if( data_obj.err_code == 0 )
  362. {
  363. load_todo('done');
  364. }
  365. else
  366. {
  367. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  368. }
  369. done();
  370. } );
  371. doing();
  372. }
  373. }
  374. // $("li#fid-"+fid+" span.cnt").text( parseInt( $("li#fid-"+fid+" span.cnt").text() ) + 1 );
  375. function feed_remove( fid )
  376. {
  377. if( confirm( '广播删除后不可恢复,继续?' ) )
  378. {
  379. var url = '?c=feed&a=feed_remove' ;
  380. var params = { 'fid' : fid };
  381. $.post( url , params , function( data )
  382. {
  383. var data_obj = $.parseJSON( data );
  384. if( data_obj.err_code == 0 )
  385. {
  386. $('#fid-'+fid).remove();
  387. }
  388. else
  389. {
  390. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  391. }
  392. done();
  393. } );
  394. doing();
  395. }
  396. }
  397. function feed_remove_comment( cid )
  398. {
  399. if( confirm( '确定删除这条评论?' ) )
  400. {
  401. var url = '?c=feed&a=feed_remove_comment' ;
  402. var params = { 'cid' : cid };
  403. $.post( url , params , function( data )
  404. {
  405. var data_obj = $.parseJSON( data );
  406. if( data_obj.err_code == 0 )
  407. {
  408. $('#cid-'+cid).remove();
  409. var fid = data_obj.data.fid;
  410. var newcnt = parseInt( $("li#fid-"+fid+" span.cnt").text() ) - 1;
  411. $("li#fid-"+fid+" span.cnt").text( newcnt );
  412. if( newcnt <= 0 ) $("li#fid-"+fid+" a.ccount").hide();
  413. }
  414. else
  415. {
  416. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  417. }
  418. done();
  419. } );
  420. doing();
  421. }
  422. }
  423. function todo_remove_comment( hid )
  424. {
  425. if( confirm( '确定删除这条评论?' ) )
  426. {
  427. var url = '?c=dashboard&a=todo_remove_comment' ;
  428. var params = { 'hid' : hid };
  429. $.post( url , params , function( data )
  430. {
  431. var data_obj = $.parseJSON( data );
  432. if( data_obj.err_code == 0 )
  433. {
  434. $('#hid-'+hid).remove();
  435. }
  436. else
  437. {
  438. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  439. }
  440. done();
  441. } );
  442. doing();
  443. }
  444. }
  445. function todo_add_comment( tid , comment )
  446. {
  447. var url = '?c=dashboard&a=todo_add_comment' ;
  448. var params = { 'tid' : tid , 'text' : comment };
  449. $.post( url , params , function( data )
  450. {
  451. var data_obj = $.parseJSON( data );
  452. if( data_obj.err_code == 0 )
  453. {
  454. $('#todo_history').prepend( $(data_obj.data.html) );
  455. $('#comment_text').val('');
  456. }
  457. else
  458. {
  459. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  460. }
  461. done();
  462. } );
  463. doing();
  464. }
  465. function feed_add_comment( fid , comment )
  466. {
  467. //
  468. var url = '?c=feed&a=feed_add_comment' ;
  469. var params = { 'fid' : fid , 'text' : comment };
  470. $.post( url , params , function( data )
  471. {
  472. var data_obj = $.parseJSON( data );
  473. if( data_obj.err_code == 0 )
  474. {
  475. $('#feed_comment').prepend( $(data_obj.data.html) );
  476. $('#fcomment_text').val('');
  477. $("li#fid-"+fid+" span.cnt").text( parseInt( $("li#fid-"+fid+" span.cnt").text() ) + 1 );
  478. $("li#fid-"+fid+" a.ccount").show();
  479. }
  480. else
  481. {
  482. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  483. }
  484. done();
  485. } );
  486. doing();
  487. }
  488. function todo_follow( tid )
  489. {
  490. var url = '?c=dashboard&a=todo_follow&type=follow' ;
  491. var params = { 'tid' : tid };
  492. $.post( url , params , function( data )
  493. {
  494. var data_obj = $.parseJSON( data );
  495. if( data_obj.err_code == 0 )
  496. {
  497. $('#t-'+tid).removeClass('nofollow').addClass('follow');
  498. bind_follow_todo();
  499. $(".gbox li.nofollow").removeClass('nofollow').addClass('follow');
  500. bind_gbox( tid );
  501. }
  502. else
  503. {
  504. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  505. }
  506. done();
  507. } );
  508. doing();
  509. }
  510. function todo_unfollow( tid )
  511. {
  512. var url = '?c=dashboard&a=todo_follow&type=unfollow' ;
  513. var params = { 'tid' : tid };
  514. $.post( url , params , function( data )
  515. {
  516. var data_obj = $.parseJSON( data );
  517. if( data_obj.err_code == 0 )
  518. {
  519. $('#t-'+tid).removeClass('follow').addClass('nofollow');
  520. bind_follow_todo();
  521. $(".gbox li.follow").removeClass('follow').addClass('nofollow');
  522. bind_gbox( tid );
  523. }
  524. else
  525. {
  526. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  527. }
  528. done();
  529. } );
  530. doing();
  531. }
  532. function todo_update( tid , text )
  533. {
  534. var url = '?c=dashboard&a=todo_update' ;
  535. var params = { 'tid' : tid , 'text' : text };
  536. $.post( url , params , function( data )
  537. {
  538. var data_obj = $.parseJSON( data );
  539. if( data_obj.err_code == 0 )
  540. {
  541. $('#t-'+tid).replaceWith( $(data_obj.data.html) );
  542. bind_todo();
  543. show_todo_detail( tid );
  544. }
  545. else
  546. {
  547. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  548. }
  549. done();
  550. } );
  551. doing();
  552. }
  553. function todo_assign( tid , uid )
  554. {
  555. //alert(tid + '~' + uid );
  556. var url = '?c=dashboard&a=todo_assign' ;
  557. var params = { 'tid' : tid , 'uid' : uid };
  558. $.post( url , params , function( data )
  559. {
  560. var data_obj = $.parseJSON( data );
  561. if( data_obj.err_code == 0 )
  562. {
  563. close_float_box();
  564. $('#t-'+tid).remove();
  565. tdboard_close();
  566. }
  567. else
  568. {
  569. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  570. }
  571. done();
  572. } );
  573. doing();
  574. }
  575. function mark_todo_done( tid )
  576. {
  577. var url = '?c=dashboard&a=todo_done' ;
  578. var params = { 'tid' : tid };
  579. $.post( url , params , function( data )
  580. {
  581. var data_obj = $.parseJSON( data );
  582. if( data_obj.err_code == 0 )
  583. {
  584. $('#todo_list_done').prepend($('#t-'+tid));
  585. bind_todo();
  586. }
  587. else
  588. {
  589. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  590. }
  591. done();
  592. } );
  593. doing();
  594. }
  595. function mark_todo_undone( tid )
  596. {
  597. var url = '?c=dashboard&a=todo_reopen' ;
  598. var params = { 'tid' : tid };
  599. $.post( url , params , function( data )
  600. {
  601. var data_obj = $.parseJSON( data );
  602. if( data_obj.err_code == 0 )
  603. {
  604. $('#todo_list_normal').prepend($('#t-'+tid));
  605. bind_todo();
  606. }
  607. else
  608. {
  609. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  610. }
  611. done();
  612. } );
  613. doing();
  614. }
  615. function show_feed_detail( fid )
  616. {
  617. // check todo_board exists or not
  618. // if not exists , create it
  619. //alert('detail-'+tid);
  620. close_all_side_board();
  621. if( $('#fdboard').length == 0 )
  622. {
  623. var did = $('<div></div>');
  624. did.attr( 'id' , 'fdboard' );
  625. did.css( 'display','none' );
  626. $('body').prepend(did);
  627. }
  628. else
  629. {
  630. $('#fdboard').html('');
  631. $('#fdboard').hide();
  632. }
  633. var xy = $("#side_container").position();
  634. $('#fdboard').css('top' , xy.top);
  635. $('#fdboard').css('left' , xy.left);
  636. $('#fdboard').fadeIn('slow');
  637. var url = '?c=feed&a=feed_detail' ;
  638. var params = { 'fid' : fid };
  639. $.post( url , params , function( data )
  640. {
  641. // add content to list
  642. $('#fdboard').html(data);
  643. $('#side_container').css('visibility','hidden');
  644. enable_at('fcomment_text');
  645. namecard();
  646. done();
  647. } );
  648. $('#fdboard').html('<h2 class="loading">Loading...</h2>');
  649. doing();
  650. }
  651. function enable_at( name )
  652. {
  653. //console.log( at_users );
  654. if( at_users.length > 0 )
  655. {
  656. $('#'+name).atWho( '@' , { 'data': at_users } );
  657. }
  658. }
  659. function show_todo_detail_center( tid )
  660. {
  661. show_float_box( 'TODO详情' , '?c=dashboard&a=todo_center&tid=' + tid );
  662. }
  663. function show_todo_detail( tid )
  664. {
  665. // check todo_board exists or not
  666. // if not exists , create it
  667. //alert('detail-'+tid);
  668. close_all_side_board();
  669. if( $('#tdboard').length == 0 )
  670. {
  671. var did = $('<div></div>');
  672. did.attr( 'id' , 'tdboard' );
  673. did.css( 'display','none' );
  674. $('body').prepend(did);
  675. }
  676. else
  677. {
  678. $('#tdboard').html('');
  679. $('#tdboard').hide();
  680. }
  681. var xy = $("#side_container").position();
  682. $('#tdboard').css('top' , xy.top);
  683. $('#tdboard').css('left' , xy.left);
  684. $('#tdboard').fadeIn('slow');
  685. var url = '?c=dashboard&a=todo_detail' ;
  686. var params = { 'tid' : tid };
  687. $.post( url , params , function( data )
  688. {
  689. // add content to list
  690. $('#tdboard').html(data);
  691. $('#side_container').css('visibility','hidden');
  692. namecard();
  693. enable_at('comment_text');
  694. done();
  695. } );
  696. $('#tdboard').html('<h2 class="loading">Loading...</h2>');
  697. doing();
  698. }
  699. function check_online()
  700. {
  701. var url = '?c=dashboard&a=user_online' ;
  702. var params = {};
  703. $.post( url , params , function( data )
  704. {
  705. var data_obj = $.parseJSON( data );
  706. //console.log( data_obj );
  707. if( data_obj.err_code == 0 )
  708. {
  709. var uids = new Array();
  710. if(!data_obj.data) return false;
  711. for( var i = 0; i < data_obj.data.length ; i++ )
  712. {
  713. uids.push(parseInt(data_obj.data[i].uid));
  714. }
  715. //console.log( uids );
  716. if( uids.length > 0 )
  717. {
  718. $('#im_buddy_list li').each( function()
  719. {
  720. if( $.inArray( parseInt($(this).attr('uid')) , uids ) == -1 )
  721. $(this).removeClass('online');
  722. else
  723. $(this).addClass('online');
  724. } );
  725. }
  726. }
  727. });
  728. }
  729. function check_notice()
  730. {
  731. var url = '?c=dashboard&a=user_unread' ;
  732. var params = {};
  733. $.post( url , params , function( data )
  734. {
  735. var data_obj = $.parseJSON( data );
  736. if( data_obj.err_code == 0 )
  737. {
  738. if( data_obj.data.all && parseInt(data_obj.data.all) > 0 )
  739. {
  740. if( data_obj.data.notice && parseInt(data_obj.data.notice) > 0 )
  741. $('div.inbox img.reddot').css( 'visibility' , 'visible' );
  742. var old_nid = parseInt($.cookie('last_nid'));
  743. var nid = parseInt(data_obj.data.nid);
  744. if( isNaN( old_nid ) ) old_nid = 0;
  745. var old_mid = parseInt($.cookie('last_mid'));
  746. var mid = parseInt(data_obj.data.mid);
  747. if( isNaN( old_mid ) ) old_mid = 0;
  748. var title = 'TeamToy有';
  749. var content = '';
  750. var send = false;
  751. if( parseInt(data_obj.data.notice) > 0 )
  752. {
  753. title += data_obj.data.notice+'条未读通知';
  754. content += data_obj.data.text;
  755. if( old_nid < 1 || old_nid < nid ) send = true;
  756. }
  757. if( parseInt(data_obj.data.message) > 0 )
  758. {
  759. title += data_obj.data.message+'条未读私信';
  760. if( old_mid < 1 || old_mid < mid ) send = true;
  761. }
  762. if( send )
  763. {
  764. $.titleAlert(title,
  765. {
  766. requireBlur:false,
  767. stopOnFocus:true,
  768. duration:10000,
  769. interval:500
  770. });
  771. play_sound();
  772. if( window.webkitNotifications && window.webkitNotifications.checkPermission() == 0 )
  773. {
  774. var notification = window.webkitNotifications.createNotification
  775. (
  776. favicon,
  777. title,
  778. content
  779. );
  780. notification.onclick = function()
  781. {
  782. window.open(site_url);
  783. };
  784. if( !$.browser.mozilla )
  785. notification.onshow = function() { setTimeout(function() {notification.close()}, 15000)};
  786. notification.show();
  787. }
  788. if( parseInt(data_obj.data.notice) > 0 ) $.cookie('last_nid',nid);
  789. if( parseInt(data_obj.data.message) > 0 ) $.cookie('last_mid',mid);
  790. }
  791. }
  792. else
  793. {
  794. $('div.inbox img.reddot').css( 'visibility' , 'hidden' );
  795. }
  796. // deal with im
  797. if( data_obj.data.message && parseInt(data_obj.data.message) > 0 )
  798. {
  799. alert_message( data_obj.data.uids.split( '|' ) );
  800. }
  801. else
  802. {
  803. blue_buddy_list();
  804. }
  805. }
  806. else
  807. {
  808. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  809. }
  810. } );
  811. }
  812. function alert_message( uids )
  813. {
  814. $('#im_header').addClass('new_message');
  815. $.each( uids , function()
  816. {
  817. // 名字加红、提升到列表顶部
  818. $('#im_blist_'+this).addClass('new_message');
  819. var tmp = $('#im_blist_'+this);
  820. $('#im_blist_'+this).remove();
  821. $('#im_buddy_list').data('jsp').getContentPane().prepend( tmp );
  822. $('#im_buddy_list').data('jsp').reinitialise();
  823. $('#im_buddy_list').data('jsp').scrollToY(0);
  824. // 重新绑定事件
  825. $('#im_buddy_list li').unbind('click');
  826. $('#im_buddy_list li').bind( 'click' , function()
  827. {
  828. $('#imkeyword').val('');
  829. $('#imkeyword').trigger('keydown');
  830. show_im_box( $(this).attr('uid') );
  831. });
  832. } );
  833. }
  834. function update_im_order()
  835. {
  836. //alert('in');
  837. var ouids = new Array();
  838. if( !kget('im_order') ) return true;
  839. ouids = kget('im_order').split('|');
  840. //ouids = ouids.reverse();
  841. for( var i = 0 ; i < ouids.length ; i++ )
  842. {
  843. var tmp = $('#im_blist_'+ouids[i]);
  844. $('#im_blist_'+ouids[i]).remove();
  845. $('#im_buddy_list').prepend( tmp );
  846. }
  847. }
  848. function save_im_order( uid )
  849. {
  850. var ouids = new Array();
  851. if( kget('im_order') )
  852. ouids = kget('im_order').split('|');
  853. ouids.push(uid);
  854. ouids = ouids.unique();
  855. kset( 'im_order' , ouids.join('|') );
  856. }
  857. function blue_buddy_list()
  858. {
  859. if( $( '#im_buddy_list li.user_line.new_message').length < 1 )
  860. if($('#im_header'))
  861. $('#im_header').removeClass('new_message');
  862. }
  863. function cast_send( text )
  864. {
  865. //alert( text );
  866. var url = '?c=feed&a=cast' ;
  867. var params = { 'text' : text };
  868. $.post( url , params , function( data )
  869. {
  870. var data_obj = $.parseJSON( data );
  871. if( data_obj.err_code == 0 )
  872. {
  873. $('#feed_list').prepend( $(data_obj.data.html) );
  874. bind_feed();
  875. $('#cast_form [name=text]').val('');
  876. }
  877. else
  878. {
  879. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  880. }
  881. done();
  882. } );
  883. doing();
  884. }
  885. function tdboard_close()
  886. {
  887. $('#tdboard').fadeOut('fast');
  888. $('#side_container').css('visibility','visible');
  889. }
  890. function fdboard_close()
  891. {
  892. $('#fdboard').fadeOut('fast');
  893. $('#side_container').css('visibility','visible');
  894. }
  895. function bind_follow_todo()
  896. {
  897. // this -- > a
  898. // this.parentNode --> .todo_row
  899. // this.parentNode.parentNode ---> .todo_fav
  900. // this.parentNode.parentNode.parentNode -----> li
  901. $('#todo_list_follow li a.item').each( function()
  902. {
  903. $(this.parentNode).unbind( 'click' );
  904. $(this.parentNode).bind( 'click' , function(evt)
  905. {
  906. evt.stopPropagation();
  907. show_todo_detail( $('#'+this.parentNode.parentNode.id).attr('tid') );
  908. return false;
  909. } );
  910. $('#'+this.parentNode.parentNode.parentNode.id).unbind('click');
  911. $('#'+this.parentNode.parentNode.parentNode.id).bind('click' , function( )
  912. {
  913. if( $(this).hasClass('nofollow') )
  914. todo_follow( $(this).attr('tid') );
  915. else
  916. todo_unfollow( $(this).attr('tid') );
  917. });
  918. });
  919. }
  920. function bind_todo()
  921. {
  922. //alert('in');
  923. $('li a.todo_play').unbind('click');
  924. $('li a.todo_play').bind('click' , function(evt)
  925. {
  926. var mtype;
  927. if( $(this.parentNode).hasClass('ing') )
  928. mtype = 'pause';
  929. else
  930. mtype = 'start';
  931. var tid = $(this).attr('tid');
  932. var url = '?c=dashboard&a=todo_start&tid=' + tid + '&type=' + mtype ;
  933. var params = {};
  934. $.post( url , params , function( data )
  935. {
  936. var data_obj = $.parseJSON( data );
  937. if( data_obj.err_code == 0 )
  938. {
  939. if( mtype == 'pause' )
  940. {
  941. $('#t-'+tid).removeClass('ing');
  942. console.log('remove class');
  943. }
  944. else
  945. {
  946. $('#t-'+tid).addClass('ing');
  947. console.log('add class');
  948. }
  949. // buddy_click();
  950. done();
  951. }
  952. else
  953. {
  954. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  955. }
  956. } );
  957. doing();
  958. evt.stopPropagation();
  959. });
  960. $('#todo_list_star li a.item,#todo_list_normal li a.item,#todo_list_done li a.item').each( function()
  961. {
  962. // this -- > a
  963. // this.parentNode --> .todo_row
  964. // this.parentNode.parentNode ---> .todo_fav
  965. // this.parentNode.parentNode.parentNode -----> li
  966. $(this.parentNode).unbind( 'click' );
  967. $(this.parentNode).bind( 'click' , function(evt)
  968. {
  969. evt.stopPropagation();
  970. show_todo_detail( $('#'+this.parentNode.parentNode.id).attr('tid') );
  971. return false;
  972. } );
  973. $(this.parentNode.parentNode).unbind( 'click' );
  974. $(this.parentNode.parentNode).bind( 'click' , function(evt)
  975. {
  976. evt.stopPropagation();
  977. if( this.parentNode.parentNode.id != 'todo_list_done' )
  978. {
  979. var is_public = 0;
  980. if( $('#'+this.parentNode.id).hasClass('blue') )
  981. is_public = 1;
  982. if( this.parentNode.parentNode.id == 'todo_list_star' )
  983. todo_star( $('#'+this.parentNode.id).attr('tid') , 'remove' , is_public );
  984. else
  985. todo_star( $('#'+this.parentNode.id).attr('tid') , 'add' , is_public );
  986. }
  987. return false;
  988. } );
  989. $('#'+this.parentNode.parentNode.parentNode.id).unbind('click');
  990. $('#'+this.parentNode.parentNode.parentNode.id).bind('click' , function( )
  991. {
  992. if( this.parentNode.id == 'todo_list_done' )
  993. {
  994. mark_todo_undone( $(this).attr('tid') );
  995. }
  996. else
  997. {
  998. mark_todo_done( $(this).attr('tid') );
  999. //
  1000. }
  1001. });
  1002. });
  1003. }
  1004. function bind_feed()
  1005. {
  1006. $('#feed_list li.todo .hotarea').each( function()
  1007. {
  1008. $(this).css({'cursor':'pointer'});
  1009. $(this).unbind( 'click' );
  1010. $(this).bind( 'click' , function(evt)
  1011. {
  1012. evt.stopPropagation();
  1013. show_todo_detail( $('#'+this.parentNode.id).attr('tid') );
  1014. return false;
  1015. } );
  1016. });
  1017. $('#feed_list li.cast .hotarea').each( function()
  1018. {
  1019. $(this).css({'cursor':'pointer'});
  1020. $(this).unbind( 'click' );
  1021. $(this).bind( 'click' , function(evt)
  1022. {
  1023. evt.stopPropagation();
  1024. show_feed_detail( $('#'+this.parentNode.id).attr('fid') );
  1025. return false;
  1026. } );
  1027. });
  1028. }
  1029. function bind_notice()
  1030. {
  1031. $('#notice_list li.todo').each( function()
  1032. {
  1033. $(this).css({'cursor':'pointer'});
  1034. $(this).unbind( 'click' );
  1035. $(this).bind( 'click' , function(evt)
  1036. {
  1037. evt.stopPropagation();
  1038. show_todo_detail( $('#'+this.id).attr('tid') );
  1039. return false;
  1040. } );
  1041. });
  1042. $('#notice_list li.cast').each( function()
  1043. {
  1044. $(this).css({'cursor':'pointer'});
  1045. $(this).unbind( 'click' );
  1046. $(this).bind( 'click' , function(evt)
  1047. {
  1048. evt.stopPropagation();
  1049. show_feed_detail( $('#'+this.id).attr('fid') );
  1050. return false;
  1051. } );
  1052. });
  1053. }
  1054. function buddy_search()
  1055. {
  1056. $('#buddy_key').bind( 'keyup keydown' , function(evt)
  1057. {
  1058. if( $('#buddy_key').val() != '' )
  1059. {
  1060. $('#buddy_list li.user').each(function()
  1061. {
  1062. if( ($(this).attr('pinyin').indexOf( $('#buddy_key').val() ) < 0)
  1063. && ( $(this).attr('user').indexOf( $('#buddy_key').val() ) < 0 ))
  1064. $(this).css('display','none');
  1065. else
  1066. $(this).css('display','block');
  1067. });
  1068. }
  1069. else
  1070. {
  1071. $('#buddy_list li.user').each(function()
  1072. {
  1073. $(this).css('display','block');
  1074. });
  1075. }
  1076. });
  1077. }
  1078. function buddy_click()
  1079. {
  1080. $('li.user').unbind('click');
  1081. $('li.user').bind('click',function(evt)
  1082. {
  1083. $(this).toggleClass('selected');
  1084. buddy_build_names();
  1085. if( $("li.selected").length > 0 )
  1086. $('#buddy_mulit_box').slideDown();
  1087. else
  1088. $('#buddy_mulit_box').slideUp();
  1089. });
  1090. }
  1091. function buddy_build_names()
  1092. {
  1093. $("#namelist").empty();
  1094. $('li.user.selected').each( function()
  1095. {
  1096. $("#namelist").append( $('<li class="nameitem" uid="' + $(this).attr('uid') + '"><i class="icon-user"></i>'+ $(this).attr('user') +'</li>') )
  1097. });
  1098. }
  1099. function cast_at_check()
  1100. {
  1101. $('#cast_text').bind( 'keydown keyup' , function(evt)
  1102. {
  1103. if( /@/.test( $('#cast_text').val() ) ) $('#cast_user_tips').text('点名的人会收到通知');
  1104. else $('#cast_user_tips').text('所有人都会收到通知');
  1105. if( $('#cast_text').val() == '' ) $('#cast_form [type=submit]').attr('disabled',true);
  1106. else $('#cast_form [type=submit]').attr('disabled',false);
  1107. });
  1108. }
  1109. function admin_user_on( uid )
  1110. {
  1111. return admin_user( uid , 1 );
  1112. }
  1113. function admin_user_off( uid )
  1114. {
  1115. return admin_user( uid , 0 );
  1116. }
  1117. function admin_user( uid , on )
  1118. {
  1119. var url = '?c=buddy&a=admin_user&set=' + on ;
  1120. var params = { 'uid' : uid };
  1121. $.post( url , params , function( data )
  1122. {
  1123. var data_obj = $.parseJSON( data );
  1124. if( data_obj.err_code == 0 )
  1125. {
  1126. $('li#uid-'+uid).replaceWith( $(data_obj.data.html) );
  1127. // buddy_click();
  1128. }
  1129. else
  1130. {
  1131. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1132. }
  1133. } );
  1134. }
  1135. function plugin_turn( fold_name , name , obj )
  1136. {
  1137. var on , doo ;
  1138. if( $(obj).is(':checked') ) on = 1 ;
  1139. else on = 0;
  1140. if( on == 0 )
  1141. {
  1142. if( confirm( '停用'+name+'插件后相关的功能将不可用,继续?' ) )
  1143. doo = 1
  1144. }
  1145. else doo = 1;
  1146. if( doo == 1 )
  1147. {
  1148. var url = '?c=pluglist&a=turn&on=' + on + '&folder_name=' + fold_name ;
  1149. var params = {};
  1150. $.post( url , params , function( data )
  1151. {
  1152. var data_obj = $.parseJSON( data );
  1153. if( data_obj.err_code == 0 )
  1154. {
  1155. location='?c=pluglist';
  1156. }
  1157. else
  1158. {
  1159. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1160. }
  1161. });
  1162. }
  1163. }
  1164. function save_password()
  1165. {
  1166. if( $('#password_form [name=oldpassword]').val() == '' )
  1167. {
  1168. alert( '原密码不能为空' );
  1169. return false;
  1170. }
  1171. if( $('#password_form [name=newpassword]').val() == '' )
  1172. {
  1173. alert( '新密码不能为空' );
  1174. return false;
  1175. }
  1176. if( $('#password_form [name=newpassword]').val() != $('#password_form [name=newpassword2]').val() )
  1177. {
  1178. alert( '两次输入的密码不一致' );
  1179. return false;
  1180. }
  1181. send_form( 'password_form' , function(data){ password_updated( data ); } )
  1182. }
  1183. function password_updated( data )
  1184. {
  1185. var data_obj = $.parseJSON( data );
  1186. if( data_obj.err_code == 0 )
  1187. {
  1188. alert('密码修改成功,请使用新密码登入');
  1189. close_float_box();
  1190. location = '?c=guest&a=logout';
  1191. }
  1192. else
  1193. {
  1194. alert('服务器通信失败,请稍后再试'+data);
  1195. }
  1196. }
  1197. function profile_updated( data )
  1198. {
  1199. var data_obj = $.parseJSON( data );
  1200. if( data_obj.err_code == 0 )
  1201. {
  1202. close_float_box();
  1203. }
  1204. else
  1205. {
  1206. if( data_obj.err_code == 10006 )
  1207. alert('Email和手机号都是必填项');
  1208. else
  1209. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1210. }
  1211. }
  1212. function admin_close_user( uid )
  1213. {
  1214. if( confirm( '确定要关闭该用户么?关闭后此用户资料将保留,但不能登入系统' ) )
  1215. {
  1216. var url = '?c=buddy&a=user_close' ;
  1217. var params = { 'uid' : uid };
  1218. $.post( url , params , function( data )
  1219. {
  1220. //console.log( data );
  1221. var data_obj = $.parseJSON( data );
  1222. //console.log( data_obj );
  1223. if( data_obj.err_code == 0 )
  1224. {
  1225. $('li#uid-'+uid).remove();
  1226. }
  1227. else
  1228. {
  1229. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1230. }
  1231. } );
  1232. }
  1233. }
  1234. var at_users = new Array();
  1235. function load_im_buddy_list()
  1236. {
  1237. var url = '?c=dashboard&a=im_buddy_list' ;
  1238. var params = {};
  1239. $.post( url , params , function( data )
  1240. {
  1241. var data_obj = $.parseJSON( data );
  1242. if( data_obj.err_code == 0 )
  1243. {
  1244. $('#im_buddy_list').html( data_obj.data.html );
  1245. update_im_order();
  1246. $('#im_header').bind( 'click' , toggle_im );
  1247. if( $.cookie('im_hide') == 1 ) toggle_im();
  1248. $('#im').show();
  1249. $('#im_buddy_list').jScrollPane();
  1250. $('#im_buddy_list li').unbind('click');
  1251. $('#im_buddy_list li').bind( 'click' , function()
  1252. {
  1253. $('#imkeyword').val('');
  1254. $('#imkeyword').trigger('keydown');
  1255. show_im_box( $(this).attr('uid') );
  1256. });
  1257. $('#imkeyword').bind('keyup keydown' , function(evt)
  1258. {
  1259. if( $('#imkeyword').val() != '' )
  1260. {
  1261. $('#im_buddy_list li.user_line').each(function()
  1262. {
  1263. if( ($(this).attr('pinyin').indexOf( $('#imkeyword').val() ) < 0)
  1264. && ( $(this).attr('user').indexOf( $('#imkeyword').val() ) < 0 ))
  1265. $(this).css('display','none');
  1266. else
  1267. $(this).css('display','block');
  1268. });
  1269. }
  1270. else
  1271. {
  1272. $('#im_buddy_list li.user_line').each(function()
  1273. {
  1274. $(this).css('display','block');
  1275. });
  1276. }
  1277. });
  1278. $('#im_buddy_list li.user_line').each(function()
  1279. {
  1280. at_users.push( { 'name':$(this).attr('user')
  1281. , 'pinyin':$(this).attr('pinyin')
  1282. , 'value':$(this).attr('user')
  1283. , 'id':$(this).attr('uid')
  1284. } );
  1285. });
  1286. // add groups
  1287. var url = '?c=buddy&a=groups' ;
  1288. $.post( url , {} , function( data2 )
  1289. {
  1290. var data_obj2 = $.parseJSON( data2 );
  1291. if( data_obj2 && data_obj2.err_code == 0 && data_obj2.data != null )
  1292. {
  1293. $.each(data_obj2.data , function(k,v)
  1294. {
  1295. at_users.push({'name':v});
  1296. });
  1297. }
  1298. });
  1299. if( $('#cast_text') ) enable_at('cast_text');
  1300. }
  1301. else
  1302. {
  1303. console.log('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1304. }
  1305. });
  1306. }
  1307. var im_check_ref;
  1308. function show_im_box( uid )
  1309. {
  1310. var url = '?c=dashboard&a=im_buddy_box&uid=' + uid ;
  1311. var params = {};
  1312. $.post( url , params , function( data )
  1313. {
  1314. var data_obj = $.parseJSON( data );
  1315. if( data_obj.err_code == 0 )
  1316. {
  1317. save_im_order( uid );
  1318. if( $('#im_box_'+uid).length > 0 )
  1319. $('#im_box_'+uid).replaceWith( data_obj.data.html );
  1320. else
  1321. $('#im_area_list').prepend( data_obj.data.html );
  1322. namecard();
  1323. $('#im_area_list li').hide();
  1324. $('#im_area_list li#im_box_'+uid).show();
  1325. $('#im_box').show();
  1326. $('#im_area_list li#im_box_'+uid+' .im_history').jScrollPane();
  1327. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').scrollToBottom();
  1328. $('#im_area_list li#im_box_'+uid+' .im_form_textarea').bind( 'keypress' , function(e)
  1329. {
  1330. if( e.which == 13 )
  1331. {
  1332. var text = $('#im_area_list li#im_box_'+uid+' .im_form_textarea').val();
  1333. var url = '?c=dashboard&a=im_send&uid=' + uid + '&text=' + encodeURIComponent( text ) ;
  1334. var params = {};
  1335. $.post( url , params , function( data )
  1336. {
  1337. done();
  1338. var data_obj = $.parseJSON( data );
  1339. if( data_obj.err_code == 0 )
  1340. {
  1341. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').getContentPane().append( data_obj.data.html );
  1342. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').reinitialise();
  1343. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').scrollToBottom();
  1344. $('#im_area_list li#im_box_'+uid+' .im_form_textarea').val('');
  1345. // alert('send text'++'TO'+$(this).attr('uid'));
  1346. }
  1347. else
  1348. {
  1349. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1350. }
  1351. $('#im_area_list li#im_box_'+uid+' .im_form_textarea').attr('disabled',false);
  1352. });
  1353. doing();
  1354. $('#im_area_list li#im_box_'+uid+' .im_form_textarea').attr('disabled','disabled');
  1355. }
  1356. } );
  1357. var url = '?c=dashboard&a=im_history&uid=' + uid ;
  1358. var params = {};
  1359. $.post( url , params , function( data )
  1360. {
  1361. //alert(data+'~in');
  1362. //alert($('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').getContentPane() + '~ini');
  1363. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').getContentPane().append( data );
  1364. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').reinitialise();
  1365. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').scrollToBottom();
  1366. im_check_ref = setInterval( function(){ check_im( uid ); } , 1000*10 );
  1367. });
  1368. //check_im( uid );
  1369. $( '#im_blist_'+uid ).removeClass('new_message');
  1370. blue_buddy_list();
  1371. }
  1372. else
  1373. {
  1374. console.log('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1375. }
  1376. });
  1377. //$('#im_area_list').html('<li>'+ uid +'</li>');
  1378. //$('#im_box').show();
  1379. //alert( uid );
  1380. }
  1381. function user_reset_password( uid , uname )
  1382. {
  1383. if( confirm( '确定要重置'+uname+'的密码?' ) )
  1384. {
  1385. var url = '?c=dashboard&a=user_reset_password&uid=' + uid ;
  1386. var params = {};
  1387. $.post( url , params , function( data )
  1388. {
  1389. var data_obj = $.parseJSON( data );
  1390. //console.log( data_obj );
  1391. if( data_obj.err_code == 0 )
  1392. {
  1393. // 显示新密码
  1394. noty(
  1395. {
  1396. layout:'topRight',
  1397. text:uname+'的密码已经被重置为' + data_obj.data.newpass,
  1398. closeWith:['button'],
  1399. buttons: [
  1400. {
  1401. addClass: 'btn btn-primary btn-small', text: '关闭', onClick: function($noty)
  1402. {
  1403. $noty.close()
  1404. }
  1405. }]
  1406. });
  1407. }
  1408. else
  1409. {
  1410. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1411. }
  1412. });
  1413. }
  1414. }
  1415. function check_im( uid )
  1416. {
  1417. var url = '?c=dashboard&a=get_fresh_chat&uid=' + uid ;
  1418. var params = {};
  1419. $.post( url , params , function( data )
  1420. {
  1421. //alert(data+'~in');
  1422. //alert($('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').getContentPane() + '~ini');
  1423. if( data )
  1424. {
  1425. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').getContentPane().append( data );
  1426. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').reinitialise();
  1427. $('#im_area_list li#im_box_'+uid+' .im_history').data('jsp').scrollToBottom();
  1428. $.titleAlert("有新的私信啦",
  1429. {
  1430. requireBlur:false,
  1431. stopOnFocus:true,
  1432. duration:10000,
  1433. interval:500
  1434. });
  1435. play_sound();
  1436. }
  1437. //im_check_ref = setInterval( function( uid ){ check_im( uid ); } , 100000 );
  1438. });
  1439. }
  1440. function close_im_box()
  1441. {
  1442. $('#im_box').hide();
  1443. clearInterval( im_check_ref );
  1444. //$('#im_area_list').html('');
  1445. }
  1446. function toggle_im()
  1447. {
  1448. if( $('#im').hasClass('peep') )
  1449. {
  1450. $('#im').removeClass('peep');
  1451. $('#im_swith').html('&minus;');
  1452. $.cookie('im_hide' , 0 );
  1453. }
  1454. else
  1455. {
  1456. $('#im').addClass('peep');
  1457. $('#im_swith').html('&plus;');
  1458. $.cookie('im_hide' , 1 );
  1459. }
  1460. }
  1461. function check_version()
  1462. {
  1463. var url = '?c=dashboard&a=check_version' ;
  1464. var params = {};
  1465. $.post( url , params , function( data )
  1466. {
  1467. var data_obj = $.parseJSON( data );
  1468. done();
  1469. if( data_obj.err_code == 0 )
  1470. {
  1471. // error in ie , becoz .new
  1472. if( data_obj.data.new && parseInt( data_obj.data.new ) == 1 )
  1473. {
  1474. if( confirm( '有新的版本'+data_obj.data.version + '['+ data_obj.data.info +']。升级到最新版?' ) )
  1475. {
  1476. location = '?c=dashboard&a=upgrade';
  1477. }
  1478. }
  1479. else
  1480. {
  1481. alert('当前版本已经是最新了');
  1482. }
  1483. }
  1484. else
  1485. {
  1486. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1487. }
  1488. } );
  1489. doing();
  1490. }
  1491. function user_added( data )
  1492. {
  1493. var data_obj = $.parseJSON( data );
  1494. //console.log( data_obj );
  1495. if( data_obj.err_code == 0 )
  1496. {
  1497. //$('li#uid-'+uid).remove();
  1498. $('#buddy_list').append( $(data_obj.data.html) );
  1499. $('html, body').animate({
  1500. scrollTop: $("footer").offset().top
  1501. }, 1000);
  1502. $('#buddy_form [type=text]').val('');
  1503. $('#buddy_form [type=password]').val('');
  1504. buddy_click();
  1505. }
  1506. else
  1507. {
  1508. if( data_obj.err_code == 100002 )
  1509. {
  1510. return alert('所有字段均为必填项,请认真填写');
  1511. }
  1512. else
  1513. {
  1514. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1515. }
  1516. }
  1517. }
  1518. function edit_tag( uid )
  1519. {
  1520. $('#t-tags-'+uid).hide();
  1521. $('#t-tags-link-'+uid).hide();
  1522. $('#t-tags-edit-'+uid).show();
  1523. if( $('#t-tags-input-'+uid+'_tag').length < 1 )
  1524. $('#t-tags-input-'+uid).tagsInput({'defaultText':'添加分组名称'});
  1525. }
  1526. function save_tag( uid )
  1527. {
  1528. var url = '?c=buddy&a=update_groups&uid='+uid+'&groups='+encodeURIComponent($('#t-tags-input-'+uid).val()) ;
  1529. var params = {};
  1530. $.post( url , params , function( data )
  1531. {
  1532. var data_obj = $.parseJSON( data );
  1533. done();
  1534. if( data_obj.err_code == 0 )
  1535. {
  1536. $('#uid-'+uid).replaceWith( $(data_obj.data.html) );
  1537. }
  1538. else
  1539. {
  1540. alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1541. }
  1542. } );
  1543. doing();
  1544. }
  1545. function cancel_tag( uid )
  1546. {
  1547. $('#t-tags-'+uid).show();
  1548. $('#t-tags-link-'+uid).show();
  1549. $('#t-tags-edit-'+uid).hide();
  1550. }
  1551. function show_im_all_history( uid , uname )
  1552. {
  1553. show_float_box( '我和'+ uname +'的聊天记录' , '?c=dashboard&a=im_all&uid='+uid );
  1554. }
  1555. function im_next_btn()
  1556. {
  1557. if( parseInt(im_his_more) == 1 )
  1558. {
  1559. $('#im_next_link').addClass('btn-primary');
  1560. $('#im_next_link').removeClass('disable');
  1561. }
  1562. else
  1563. {
  1564. $('#im_next_link').removeClass('btn-primary');
  1565. $('#im_next_link').addClass('disable');
  1566. }
  1567. }
  1568. function im_all_update( uid , keyword , max )
  1569. {
  1570. // im_all_json
  1571. var url = '?c=dashboard&a=im_all_json&uid='+uid+'&keyword='+encodeURIComponent(keyword)+'&max_id='+max ;
  1572. var params = {};
  1573. $.post( url , params , function( data )
  1574. {
  1575. var data_obj = $.parseJSON( data );
  1576. done();
  1577. if( data_obj.err_code == 0 )
  1578. {
  1579. $('#im_all_text_div').html( $(data_obj.data.html) );
  1580. $('#im_all_text_div').animate
  1581. ({
  1582. scrollTop: 0},
  1583. 'fast');
  1584. im_his_min = parseInt(data_obj.data.min);
  1585. im_his_more = parseInt(data_obj.data.more);
  1586. im_next_btn();
  1587. }
  1588. else
  1589. {
  1590. //alert('API调用错误,请稍后再试。错误号'+data_obj.err_code + ' 错误信息 ' + data_obj.message);
  1591. }
  1592. } );
  1593. doing();
  1594. }
  1595. function doing()
  1596. {
  1597. $("li#doing_gif").show();
  1598. }
  1599. function done()
  1600. {
  1601. $("li#doing_gif").hide();
  1602. }
  1603. function show_float_box( title , url )
  1604. {
  1605. $('#float_box').off('show');
  1606. $('#float_box').on('show', function ()
  1607. {
  1608. $('#float_box_title').text(title);
  1609. $('#float_box .modal-body').load(url);
  1610. })
  1611. $('#float_box .modal-body').html('<div class="muted"><center>Loading</center>');
  1612. $('#float_box').modal({ 'show':true });
  1613. }
  1614. function close_float_box()
  1615. {
  1616. $('#float_box').modal('hide');
  1617. }
  1618. function assign_chooser()
  1619. {
  1620. if( $('#todo_form [name=private]:checked').val() == 1 )
  1621. {
  1622. alert( '私有TODO不能添加给别人' );
  1623. return false;
  1624. }
  1625. show_float_box( '点击你要加TODO的同事' , '?c=dashboard&a=people_box&jsfunc=assign_set&self=1' );
  1626. }
  1627. function assign_set( tid , uid , uname )
  1628. {
  1629. $('#assign_chooser_span a').html('给 <i class="icon-user"></i> '+uname);
  1630. $('#todo_assign_uid').val(uid);
  1631. close_float_box();
  1632. }
  1633. function at_chooser()
  1634. {
  1635. show_float_box( '请在选择你要点名的同事' , '?c=dashboard&a=people_box&jsfunc=cast_at_selected&multi=1' );
  1636. }
  1637. function cast_at_selected( uids , unames )
  1638. {
  1639. $.each( unames , function()
  1640. {
  1641. //alert( this );
  1642. var that = this;
  1643. $('#cast_text').val( $('#cast_text').val() + ' @'+that );
  1644. } );
  1645. close_float_box();
  1646. $('#cast_text').focus();
  1647. }
  1648. function close_all_side_board()
  1649. {
  1650. $('#tdboard').hide();
  1651. $('#fdboard').hide();
  1652. //$('#side_container').css( 'visibility' , 'visible' );
  1653. }
  1654. function get_img_src( file , fn )
  1655. {
  1656. if ($.browser.msie) {
  1657. if ($.browser.version <= 6) {
  1658. fn(file.value);
  1659. return;
  1660. } else if ($.browser.version <= 8) {
  1661. var src = '';
  1662. file.select();
  1663. try {
  1664. src = document.selection.createRange().text;
  1665. } finally {
  1666. document.selection.empty();
  1667. }
  1668. src = src.replace(/[)'"%]/g, function(s){ return escape(escape(s)); });
  1669. fn(src);
  1670. return;
  1671. }
  1672. }
  1673. if ($.browser.mozilla) {
  1674. var oFile = file.files[0];
  1675. if (oFile.getAsDataURL) {
  1676. fn(oFile.getAsDataURL());
  1677. return;
  1678. }
  1679. }
  1680. try {
  1681. var oFile = file.files[0];
  1682. var oFReader = new FileReader();
  1683. oFReader.onload = function (oFREvent) {
  1684. /*
  1685. var img = new Image();
  1686. img.onload = function( evt )
  1687. {
  1688. }
  1689. img.src = oFREvent.target.result;
  1690. */
  1691. fn(oFREvent.target.result);
  1692. };
  1693. oFReader.onerror = function(a) {
  1694. fn(options.okImg);
  1695. };
  1696. oFReader.readAsDataURL(oFile);
  1697. } catch(e) {
  1698. fn(options.okImg);
  1699. }
  1700. }
  1701. function kset( key , value )
  1702. {
  1703. if( window.localStorage )
  1704. return window.localStorage.setItem( key , value );
  1705. }
  1706. function kget( key )
  1707. {
  1708. if( window.localStorage )
  1709. return window.localStorage.getItem( key );
  1710. }
  1711. function kremove( key )
  1712. {
  1713. if( window.localStorage )
  1714. return window.localStorage.removeItem( key );
  1715. }
  1716. Array.prototype.unique =
  1717. function() {
  1718. var a = [];
  1719. var l = this.length;
  1720. for(var i=0; i<l; i++) {
  1721. for(var j=i+1; j<l; j++) {
  1722. // If this[i] is found later in the array
  1723. if (this[i] === this[j])
  1724. j = ++i;
  1725. }
  1726. a.push(this[i]);
  1727. }
  1728. return a;
  1729. };
  1730. function play_sound()
  1731. {
  1732. if( $.cookie( 'tt2-sound-enable' ) == 1 )
  1733. document.getElementById('ttsoundplayer').play();
  1734. }
  1735. if( $.cookie( 'tt2-sound-enable' ) != 1 && $.cookie( 'tt2-sound-enable' ) != 0 )
  1736. $.cookie( 'tt2-sound-enable' , 1 );
  1737. /* post demo
  1738. $.post( 'url&get var' , { 'post':'value'} , function( data )
  1739. {
  1740. var data_obj = jQuery.parseJSON( data );
  1741. console.log( data_obj );
  1742. if( data_obj.err_code == 0 )
  1743. {
  1744. }
  1745. else
  1746. {
  1747. }
  1748. } );
  1749. */