timesheet source code
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1567 lines
44KB

  1. (function ($) {
  2. $(function () {
  3. // http://davidwalsh.name/javascript-debounce-function
  4. function debounce(func, wait, immediate) {
  5. var timeout;
  6. return function () {
  7. var context = this, args = arguments;
  8. var later = function () {
  9. timeout = null;
  10. if (!immediate)
  11. func.apply(context, args);
  12. };
  13. var callNow = immediate && !timeout;
  14. clearTimeout(timeout);
  15. timeout = setTimeout(later, wait);
  16. if (callNow)
  17. func.apply(context, args);
  18. };
  19. };
  20. /*____________________________________________________________________________________*/
  21. class People{
  22. constructor(selector, template, data){
  23. this.selector = selector;
  24. this.data = data;
  25. this.template = template;
  26. // this.sample_people = {
  27. // login: '01515b52-6936-46b2-a000-9ad4cd7a5b50',
  28. // firstname: "first",
  29. // lastname: "last",
  30. // phone: '041122221',
  31. // email: 'abc@gmail.com',
  32. // pay: 0,
  33. // hour: 12,
  34. // OT: 3,
  35. // petrol: 50,
  36. // rating: 1,
  37. // };
  38. this.load_data(this.data);
  39. }
  40. load_data(data){
  41. var template = $(this.template).html();
  42. var html = Mustache.render(template, data);
  43. $(this.selector).html(html);
  44. //save it
  45. $(this.selector).data({obj:this, data:data});
  46. //draw rating star
  47. this.set_ratings(this.data.rating);
  48. this.set_unconfirmed_job(this.data.unconfirmedjob);
  49. }
  50. set_ratings(num){
  51. for (var i=1; i<= 5; i++){
  52. if (i <=num){
  53. $(this.selector + " div[name='rating'] span:nth-child(" +i+ ")").addClass('checked');
  54. }else{
  55. $(this.selector + " div[name='rating'] span:nth-child(" +i+ ")").removeClass('checked');
  56. }
  57. }
  58. this.data.rating = num;
  59. }
  60. set_unconfirmed_job(num){
  61. if( num == 0 )
  62. $(this.selector + " span[name='badge']").hide();
  63. else
  64. $(this.selector + " span[name='badge']").show();
  65. this.data.unconfirmedjob = num;
  66. }
  67. reset_summary() {
  68. this.summary = {
  69. wages : 0,
  70. normal_hour : 0,
  71. ot_hour : 0,
  72. petrol : 0,
  73. };
  74. this.update_summary_in_gui();
  75. }
  76. add_payment_summary(ps)
  77. {
  78. //{ot: false, hour: "2.67", money: "76.90"}
  79. this.summary.wages += ps.money;
  80. if (! ps.ot )
  81. this.summary.normal_hour += ps.hour;
  82. else
  83. this.summary.ot_hour += ps.hour;
  84. this.update_summary_in_gui();
  85. }
  86. update_summary_in_gui()
  87. {
  88. var msg = '$' + this.summary.wages.toFixed(2);
  89. $(this.selector).find('div[name="wages"]').html(msg);
  90. msg = this.summary.normal_hour.toFixed(2) + '+' +this.summary.ot_hour.toFixed(2) + 'hr';
  91. $(this.selector).find('div[name="hours"]').html(msg);
  92. msg = 'petrol:' + this.summary.petrol.toFixed(2) + 'km';
  93. $(this.selector).find('div[name="petrol"]').html(msg);
  94. }
  95. }//end of class People
  96. function bts_staff_html(data){
  97. var template = $('#staff_item').html();
  98. var head = '<div class="peopleitem" id="p'+ data.login +'">';
  99. r = head + '</div>' ;
  100. return r;
  101. }
  102. function bts_client_html(data){
  103. var template = $('#client_item').html();
  104. var head = '<div class="peopleitem" id="p'+ data.login +'">';
  105. r = head + '</div>' ;
  106. return r;
  107. }
  108. function sample_staff(){
  109. for (var i=1; i<100; i++){
  110. var sample_people = {
  111. login: '01515b52-6936-46b2-a000-9ad4cd7a5b50' +i,
  112. firstname: "first"+i,
  113. lastname: "last",
  114. mobile: '041122221' +i,
  115. email: 'abc@gmail.com' + i,
  116. wages: 0,
  117. hour: i,
  118. OT: 3,
  119. petrol: 50 +i,
  120. rating: Math.floor(Math.random() * Math.floor(5)),
  121. unconfirmedjob: Math.floor(Math.random() * Math.floor(30)),
  122. };
  123. var html = bts_staff_html(sample_people);
  124. jQuery('div.stafflist').append(html);
  125. new People("#p" + sample_people.login, sample_people);
  126. }
  127. }
  128. function list_staff() {
  129. show_loading_staff();
  130. $('div.stafflist div.peopleitem').remove();
  131. $.post(bts().ajax_url, { // POST request
  132. _ajax_nonce: bts().nonce, // nonce
  133. action: "list_staff", // action
  134. }).done(function(response, status, xhr){
  135. if (response.status =='success'){
  136. bts().staff = response.users;
  137. bts().staff_map = {};
  138. response.users.forEach(function(u){
  139. bts().staff_map[u.login] = u;
  140. var html = bts_staff_html(u);
  141. jQuery('div.stafflist').append(html);
  142. new People("#p" + u.login,'#staff_item', u);
  143. });
  144. hide_loading_staff();
  145. calculate_total_hour_and_money();
  146. }else{
  147. alert('error getting staff list');
  148. }
  149. });
  150. }
  151. function list_clients() {
  152. show_loading_client();
  153. $('div.clientlist div.peopleitem').remove(); //clear it
  154. $.post(bts().ajax_url, { // POST request
  155. _ajax_nonce: bts().nonce, // nonce
  156. action: "list_client", // action
  157. }, function(response, status, xhr){
  158. if (response.status =='success'){
  159. bts().client = response.users;
  160. bts().client_map = {};
  161. response.users.forEach(function(u){
  162. bts().client_map[u.login] = u;
  163. hide_loading_client();
  164. var html = bts_client_html(u);
  165. jQuery('div.clientlist').append(html);
  166. new People("#p" + u.login, '#client_item' ,u);
  167. });
  168. }else{
  169. alert('error getting Client list');
  170. }
  171. });
  172. }
  173. function list_tos() {
  174. wifi(true);
  175. $.post(bts().ajax_url, { // POST request
  176. _ajax_nonce: bts().nonce, // nonce
  177. action: "list_tos", // action
  178. }, function(response, status, xhr){
  179. if (response.status =='success'){
  180. bts().tos = response.tos;
  181. wifi(false);
  182. }else{
  183. alert('error getting Type of Service list');
  184. }
  185. });
  186. }
  187. function show_loading_staff(){
  188. jQuery('div.stafflist img').attr('src', bts().load_user_img).show();
  189. }
  190. function show_loading_client(){
  191. jQuery('div.clientlist img').attr('src', bts().load_user_img).show();
  192. }
  193. function hide_loading_staff(){
  194. jQuery('div.stafflist img').hide();
  195. }
  196. function hide_loading_client(){
  197. jQuery('div.clientlist img').hide();
  198. }
  199. function show_loading_jobs(){
  200. jQuery('div.workspace img').attr('src', bts().load_job_img).show();
  201. }
  202. function hide_loading_jobs(){
  203. jQuery('div.workspace img').hide();
  204. }
  205. function xero(t){
  206. if (t)
  207. $('div.xero i').show();
  208. else
  209. $('div.xero i').hide();
  210. }
  211. function wifi(t){
  212. if (t)
  213. $('div.wifi i').show();
  214. else
  215. $('div.wifi i').hide();
  216. }
  217. function csv(t){
  218. if (t)
  219. $('div.csv i').show();
  220. else
  221. $('div.csv i').hide();
  222. }
  223. function init_user_search(){
  224. $('div.b_search input').keyup(debounce(function(e){
  225. filter_user(e.target);
  226. }, 500));
  227. }
  228. function filter_user(input){
  229. var value = $(input).attr('value');
  230. value = value.toLowerCase();
  231. var selector = get_selector_for_filter_people(input);
  232. $.each( $(selector).find('div.peopleitem'), function(index, e){
  233. //uncheck everyone
  234. $(e).find('input[type="checkbox"]').prop('checked', false);
  235. var html = $(e).find('div[name="title"] a').html();
  236. html = html.toLowerCase();
  237. if (-1 != html.indexOf(value)){//we find it;
  238. $(e).show();
  239. }else{
  240. $(e).hide();
  241. }
  242. });
  243. }
  244. function get_selector_for_filter_people(input){
  245. var selector='';
  246. var role = $(input).attr('placeholder');
  247. if (role == 'staff') //we filter staff
  248. selector = 'div.stafflist';
  249. else if (role = 'client')
  250. selector = 'div.clientlist';
  251. return selector;
  252. }
  253. $(document).on('click', 'div.divTableHead.bdelete', function(){
  254. add_new_empty_job();
  255. });
  256. function add_new_empty_job(){
  257. var o = new Job({empty:true});
  258. $('div.workspace').append(o.el);
  259. o.el.get(0).scrollIntoView();
  260. dtp_init();
  261. }
  262. $(document).on('click', 'div[name="copyschedule"]', function(e){
  263. e.stopPropagation();
  264. add_new_empty_job();
  265. });
  266. $(document).on('click', 'div.divTableCell.bdelete', function(){
  267. var job = $(this).closest('.divTable').data().job;
  268. var el = $(this).closest('div.divTable');
  269. if ( job.get_job_id() == '')
  270. el.remove();
  271. else{
  272. if (confirm('delete this job?')){
  273. $.post(bts().ajax_url, { // POST request
  274. _ajax_nonce: bts().nonce, // nonce
  275. action: "delete_job", // action
  276. jobid: job.data.id,
  277. }, function(response, status, xhr){
  278. if (response.status=='success'){
  279. el.addClass('blink_me');
  280. el.fadeOut(900);
  281. setTimeout(function(){
  282. el.remove();
  283. }, 900);
  284. }else{
  285. alert( 'error saving data, please check your network');
  286. }
  287. });
  288. }
  289. }
  290. });
  291. $(document).on('mouseenter', 'div.divTableCell', function(){
  292. $(this).closest('div.divTable').addClass('highlight');
  293. });
  294. $(document).on('mouseleave', 'div.divTableCell', function(){
  295. $(this).closest('div.divTable').removeClass('highlight');
  296. });
  297. $(document).on('click', 'div.workspace span.ticon.ticon-save', function(){
  298. var table = $(this).closest('div.divTable');
  299. table.data().job.do_save_record();
  300. });
  301. $(document).on('click', '.divTableHeading span.ticon.ticon-save', function(){
  302. //save all
  303. $('div.workspace span.ticon.ticon-save').each(function (i,e){
  304. if ($(this).is(":visible"))
  305. $(this).trigger('click');
  306. });
  307. });
  308. $(document).on('click', 'span.ticon.ticon-copy', function(){
  309. if (!confirm("make a copy of this job?"))
  310. return;
  311. var table = $(this).closest('div.divTable');
  312. var job = table.data().job;
  313. var newj = clone_data_create_new_job(job.get_record_from_ui());
  314. $('div.workspace').append(newj.el);
  315. newj.el.get(0).scrollIntoView();//make sure it's visible;
  316. newj.mark_highlight_me(1000);//for 1 second;
  317. dtp_init();
  318. });
  319. class Job{ //save data for the record, and display it as GUI
  320. constructor(data){
  321. var html = jQuery("#jobv1_item").html();
  322. this.el = $(html);
  323. //jQuery('div.workspace').append(this.el);
  324. this.load_data(data);
  325. this.init_start_rating();
  326. }
  327. init_start_rating(){
  328. var self = this;
  329. this.el.find("div.brating span").click(function(){
  330. var r = $(this).attr('data-rating');
  331. self.mark_dirty();
  332. self.set_rating(r);
  333. })
  334. this.el.find("div.brating").mouseenter(function(){
  335. //change to all hollow star
  336. $(this).find('span').html('☆');
  337. });
  338. this.el.find("div.brating").mouseleave(function(){
  339. self.set_rating(self.data.rating);
  340. });
  341. }
  342. load_data(data)
  343. {
  344. //save to html element
  345. this.data = data;
  346. this.el.data({job:this, data:data});
  347. //draw GUI
  348. this.clear_err_msg();
  349. this.set_job_id(data.id);
  350. this.set_tos(data.tos);
  351. this.set_start(data.start);
  352. this.set_finish(data.finish);
  353. this.set_rate(data.rate);
  354. this.set_staff(data.staff);
  355. this.set_client(data.client);
  356. this.set_ack(data.ack);
  357. this.set_rating(data.rating);
  358. //draw GUI by other
  359. this.mark_dirty_on_new_record(data);
  360. this.mark_week_color();
  361. this.validate(); //also triggers mark errors
  362. }
  363. get_job_id(){
  364. return this.el.find('input[name="id"]').attr('value');
  365. }
  366. set_job_id(val){
  367. return this.el.find('input[name="id"]').attr('value', val);
  368. }
  369. get_tos()
  370. {
  371. return this.el.find('div.btos select').children("option:selected").val();
  372. }
  373. set_tos(val)
  374. {
  375. if (typeof(val) =="undefined")
  376. return;
  377. this.el.find('div.btos select option[value="'+val+'"]').prop('selected',true);
  378. }
  379. get_start(){
  380. return this.el.find('div.bstart input').attr('value');
  381. }
  382. set_start(val)
  383. {
  384. if (typeof(val) =="undefined")
  385. return;
  386. this.el.find('div.bstart input').attr('value', val);
  387. }
  388. get_finish()
  389. {
  390. return this.el.find('div.bfinish input').attr('value');
  391. }
  392. set_finish(val)
  393. {
  394. if (typeof(val) == "undefined")
  395. return;
  396. this.el.find('div.bfinish input').attr('value', val);
  397. }
  398. get_rate()
  399. {
  400. return this.el.find('div.brate select').children("option:selected").val();
  401. }
  402. set_rate(val)
  403. {
  404. if (typeof(val) =="undefined")
  405. return;
  406. this.el.find('div.brate select option[value="'+val+'"]').prop('selected',true);
  407. }
  408. get_staff()
  409. {
  410. return this.el.find('div.bstaff select').children("option:selected").val();
  411. }
  412. set_staff(val)
  413. {
  414. if (typeof(val) =="undefined")
  415. return;
  416. this.el.find('div.bstaff select option[value="'+val+'"]').prop('selected',true);
  417. }
  418. get_client()
  419. {
  420. return this.el.find('div.bclient select').children("option:selected").val();
  421. }
  422. set_client(val)
  423. {
  424. if (typeof(val) =="undefined")
  425. return;
  426. this.el.find('div.bclient select option[value="'+val+'"]').prop('selected',true);
  427. }
  428. get_ack()
  429. {
  430. return this.el.find('div.bconfirmed input:checked').length > 0;
  431. }
  432. set_ack(val)
  433. {
  434. if (typeof(val) =="undefined")
  435. return;
  436. return this.el.find('div.bconfirmed input').prop('checked', val!=0);
  437. }
  438. get_rating(){
  439. var count =0;
  440. this.el.find('div.brating span').each(function(i,e){
  441. if ($(e).html()=='★')
  442. count +=1;
  443. });
  444. return count;
  445. }
  446. set_rating(num){
  447. if (!(1 <= num && num <=5))
  448. return;
  449. this.el.find('div.brating span').each(function(i,e){
  450. var rating = $(e).attr('data-rating');
  451. var rating = parseInt(rating);
  452. if (rating <= num)
  453. $(e).html('★');
  454. else
  455. $(e).html('☆');
  456. });
  457. }
  458. get_record_from_ui(){
  459. var record = {};
  460. record.id = this.get_job_id();
  461. record.tos = this.get_tos();
  462. record.start = this.get_start();
  463. record.finish = this.get_finish();
  464. record.rate = this.get_rate();
  465. record.staff = this.get_staff();
  466. record.client = this.get_client();
  467. record.ack = this.get_ack();
  468. record.rating = this.get_rating();
  469. return record;
  470. }
  471. do_save_record(){
  472. var self = this;
  473. $.post(bts().ajax_url, { // POST request
  474. _ajax_nonce: bts().nonce, // nonce
  475. action: "save_job", // action
  476. record: this.get_record_from_ui(),
  477. }, function(response, status, xhr){
  478. if (response.status=='success'){
  479. self.load_data(response.newdata);
  480. self.mark_saved();
  481. self.mark_old();
  482. }else{
  483. alert( 'error saving data, please check your network');
  484. }
  485. });
  486. }
  487. mark_dirty_on_new_record(data){
  488. if (typeof(data.id) === 'undefined' || data.id == ''){
  489. this.mark_dirty();
  490. this.mark_new();
  491. }
  492. else{
  493. this.mark_saved();
  494. }
  495. }
  496. mark_dirty() //need save
  497. {
  498. var d = this.el.find('.bsave');
  499. d.removeClass('saved');
  500. d.addClass('blink_me');
  501. setTimeout(function(){
  502. d.removeClass('blink_me');
  503. d.removeClass('saved');
  504. },1000);
  505. }
  506. mark_saved()
  507. {
  508. var d = this.el.find('.bsave');
  509. d.addClass('blink_me');
  510. setTimeout(function(){
  511. d.removeClass('blink_me');
  512. d.addClass('saved');
  513. },1000);
  514. }
  515. //newly created empty record
  516. mark_new()
  517. {
  518. this.el.addClass('emptyrecord');
  519. }
  520. mark_old()
  521. {
  522. this.el.removeClass('emptyrecord');
  523. }
  524. mark_highlight_me(ms){
  525. this.el.addClass('blink_me');
  526. this.el.addClass('highlight');
  527. this.el.addClass('newcopy');
  528. var self = this;
  529. setTimeout(function(){
  530. self.el.removeClass('blink_me');
  531. self.el.removeClass('highlight');
  532. self.el.removeClass('newcopy');
  533. },ms);
  534. }
  535. is_start_valid(){
  536. var s = this.get_start();
  537. return is_valid_date_str(s);
  538. }
  539. is_finish_valid(){
  540. var f = this.get_finish();
  541. if (!is_valid_date_str(f))
  542. return false;
  543. }
  544. is_finish_resonable(){
  545. var f = this.get_finish();
  546. if (!is_valid_date_str(f))
  547. return false;
  548. var s = this.get_start();
  549. s = new Date(s);
  550. f = new Date(f);
  551. return (s < f);
  552. }
  553. validate()
  554. {
  555. var ok_time = this.validate_start() &&
  556. this.validate_finish(); //finish might not be executed, if start is wrong
  557. var ok_tos = this.validate_tos(); //make sure this validate is executed;
  558. var ok_rate = this.validate_rate() ; //make sure this validate is executed
  559. var ok = ok_time && ok_tos && ok_rate;
  560. if (ok){
  561. this.el.removeClass('invalidjob');
  562. }else{
  563. this.el.addClass('invalidjob');
  564. }
  565. return ok;
  566. }
  567. validate_start(){
  568. var str = this.get_start();
  569. if ( is_valid_date_str(str) ){
  570. this.mark_start_valid();
  571. this.set_err_msg_start('');
  572. return true;
  573. }else{
  574. this.mark_start_invalid();
  575. this.set_err_msg_start('wrong date');
  576. return false;
  577. }
  578. }
  579. validate_finish()
  580. {
  581. var str = this.get_finish();
  582. if (! is_valid_date_str(str)){
  583. this.set_err_msg_finish('wrong date');
  584. this.mark_finish_invalid();
  585. return false;
  586. }
  587. if (!this.is_finish_resonable()){
  588. this.set_err_msg_finish("older than start")
  589. this.mark_finish_invalid();
  590. return false;
  591. }
  592. this.mark_finish_valid();
  593. this.set_err_msg_finish('');
  594. return true;
  595. }
  596. validate_rate()
  597. {
  598. var rate_info = this.get_rate_info_by_id(this.get_rate());
  599. if ( rate_info.RatePerUnit <= 0){
  600. this.set_err_msg_rate('bad rate');
  601. this.mark_rate_invalid();
  602. return false;
  603. }
  604. // if (this.get_rate() != this.data.rate){
  605. // this.set_err_msg_rate('rate@Xero inactive ' + this.data.rate);
  606. // this.mark_rate_invalid();
  607. // this.mark_dirty();
  608. // return false;
  609. // }
  610. this.set_err_msg_rate('');
  611. this.mark_rate_valid();
  612. return true;
  613. }
  614. validate_tos(){
  615. // if (this.get_tos() != this.data.tos){
  616. // this.set_err_msg_tos('require NDIS ' + this.data.tos);
  617. // this.mark_tos_invalid();
  618. // this.mark_dirty();
  619. // console.log('tos mark dirty');
  620. // return false;
  621. // }
  622. this.set_err_msg_tos('');
  623. this.mark_tos_valid();
  624. return true;
  625. }
  626. clear_err_msg(){
  627. this.el.find('.divTableRow.errmsg > div').html('');
  628. }
  629. set_err_msg_start(str)
  630. {
  631. this.el.find('div.bstart_err').html(str);
  632. }
  633. set_err_msg_finish(str)
  634. {
  635. this.el.find('div.bfinish_err').html(str);
  636. }
  637. set_err_msg_rate(str)
  638. {
  639. this.el.find('div.brate_err').html(str);
  640. }
  641. set_err_msg_save(str)
  642. {
  643. this.el.find('div.bsave_err').html(str);
  644. }
  645. set_err_msg_tos(str)
  646. {
  647. this.el.find('div.btos_err').html(str);
  648. }
  649. mark_tos_valid(){
  650. this.el.find('div.btos select').removeClass('invalid');
  651. }
  652. mark_tos_invalid(){
  653. this.el.find('div.btos select').addClass('invalid');
  654. }
  655. mark_start_valid(){
  656. this.el.find('div.bstart input').removeClass('invalid');
  657. }
  658. mark_start_invalid(){
  659. this.el.find('div.bstart input').addClass('invalid');
  660. }
  661. mark_finish_valid(){
  662. this.el.find('div.bfinish input').removeClass('invalid');
  663. }
  664. mark_finish_invalid(){
  665. this.el.find('div.bfinish input').addClass('invalid');
  666. }
  667. mark_rate_valid(){
  668. this.el.find('div.brate select').removeClass('invalid');
  669. }
  670. mark_rate_invalid(){
  671. this.el.find('div.brate select').addClass('invalid');
  672. }
  673. mark_week_color(){
  674. this.el.find('div.brating').removeClass('week1color');
  675. this.el.find('div.brating').removeClass('week2color');
  676. if (this.is_week1()){
  677. this.el.find('div.brating').addClass('week1color');
  678. }else if (this.is_week2()){
  679. this.el.find('div.brating').addClass('week2color');
  680. }
  681. }
  682. is_week1()
  683. {
  684. var w1_begin = new Date($('span[name="w1d1"]').data().date) ;
  685. var w1_end = new Date($('span[name="w1d7"]').data().date);
  686. w1_begin.setHours(0,0,0,0);
  687. w1_end.setHours(23,59,59);
  688. //console.log("week1 begin %o, end %o", w1_begin, w1_end);
  689. //w1_end = new Date (w1_end.setDate(w1_end.getDate()+1)); //from 00:00 to 23:59;
  690. var me = new Date(this.data.start);
  691. return (w1_begin <= me && me <= w1_end );
  692. }
  693. is_week2()
  694. {
  695. var w2_begin = new Date($('span[name="w2d1"]').data().date);
  696. var w2_end = new Date($('span[name="w2d7"]').data().date);
  697. w2_begin.setHours(0,0,0,0);
  698. w2_end.setHours(23,59,59);
  699. var me = new Date(this.data.start);
  700. return (w2_begin <= me && me <= w2_end );
  701. }
  702. get_payment_summary(){
  703. var result ={};
  704. result.ot = this.get_is_high_pay();
  705. result.hour = this.get_working_duration();
  706. result.money = this.get_wages();
  707. return result;
  708. }
  709. get_is_high_pay()
  710. {
  711. var rate_info = this.get_rate_info_by_id(this.get_rate());
  712. return this.is_high_pay_hour(rate_info);
  713. }
  714. get_working_duration()
  715. {
  716. //finish - start
  717. var f = new Date(this.get_finish());
  718. var s = new Date(this.get_start());
  719. var diff = f.getTime() - s.getTime();
  720. var hours = Math.floor(diff / 1000 / 60 / 60);
  721. diff -= hours * 1000 * 60 * 60;
  722. var minutes = Math.floor(diff / 1000 / 60);
  723. var minute_to_hour = minutes/60;
  724. return (hours + minute_to_hour);
  725. }
  726. get_wages(){
  727. var hour = this.get_working_duration();
  728. var rate_info = this.get_rate_info_by_id(this.get_rate());
  729. return hour * rate_info.RatePerUnit;
  730. }
  731. get_rate_info_by_id(id){
  732. var rate_info = {};
  733. var rates = bts().earnings_rate;
  734. for(var i =0; i< rates.length; i++){
  735. var r = rates[i];
  736. if(r.EarningsRateID == id){
  737. rate_info = $.extend(true,{}, r);//make a copy
  738. break;
  739. }
  740. }
  741. return rate_info;
  742. }
  743. is_high_pay_hour(rate_info){
  744. var keywords =bts().high_pay_keywords;
  745. var found = false;
  746. return false;
  747. keywords.forEach(function(e){
  748. if (-1 != rate_info.Name.toLowerCase().indexOf(e.toLowerCase()) )
  749. found = true;
  750. });
  751. return found;
  752. }
  753. }//end of class Job
  754. //global GUI summary
  755. function get_wages()
  756. {
  757. var txt = $('div.wages div').html();
  758. return parseInt(txt);
  759. }
  760. function set_wages(num){
  761. $('div.wages div').html(num);
  762. }
  763. function set_working_hours(num){
  764. $('input#woh').attr('value', num);
  765. }
  766. function get_working_hours(){
  767. var txt = $('input#woh').attr('value');
  768. return parseFloat(txt);
  769. }
  770. //modal box
  771. function set_modal_title(selector, title){
  772. var s = 'div.bts_'+ selector +' .ult_modal-title';
  773. $(s).html(title);
  774. }
  775. function set_modal_content(selector, content){
  776. var s = 'div.bts_'+ selector +' div.ult_modal-body.ult-html';
  777. $(s).html(content);
  778. }
  779. function open_modal (selector){
  780. var s='div.bts_'+selector+'_button';
  781. $(s).trigger('click');
  782. }
  783. // setTimeout(function(){
  784. // set_modal_title('warning', 'suck title');
  785. // set_modal_content('warning', 'fucking details');
  786. // //open_modal('warning');
  787. // }, 1000);
  788. //
  789. // setTimeout(function(){
  790. // set_modal_title('error', 'error title');
  791. // set_modal_content('error', 'error details');
  792. // //open_modal('error');
  793. // }, 5000);
  794. $(document).on('mouseenter', 'div.week1 div', function(){
  795. $(this).addClass('blink_me');
  796. get_week2_partner(this).addClass('blink_me');
  797. blink_same_date_by_div(this);
  798. });
  799. $(document).on('mouseleave', 'div.week1 div', function(){
  800. $(this).removeClass('blink_me');
  801. get_week2_partner(this).removeClass('blink_me');
  802. unblink_all_date();
  803. });
  804. function get_week2_partner(div){
  805. var index = $(div).index()+1;
  806. return $('div.week2 div:nth-child('+index+')');
  807. }
  808. function init_weekdays(){
  809. var curr = new Date; // get current date
  810. init_weekdays_by_anchor(curr, true);
  811. return;
  812. }
  813. function init_weekdays_by_anchor(anchor, is_week1){
  814. var curr = new Date(anchor); // get the date;
  815. if (!is_week1){ //it is week2, shift for 7 days;
  816. curr.setDate(curr.getDate() -7); //curr will be changed;
  817. }
  818. var first = curr.getDate() - curr.getDay() + 1; //+1 we want Mon as first
  819. var last = first + 6; // last day is the first day + 6
  820. if (curr.getDay() == 0 ){// it's Sunday;
  821. last = curr.getDate();
  822. first = last - 6;
  823. }
  824. var pos = 1; //first lot
  825. for (var i=first; i<=last; i++)
  826. {
  827. var now = new Date(curr);
  828. var d1 = new Date(now.setDate(i));
  829. now = new Date(curr);
  830. var d2 = new Date(now.setDate(i+7));
  831. set_day_number(1,pos, d1); //week 1
  832. set_day_number(2,pos, d2); //week 2
  833. pos +=1;
  834. }
  835. }
  836. function set_day_number(week, index, date){
  837. var selector = 'span[name="w'+week+'d'+index+'"]';
  838. $(selector).html(date.getDate());
  839. $(selector).data({date:date});
  840. //console.log('set w%d-d%d %o', week,index,date);
  841. }
  842. function set_today(){
  843. var selector = 'div.sheettitle span[name="today"]';
  844. var curr = new Date;
  845. $(selector).html(format_date(curr));
  846. }
  847. Date.prototype.get_week_number = function(){
  848. var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()));
  849. var dayNum = d.getUTCDay() || 7;
  850. d.setUTCDate(d.getUTCDate() + 4 - dayNum);
  851. var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1));
  852. return Math.ceil((((d - yearStart) / 86400000) + 1)/7)
  853. };
  854. function set_week_number(){
  855. var date = $('span[name="w1d1"]').data().date;
  856. //console.log("date %o", date);
  857. var num = date.get_week_number();
  858. $('div.weekly span[name="week1"]').html(num);
  859. $('div.weekly span[name="week2"]').html(num+1);
  860. set_week_boundry();
  861. }
  862. function set_week_boundry()
  863. {
  864. var date = $('span[name="w1d1"]').data().date;
  865. $('#week1b').attr('value', format_date(date));
  866. var date = $('span[name="w2d7"]').data().date;
  867. $('#week2b').attr('value', format_date(date));
  868. }
  869. function number_of_unsaved_job(){
  870. var count =0;
  871. var total_job = $('div.bsave').length -1;//remove table header
  872. var total_saved = $('div.bsave.saved').length;
  873. var empty = $('div.emptyrecord').length;
  874. count = total_job - total_saved - empty;
  875. return count;
  876. }
  877. $('div.prevweek.left').click(function(){
  878. if (number_of_unsaved_job() > 0){
  879. if(!confirm("you have unsaved jobs, proceed will lost them"))
  880. return;
  881. }
  882. $('div.weekdays span.weekday').each(function(i, e){
  883. var date = $(e).data().date;
  884. var newdate = new Date(date.setDate(date.getDate() -7 ));
  885. $(e).html(newdate.getDate());
  886. $(e).data({data:newdate});
  887. });
  888. set_week_number();
  889. debounced_load_timesheet();
  890. });
  891. $('div.nextweek.right').click(function(){
  892. if (number_of_unsaved_job() > 0){
  893. if(!confirm("you have unsaved jobs,proceed will lost them"))
  894. return;
  895. }
  896. $('div.weekdays span.weekday').each(function(i, e){
  897. var date = $(e).data().date;
  898. var newdate = new Date(date.setDate(date.getDate() +7 ));
  899. $(e).html(newdate.getDate());
  900. $(e).data({data:newdate});
  901. });
  902. set_week_number();
  903. debounced_load_timesheet();
  904. });
  905. $('div.weekly div.weekname.prev >input ').click(function(e){
  906. e.stopPropagation();
  907. });
  908. $('div.weekly div.weekname.prev >input ').change(function(e){
  909. var date = $('#week1b').attr('value');
  910. init_weekdays_by_anchor(date, true);
  911. set_week_number();
  912. debounced_load_timesheet();
  913. });
  914. $('div.weekly div.weekname.prev').click(function(){
  915. if (!confirm ('copy entire week to next week? '))
  916. return;
  917. var jobs = [];
  918. var job_els =[];
  919. $('div.week1 >div').each(function(i,e){
  920. var date = new Date($(e).find('span.weekday').data().date);
  921. var strDate = format_date(date); //yyyy-mm-dd
  922. $('div.bstart input').each(function(i,e){
  923. var value = $(e).attr('value');
  924. if( -1 != value.indexOf(strDate) ) //found
  925. {
  926. var el = $(e).closest('div.divTable');
  927. if (el.is(":visible")){
  928. var j = el.data().job;
  929. var newj = clone_data_create_new_job(j.get_record_from_ui(),7);//add 7 days
  930. job_els.push(newj.el);
  931. }
  932. }
  933. });
  934. });
  935. show_jobs(job_els);
  936. debounced_calculate();
  937. });
  938. $('div.weekly div.weekname.next > input').click(function(e){
  939. e.stopPropagation();
  940. });
  941. $('div.weekly div.weekname.next >input ').change(function(e){
  942. e.stopPropagation();
  943. var date = $('#week2b').attr('value');
  944. init_weekdays_by_anchor(date, false);
  945. set_week_number();
  946. debounced_load_timesheet();
  947. });
  948. $('div.weekly div.weekname.next').click(function(e){
  949. $(e).find('input').trigger('click');
  950. });
  951. $('div.week1 > div').click(function(e){
  952. e.stopPropagation();
  953. if ($('div.bstart input.blink_me').length == 0){
  954. alert("nothing to copy");
  955. return;
  956. }
  957. if (!confirm ('copy to next week'))
  958. return;
  959. var jobs_el = [];
  960. $('div.bstart input.blink_me').each(function(i,e){
  961. var r = copy_single_day_to_next_week(e);
  962. if (r != false)
  963. jobs_el.push(r.el);
  964. });
  965. show_jobs(jobs_el);
  966. unblink_all_date();
  967. });
  968. $('div.week1,div.week2').click(function(e){
  969. e.stopPropagation();
  970. $(this).toggleClass('filtered');
  971. do_filter_workspace();
  972. });
  973. function copy_single_day_to_next_week(el){
  974. var tb = $(el).closest('div.divTable');
  975. if (tb.is(':visible')){
  976. var j = $(tb).data().job;
  977. var newj = clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days
  978. return newj;
  979. }
  980. return false;
  981. }
  982. function clone_data_create_new_job(val, num_of_shifted_days){
  983. var data = $.extend(true, {}, val);//make a copy
  984. num_of_shifted_days = typeof num_of_shifted_days !=='undefined'? num_of_shifted_days: 0;// 0 days
  985. //reset
  986. data.id='';
  987. data.ack = 0;
  988. data.rating = 0;
  989. if (is_valid_date_str(data.start)){
  990. var s = new Date(data.start);
  991. var s1 = s.getDate() + num_of_shifted_days;
  992. s = new Date(s.setDate(s1));
  993. data.start = format_date_time(s);
  994. }
  995. if (is_valid_date_str(data.finish)){
  996. var f = new Date(data.finish);
  997. var f1 = f.getDate() + num_of_shifted_days;
  998. f = new Date(f.setDate(f1));
  999. data.finish = format_date_time(f);
  1000. }
  1001. var newj = new Job(data);
  1002. return newj;
  1003. }
  1004. function is_valid_date_str(val){
  1005. var d = new Date(val);
  1006. if (d.toString()== 'Invalid Date')
  1007. return false;
  1008. return true;
  1009. }
  1010. function blink_same_date_by_div(div){
  1011. var date = new Date($(div).find('span.weekday').data().date);
  1012. blink_same_date(date);
  1013. }
  1014. function blink_same_date(date){
  1015. var strDate = format_date(date); //yyyy-mm-dd
  1016. var els=[];
  1017. unblink_all_date();
  1018. $('div.bstart input').each(function(i,e){
  1019. if ( $(e).is(":visible") ){
  1020. var value = $(e).attr('value');
  1021. if( -1 != value.indexOf(strDate) ) //found
  1022. {
  1023. els.push(e);
  1024. $(e).addClass('blink_me');
  1025. }
  1026. }
  1027. });
  1028. }
  1029. function unblink_all_date(){
  1030. $('div.bstart input').removeClass('blink_me');
  1031. }
  1032. $('div.sheettitle h1 span').click(function(){
  1033. reset_title_to_today();
  1034. load_timesheet();
  1035. });
  1036. function reset_title_to_today(){
  1037. set_today();
  1038. init_weekdays();
  1039. set_week_number();
  1040. }
  1041. var debounced_load_timesheet = debounce(load_timesheet,1000);
  1042. function load_timesheet()
  1043. {
  1044. clear_workspace();
  1045. var first = $('span[name="w1d1"]').data().date;
  1046. var last = $('span[name="w2d7"]').data().date;
  1047. $.post(bts().ajax_url, { // POST request
  1048. _ajax_nonce: bts().nonce, // nonce
  1049. action: "list_jobv1", // action
  1050. start: format_date(first),
  1051. finish: format_date(last),
  1052. }, function(response, status, xhr){
  1053. if (response.status =='success'){
  1054. display_jobs_after_staff_client_tos_info_ready(response);
  1055. }else{
  1056. alert('error loading job');
  1057. hide_loading_jobs();
  1058. }
  1059. });
  1060. }
  1061. function display_jobs_after_staff_client_tos_info_ready(response)
  1062. {
  1063. var b = bts();
  1064. if ((typeof b.staff_map != "undefined" && Object.keys(b.staff_map).length > 0) &&
  1065. (typeof b.client_map != "undefined" && Object.keys(b.client_map).length > 0) &&
  1066. (typeof b.tos != "undefined" && Object.keys(b.tos).length > 0 ))
  1067. {
  1068. //we do works, load timesheets
  1069. var template = $("#jobv1_item").html();
  1070. var html = Mustache.render(template, response);
  1071. $('div.workspace').append(html);
  1072. hide_loading_jobs();
  1073. //filter it if reqired
  1074. //debounced_filter_workspace();
  1075. return;
  1076. }
  1077. console.log('wating staff/client/tos info to be ready');
  1078. setTimeout(function(){
  1079. display_jobs_after_staff_client_tos_info_ready(response);
  1080. }, 500); //try it half seconds later
  1081. }
  1082. function show_jobs(job_els, in_ajax){
  1083. if (job_els.length >0){
  1084. $('div.workspace').append(job_els);
  1085. job_els[0].get(0).scrollIntoView();
  1086. console.log('loading ... %d jobs', job_els.length);
  1087. }
  1088. if (typeof in_ajax =='undefined')
  1089. dtp_init();
  1090. }
  1091. function format_date(date){
  1092. var dd = date.getDate();
  1093. var mm = date.getMonth() + 1; //January is 0!
  1094. var yyyy = date.getFullYear();
  1095. if (dd < 10) {
  1096. dd = '0' + dd;
  1097. }
  1098. if (mm < 10) {
  1099. mm = '0' + mm;
  1100. }
  1101. return yyyy + '-' + mm + '-' +dd ;
  1102. }
  1103. function format_date_time(date){
  1104. var strdate = format_date(date);
  1105. var hh = date.getHours();
  1106. if (hh<10){
  1107. hh= '0' + hh;
  1108. }
  1109. var mm = date.getMinutes();
  1110. if (mm<10){
  1111. mm='0' + mm;
  1112. }
  1113. return strdate + ' ' + hh + ":" + mm;
  1114. }
  1115. function clear_workspace()//clear all timesheet jobs
  1116. {
  1117. $('div.workspace > div.divTable').remove();
  1118. //clear datetime picker
  1119. $('div.xdsoft_datetimepicker').remove();
  1120. //
  1121. show_loading_jobs();
  1122. }
  1123. $('div.workinghours').click(function(){
  1124. $('div.bts_message_button').trigger('click');
  1125. });
  1126. $('button[name="confirmschedule"]').click(function(){
  1127. if (!confirm('sending email to each staff for their job arrangement?'))
  1128. return;
  1129. $('div.bts_message .ult-overlay-close-inside').hide();
  1130. $('div.bts_message_button').trigger('click');
  1131. setTimeout(do_email_jobs, 2000);//2 seconds for dialog to popup
  1132. });
  1133. $('button[name="confirmschedule"]').mouseenter(function(){
  1134. $('div.week2').addClass('blink_me');
  1135. })
  1136. $('button[name="confirmschedule"]').mouseleave(function(){
  1137. $('div.week2').removeClass('blink_me');
  1138. })
  1139. var debounced_filter_workspace = debounce(do_filter_workspace, 1000);
  1140. $(document).on('click','div.userlist', debounced_filter_workspace);
  1141. function do_filter_workspace(){
  1142. var staffs =[];
  1143. $('div.stafflist div.peopleitem :checked').each(function(i, e){
  1144. if ($(e).parent().is(':visible')){
  1145. var id = $(e).parent().attr('data-id');
  1146. //console.log("%o, id=%s", e, id);
  1147. staffs.push(id.substring(1));
  1148. }
  1149. });
  1150. var clients =[];
  1151. $('div.clientlist div.peopleitem :checked').each(function(i, e){
  1152. if ($(e).parent().is(':visible')){
  1153. var id = $(e).parent().attr('data-id');
  1154. //console.log("%o, id=%s", e, id);
  1155. clients.push(id.substring(1));
  1156. }
  1157. });
  1158. filter_workspace(staffs, clients);
  1159. filter_workspace_by_weeks();
  1160. debounced_calculate();
  1161. }
  1162. function filter_workspace(staffs, clients){
  1163. //if both array is empty
  1164. if( (staffs === undefined || staffs.length ==0) &&
  1165. (clients===undefined || clients.length ==0)){
  1166. //show all
  1167. $('div.workspace div.divTable').show();
  1168. return;
  1169. }
  1170. //if staffs is empty, we only filter by client
  1171. if (staffs === undefined || staffs.length ==0){
  1172. filter_workspace_by_client(clients);
  1173. return;
  1174. }
  1175. //if clients is empty, we only filter by staff
  1176. if (clients===undefined || clients.length ==0){
  1177. filter_workspace_by_staff(staffs);
  1178. return;
  1179. }
  1180. //filter by both
  1181. filter_workspace_by_both(staffs, clients);
  1182. }
  1183. function filter_workspace_by_staff(staffs)
  1184. {
  1185. //filter some of them;
  1186. $('div.workspace div.divTable').each(function(i,e){
  1187. var job = $(e).data().job;
  1188. var s = job.get_staff();
  1189. if (staffs.indexOf(s) ==-1)
  1190. $(this).fadeOut();
  1191. else
  1192. $(this).fadeIn();
  1193. });
  1194. }
  1195. function filter_workspace_by_client(clients)
  1196. {
  1197. //filter some of them;
  1198. $('div.workspace div.divTable').each(function(i,e){
  1199. var job = $(e).data().job;
  1200. var c = job.get_client();
  1201. if (clients.indexOf(c) ==-1)
  1202. $(this).fadeOut();
  1203. else
  1204. $(this).fadeIn();
  1205. });
  1206. }
  1207. function filter_workspace_by_both(staffs, clients)
  1208. {
  1209. //filter some of them;
  1210. $('div.workspace div.divTable').each(function(i,e){
  1211. var job = $(e).data().job;
  1212. var s = job.get_staff();
  1213. var c = job.get_client();
  1214. if (staffs.indexOf(s) ==-1 || clients.indexOf(c) ==-1)
  1215. $(this).fadeOut();
  1216. else
  1217. $(this).fadeIn();
  1218. });
  1219. }
  1220. function filter_workspace_by_weeks(){
  1221. var hide_week1 = $('div.week1').hasClass('filtered');
  1222. var hide_week2 = $('div.week2').hasClass('filtered');
  1223. if (hide_week1 && hide_week2 ){
  1224. alert("You are hiding both weeks");
  1225. }
  1226. $('div.workspace div.divTable').each(function(i,e){
  1227. var job = $(e).data().job;
  1228. if ((hide_week1 && job.is_week1()) ||
  1229. (hide_week2 && job.is_week2()) ){
  1230. $(e).fadeOut();
  1231. }
  1232. });
  1233. }
  1234. var debounced_calculate = debounce(calculate_total_hour_and_money, 2000);
  1235. function calculate_total_hour_and_money()
  1236. {
  1237. //init pays for all staff;
  1238. var pays={
  1239. total: 0,
  1240. hours: 0,
  1241. };
  1242. $('.stafflist > div.peopleitem').each(function(i,e){
  1243. var people = $(this).data().obj;
  1244. people.reset_summary();
  1245. });
  1246. $('div.workspace > .divTable').each(function(i,e){
  1247. if (! $(e).is(':visible'))
  1248. return;
  1249. var job = $(e).data().job; //class Job
  1250. if (typeof job === 'undefined')
  1251. return;
  1252. var ps = job.get_payment_summary();
  1253. pays.total += ps.money;
  1254. pays.hours += ps.hour;
  1255. var staff = job.get_staff();
  1256. var people = find_staff(staff); //class People
  1257. if (people !=false)
  1258. people.add_payment_summary(ps);
  1259. });
  1260. set_wages(pays.total.toFixed(2));
  1261. set_working_hours(pays.hours.toFixed(2));
  1262. }
  1263. function find_staff(login)
  1264. {
  1265. var d = $('#p'+login).data();
  1266. if (typeof d === 'undefined')
  1267. return false;
  1268. return $('#p'+login).data().obj;
  1269. }
  1270. $(document).on('change', '.divTableRow select, .divTableRow input', function() {
  1271. var job = $(this).closest('.divTable').data().job;
  1272. job.validate();
  1273. job.mark_dirty();
  1274. debounced_calculate();
  1275. });
  1276. function init_ts(){
  1277. show_loading_jobs();
  1278. setTimeout(list_staff, 5000); // for testing delayed loading of jobs only
  1279. //list_staff();
  1280. //list_clients();
  1281. setTimeout(list_clients, 8000); // for testing delayed loading of jobs only
  1282. //list_tos();
  1283. setTimeout(list_tos, 10000); // for testing delayed loading of jobs only
  1284. xero(false);
  1285. wifi(false);
  1286. csv(false);
  1287. init_user_search();
  1288. reset_title_to_today();
  1289. load_timesheet();
  1290. }
  1291. function do_email_jobs()
  1292. {
  1293. var selector = 'div.bts_message div.ult_modal-body';
  1294. $(selector).html('Analysis staff jobs ... ok');
  1295. var staff = bts().staff.slice(0);//copy this array;
  1296. var s = staff.pop();
  1297. //week2 start
  1298. var w2_begin = new Date($('span[name="w2d1"]').data().date);
  1299. var w2_end = new Date($('span[name="w2d7"]').data().date);
  1300. var start = format_date(w2_begin);
  1301. var finish = format_date(w2_end);
  1302. function do_staff(){
  1303. var el = $('<p> Checking ' + s.firstname + "....</p>");
  1304. $(selector).append(el);
  1305. el[0].scrollIntoView();
  1306. $.post(bts().ajax_url, { // POST request
  1307. _ajax_nonce: bts().nonce, // nonce
  1308. action: "email_job", // action
  1309. staff : s.login,
  1310. start : start,
  1311. finish: finish,
  1312. }, function(response, status, xhr){
  1313. if (response.status == 'success'){
  1314. if (response.sent){
  1315. el.append('<span class="sent">' + response.emailstatus + '</span>');
  1316. }else{
  1317. el.append('<span class="nojob">' + response.emailstatus + '</span>');
  1318. }
  1319. }else{
  1320. el.append('<span class="error"> Error[' + response.error + ' ...]</span>');
  1321. }
  1322. }).fail(function(){
  1323. el.append('<span class="error">' + 'Network Error occured' + '</span>');
  1324. //clear staff pending list, stop further processing
  1325. s = [];
  1326. }).always(function(){//next staff
  1327. if (staff.length >0){
  1328. s = staff.pop();
  1329. setTimeout(do_staff, 100); //a short delay makes it looks nice
  1330. }else{
  1331. $('div.bts_message .ult-overlay-close-inside').show();
  1332. $('div.bts_message .ult-overlay-close-inside').addClass('blink_me');
  1333. $('div.week2').removeClass('blink_me');
  1334. $(selector).append('<span class="sent">All staff confirmed! </span>');
  1335. }
  1336. });
  1337. }
  1338. //execute
  1339. do_staff();
  1340. }
  1341. // function ajax_earning_rate(){
  1342. // $.post(bts().ajax_url, { // POST request
  1343. // _ajax_nonce: bts().nonce, // nonce
  1344. // action: "earnings_rate", // action
  1345. // }, function(response, status, xhr){
  1346. // bts().earnings_rate = response;
  1347. // console.log("%o", bts().earnings_rate);
  1348. // });
  1349. // }
  1350. $( ".boundary_datepicker" ).datepicker();
  1351. $( ".boundary_datepicker" ).datepicker("option", "dateFormat", "yy-mm-dd");
  1352. $(document).on('click', 'div.clientlist div[name="title"] a', function(e){
  1353. e.preventDefault();
  1354. e.stopPropagation();
  1355. var id = $(this).closest('label.peopleitem').attr('data-id').substring(1);
  1356. var str = 'https://acaresydncy.com.au/feedback_card/' + id;
  1357. var name = $(this).html();
  1358. if ( confirm ("Email feedback link of : " + name + "\n\n\n" + str + "\n\n\n to helen@acaresydney.com.au?")){
  1359. $.post(bts().ajax_url, { // POST request
  1360. _ajax_nonce: bts().nonce, // nonce
  1361. action: "email_feedback_url", // action
  1362. client : id,
  1363. }, function(response, status, xhr){
  1364. //alert('please check your email on the phone and SMS the link to your client');
  1365. }).fail(function(){
  1366. alert('network error ');
  1367. });
  1368. }
  1369. });
  1370. init_ts();
  1371. /*________________________________________________________________________*/
  1372. });
  1373. })(jQuery);
  1374. /*______________scrolling______________________________________________*/
  1375. jQuery(document).ready(function(){
  1376. var timeoutid =0;
  1377. jQuery('button.peoplelist[name="down"]').mousedown(function(){
  1378. var button = this;
  1379. timeoutid = setInterval(function(){
  1380. //console.log("down scrotop %d ", jQuery(button).parent().find(".userlist").get(0).scrollTop );
  1381. jQuery(button).parent().find(".userlist").get(0).scrollTop +=240;
  1382. }, 100);
  1383. }).on('mouseup mouseleave', function(){
  1384. clearTimeout(timeoutid);
  1385. });
  1386. jQuery('button.peoplelist[name="up"]').mousedown(function(){
  1387. var button = this;
  1388. timeoutid = setInterval(function(){
  1389. //console.log("up scrotop %d ", jQuery(button).parent().find(".userlist").get(0).scrollTop );
  1390. jQuery(button).parent().find(".userlist").get(0).scrollTop -=240;
  1391. }, 100);
  1392. }).on('mouseup mouseleave', function(){
  1393. clearTimeout(timeoutid);
  1394. });
  1395. });