timesheet source code
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

1540 行
42KB

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