PageRenderTime 46ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/static/script/app.js

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