| var el = $('#job_' + job.id).addClass("blink_me"); | var el = $('#job_' + job.id).addClass("blink_me"); | ||||
| setTimeout(function(){ | setTimeout(function(){ | ||||
| el.removeClass('blink_me'); | el.removeClass('blink_me'); | ||||
| }, 1500); | |||||
| }, 1500); | |||||
| debounced_calculate(); | |||||
| }); | }); | ||||
| $(document).on('click', 'div.divTableHead.bdelete span.ticon-trash', function(){ | $(document).on('click', 'div.divTableHead.bdelete span.ticon-trash', function(){ | ||||
| if (response.status=='success'){ | if (response.status=='success'){ | ||||
| var id = el.attr('data-id'); | var id = el.attr('data-id'); | ||||
| delete bts().job_map[id]; | delete bts().job_map[id]; | ||||
| console.log("delete %s , job_map[%s]=%o ", id, id, bts().job_map[id]); | |||||
| //console.log("delete %s , job_map[%s]=%o ", id, id, bts().job_map[id]); | |||||
| el.addClass('blink_me'); | el.addClass('blink_me'); | ||||
| el.fadeOut(900); | el.fadeOut(900); | ||||
| setTimeout(function(){ | setTimeout(function(){ | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| debounced_calculate(); | |||||
| }); | }); | ||||
| $(document).on('mouseenter', 'div.divTableCell', function(){ | $(document).on('mouseenter', 'div.divTableCell', function(){ | ||||
| if (!confirm ('copy entire week to next week? ')) | if (!confirm ('copy entire week to next week? ')) | ||||
| return; | return; | ||||
| var jobs = []; | var jobs = []; | ||||
| var job_els =[]; | |||||
| $('div.week1 >div').each(function(i,e){ | $('div.week1 >div').each(function(i,e){ | ||||
| var date = new Date($(e).find('span.weekday').data().date); | var date = new Date($(e).find('span.weekday').data().date); | ||||
| var strDate = format_date(date); //yyyy-mm-dd | var strDate = format_date(date); //yyyy-mm-dd | ||||
| $('div.bstart input').each(function(i,e){ | |||||
| var value = $(e).attr('value'); | |||||
| $('div.bstart:visible').each(function(i,e){ | |||||
| var value = $(e).html(); | |||||
| if( -1 != value.indexOf(strDate) ) //found | if( -1 != value.indexOf(strDate) ) //found | ||||
| { | { | ||||
| var el = $(e).closest('div.divTable'); | |||||
| if (el.is(":visible")){ | |||||
| var j = el.data().job; | |||||
| var newj = clone_data_create_new_job(j.get_record_from_ui(),7);//add 7 days | |||||
| job_els.push(newj.el); | |||||
| var el = $(e).closest('div.jobTable'); | |||||
| if (el.is(":visible") && el.hasClass('saved')){ | |||||
| var id = el.data().id; | |||||
| var j = bts().job_map[id]; | |||||
| var newj = clone_data_create_new_job(j.get_record(),7);//add 7 days | |||||
| add_new_job_to_map(newj); | |||||
| jobs.push(newj); | |||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| }); | }); | ||||
| show_jobs(job_els); | |||||
| show_jobs(jobs); | |||||
| debounced_calculate(); | debounced_calculate(); | ||||
| }); | }); | ||||
| $('div.week1 > div').click(function(e){ | $('div.week1 > div').click(function(e){ | ||||
| e.stopPropagation(); | e.stopPropagation(); | ||||
| if ($('div.bstart input.blink_me').length == 0){ | |||||
| if ($('div.bstart.blink_me').length == 0){ | |||||
| alert("nothing to copy"); | alert("nothing to copy"); | ||||
| return; | return; | ||||
| } | } | ||||
| if (!confirm ('copy to next week')) | if (!confirm ('copy to next week')) | ||||
| return; | return; | ||||
| var jobs_el = []; | |||||
| $('div.bstart input.blink_me').each(function(i,e){ | |||||
| var new_jobs = []; | |||||
| $('div.bstart.blink_me').each(function(i,e){ | |||||
| var r = copy_single_day_to_next_week(e); | var r = copy_single_day_to_next_week(e); | ||||
| if (r != false) | |||||
| jobs_el.push(r.el); | |||||
| if (r != false){ | |||||
| add_new_job_to_map(r); | |||||
| new_jobs.push(r); | |||||
| } | |||||
| }); | }); | ||||
| show_jobs(jobs_el); | |||||
| show_jobs(new_jobs); | |||||
| unblink_all_date(); | unblink_all_date(); | ||||
| }); | }); | ||||
| function copy_single_day_to_next_week(el){ | function copy_single_day_to_next_week(el){ | ||||
| var tb = $(el).closest('div.jobTable'); | var tb = $(el).closest('div.jobTable'); | ||||
| if (tb.is(':visible')){ | |||||
| if (tb.is(':visible') && tb.hasClass('saved')){ | |||||
| var id = tb.data().id; | var id = tb.data().id; | ||||
| var j = bts().job_map[id]; | var j = bts().job_map[id]; | ||||
| var newj = clone_data_create_new_job(j.get_record() , 7); // +7 days | var newj = clone_data_create_new_job(j.get_record() , 7); // +7 days | ||||
| var strDate = format_date(date); //yyyy-mm-dd | var strDate = format_date(date); //yyyy-mm-dd | ||||
| var els=[]; | var els=[]; | ||||
| unblink_all_date(); | unblink_all_date(); | ||||
| $('div.bstart input').each(function(i,e){ | |||||
| var first_into_view = false; //make sure first row in match is visible | |||||
| $('div.bstart').each(function(i,e){ | |||||
| if ( $(e).is(":visible") ){ | if ( $(e).is(":visible") ){ | ||||
| var value = $(e).attr('value'); | |||||
| var value = $(e).html(); | |||||
| if( -1 != value.indexOf(strDate) ) //found | if( -1 != value.indexOf(strDate) ) //found | ||||
| { | { | ||||
| if ( !first_into_view ){ //scroll to top | |||||
| first_into_view = true; | |||||
| $(e).get(0).scrollIntoView(); | |||||
| } | |||||
| els.push(e); | els.push(e); | ||||
| $(e).addClass('blink_me'); | $(e).addClass('blink_me'); | ||||
| } | } | ||||
| function unblink_all_date(){ | function unblink_all_date(){ | ||||
| $('div.bstart input').removeClass('blink_me'); | |||||
| $('div.bstart').removeClass('blink_me'); | |||||
| } | } | ||||
| $('div.sheettitle h1 span').click(function(){ | $('div.sheettitle h1 span').click(function(){ | ||||
| return s.indexOf('hour') != -1; | return s.indexOf('hour') != -1; | ||||
| } | } | ||||
| function show_jobs(job_els, in_ajax){ | |||||
| if (job_els.length >0){ | |||||
| $('div.workspace').append(job_els); | |||||
| job_els[0].get(0).scrollIntoView(); | |||||
| console.log('loading ... %d jobs', job_els.length); | |||||
| function show_jobs(jobs){ | |||||
| if (jobs.length >0){ | |||||
| var templ = $("#jobv1_item").html(); | |||||
| var html = Mustache.render(templ, {jobs:jobs}); //job id should be available; | |||||
| var el = $(html); | |||||
| $('div.workspace').append(el); | |||||
| el.get(0).scrollIntoView(); | |||||
| } | } | ||||
| if (typeof in_ajax =='undefined') | |||||
| dtp_init(); | |||||
| debounced_calculate(); | |||||
| } | } | ||||
| function format_date(date){ | function format_date(date){ | ||||
| $('div.bts_message_button').trigger('click'); | $('div.bts_message_button').trigger('click'); | ||||
| }); | }); | ||||
| $('button[name="confirmschedule"]').click(function(){ | |||||
| $('button[name="confirmschedule"]').click(function(){//TODO: check error before confirm | |||||
| if (!confirm('sending email to each staff for their job arrangement?')) | if (!confirm('sending email to each staff for their job arrangement?')) | ||||
| return; | return; | ||||
| $('div.bts_message .ult-overlay-close-inside').hide(); | $('div.bts_message .ult-overlay-close-inside').hide(); | ||||
| var id = $(e).attr('data-id'); | var id = $(e).attr('data-id'); | ||||
| var job = bts().job_map[id]; | var job = bts().job_map[id]; | ||||
| if (id == ''){ | |||||
| //is this a new Job without id? | |||||
| var newjob_id = $(e).attr('data-newjob_id'); | |||||
| if ( typeof newjob_id != "undefined"){ | |||||
| id = newjob_id; | |||||
| job = bts().job_map_new[newjob_id]; | |||||
| } | |||||
| } | |||||
| if (typeof job === 'undefined' || !job.is_job_valid() ) | if (typeof job === 'undefined' || !job.is_job_valid() ) | ||||
| return; | return; | ||||
| var ps = job.get_payment_summary(); | var ps = job.get_payment_summary(); |