Procházet zdrojové kódy

copy single existing job works.

master
patrick před 6 roky
rodič
revize
093131ee21
3 změnil soubory, kde provedl 158 přidání a 40 odebrání
  1. +3
    -3
      html/jobv1.html
  2. +133
    -37
      js/bts_office.js
  3. +22
    -0
      js/ts.js

+ 3
- 3
html/jobv1.html Zobrazit soubor

{{#jobs}} {{#jobs}}
<div class="divTable jobTable blueTable {{#saved}} saved {{/saved}} {{^saved}} dirty {{/saved}} {{#is_week1}}week1job{{/is_week1}} {{#is_week2}} week2job {{/is_week2}}" id="job_{{id}}"
data-id="{{id}}" data-tos="{{tos}}" data-rate="{{rate}}" data-staff="{{staff}}" data-client="{{client}}">
<div class="divTable jobTable blueTable {{#saved}} saved {{/saved}} {{^saved}} dirty {{/saved}} {{#is_week1}}week1job{{/is_week1}} {{#is_week2}} week2job {{/is_week2}}"
{{#id}} id="job_{{id}}" {{/id}} {{^id}} id="{{newjob_id}}" {{/id}}
data-id="{{id}}" {{^id}} data-newjob_id="{{newjob_id}}" {{/id}} data-tos="{{tos}}" data-rate="{{rate}}" data-staff="{{staff}}" data-client="{{client}}">
<div class="divTableBody"> <div class="divTableBody">
<div class="divTableRow"> <div class="divTableRow">
<div class="divTableCell btos {{#tos_err}}error{{/tos_err}}" title="{{tos_err}}"> <div class="divTableCell btos {{#tos_err}}error{{/tos_err}}" title="{{tos_err}}">
<span class="ticon ticon-trash"></span> <span class="ticon ticon-trash"></span>
</div> </div>
<div class="divTableCell bsave "> <div class="divTableCell bsave ">
<span class="ticon ticon-save"></span>
<span class="ticon ticon-copy"></span> <span class="ticon ticon-copy"></span>
</div> </div>
</div> </div>

+ 133
- 37
js/bts_office.js Zobrazit soubor

$(document).on('click', 'div.workspace div.bedit span.ticon-edit', function(){ $(document).on('click', 'div.workspace div.bedit span.ticon-edit', function(){
var el = $(this).closest('div.jobTable'); var el = $(this).closest('div.jobTable');
el.addClass('Editing'); el.addClass('Editing');
var id = el.attr('data-id');
do_edit_job(id);
var newjob_id = el.attr('data-newjob_id');
if (newjob_id != ''){
do_edit_new_job(newjob_id);
}else{
var id = el.attr('data-id');
do_edit_job(id);
}
}); });


// $(document).on('click', 'div.bts_editor div.ult-overlay-close', function(){ // $(document).on('click', 'div.bts_editor div.ult-overlay-close', function(){
var templ = $("#jobv1_item").html(); var templ = $("#jobv1_item").html();
var html = Mustache.render(templ, {jobs:job}); //job id should be available; var html = Mustache.render(templ, {jobs:job}); //job id should be available;
if (job.is_new){
if ( $('div.jobTable.Editing').length == 0){
$('div.workspace').append(html); $('div.workspace').append(html);
$('#job_'+job.id).get(0).scrollIntoView(); $('#job_'+job.id).get(0).scrollIntoView();
}else{ }else{
},300); },300);
} }
function add_new_empty_job(){
var job = new Job({empty:true});
job.is_new = true;
function add_new_empty_job(job){
var title = "";
if (typeof job == 'undefined' || ! (job instanceof Job) ){
job = new Job({empty:true});
job.is_new = true;
title = "Create New Job ";
}else if (job instanceof Job){
tile = "Create new Job by Copy Existing one";
}
job.editorid = Math.floor(Math.random() * Math.floor(99999)); // a random number; job.editorid = Math.floor(Math.random() * Math.floor(99999)); // a random number;

//show editor //show editor
var html = $('#jobv1_editor').html(); var html = $('#jobv1_editor').html();
html = Mustache.render(html, job); html = Mustache.render(html, job);
set_modal_content('editor', html); set_modal_content('editor', html);
//update GUI //update GUI
open_modal('editor'); open_modal('editor');
set_modal_title('editor', "Create New Job ");
set_modal_title('editor', title);
dtp_init(); dtp_init();
//init editor //init editor
var e = new JobEditor('#editor_' + job.editorid, job); var e = new JobEditor('#editor_' + job.editorid, job);
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[%d]=%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(){
}); });
}); });
$(document).on('click', 'span.ticon.ticon-copy', function(){ $(document).on('click', 'span.ticon.ticon-copy', function(){
if (!confirm("make a copy of this job?"))
return;
var table = $(this).closest('div.divTable');
var job = table.data().job;
var newj = clone_data_create_new_job(job.get_record_from_ui());
$('div.workspace').append(newj.el);
newj.el.get(0).scrollIntoView();//make sure it's visible;
newj.mark_highlight_me(1000);//for 1 second;
dtp_init();
var table = $(this).closest('div.jobTable');
var record = bts().job_map[table.data().id].get_record();
//create new job;
var newj = clone_data_create_new_job(record);
add_new_empty_job(newj);
}); });
function mark_highlight_me(el, ms){
el.addClass('blink_me');
el.addClass('highlight');
el.addClass('newcopy');
setTimeout(function(){
el.removeClass('blink_me');
el.removeClass('highlight');
el.removeClass('newcopy');
},ms);
}
class Job{ class Job{
constructor(record) constructor(record)
{ {
self.set_err_msg_save('Data Error'); self.set_err_msg_save('Data Error');
} }
}); });
}
}
off_event_handler(){
this.el.off('change',"div.btos select");
//TODO
this.el.find("div.bstart input").change(function(){
if (self.validate_start()){
self.data.start = self.get_start();
self.set_err_msg_start('');
self.validate_start_and_finish();
}
});
this.el.find("div.bfinish input").change(function(){
if (self.validate_finish()){
self.data.finish = self.get_finish();
self.set_err_msg_finish('');
self.validate_start_and_finish();
}
});
this.el.find("div.bstaff select").change(function(){
if (self.validate_staff()){
self.data.staff = self.get_staff();
self.set_err_msg_staff('');
}
});
this.el.find("div.bclient select").change(function(){
if (self.validate_client()){
self.data.client = self.get_client();
self.set_err_msg_client('');
}
});
this.el.find("div.brate select").change(function(){
if (self.validate_rate()){
self.data.rate = self.get_rate();
self.set_err_msg_rate('');
}
});
this.el.find("div.bconfirmed input").change(function(){
if(self.validate_ack()){
self.data.ack = self.get_ack();
}
});
this.el.find("div.brating select").change(function(){
if( self.validate_rating()){
self.data.rating =self.get_rating();
}
});
this.el.find("div.bsave span.ticon-save").click(function(e){
if ( self.validate() ){
self.do_save_record();
}else{
self.set_err_msg_save('Data Error');
}
});
}


get_job_id(){ get_job_id(){
return this.el.attr('data-id'); return this.el.attr('data-id');
this.el.removeClass('emptyrecord'); this.el.removeClass('emptyrecord');
} }
mark_highlight_me(ms){
this.el.addClass('blink_me');
this.el.addClass('highlight');
this.el.addClass('newcopy');
var self = this;
setTimeout(function(){
self.el.removeClass('blink_me');
self.el.removeClass('highlight');
self.el.removeClass('newcopy');
},ms);
}

is_start_valid(){ is_start_valid(){
var s = this.get_start(); var s = this.get_start();
}); });
function copy_single_day_to_next_week(el){ function copy_single_day_to_next_week(el){
var tb = $(el).closest('div.divTable');
var tb = $(el).closest('div.jobTable');
if (tb.is(':visible')){ if (tb.is(':visible')){
var j = $(tb).data().job;
var newj = clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days
var id = tb.data().id;
var j = bts().job_map[id];
var newj = clone_data_create_new_job(j.get_record() , 7); // +7 days
return newj; return newj;
} }
return false; return false;
data.finish = format_date_time(f); data.finish = format_date_time(f);
} }
var newj = new Job(data); var newj = new Job(data);
//return;
return newj; return newj;
} }
function add_new_job_to_map(newj)
{
//add to job map
newj.newjob_id = "new_" + bts_unique_ID();
if (typeof bts().job_map_new == 'undefined'){
bts().job_map_new = [];
}
bts().job_map_new[newj.newjob_id] = newj;
}
function is_valid_date_str(val){ function is_valid_date_str(val){
var d = new Date(val); var d = new Date(val);
if (d.toString()== 'Invalid Date') if (d.toString()== 'Invalid Date')
}); });
} }
function do_edit_new_job(id)
{
open_modal('editor');
set_modal_title('editor', "Editing New Job ");

var new_job = bts().job_map_new[id];
new_job.editorid = id;
//set_modal_data('editor', {jobid: id, job_copy:job_copy});
var html = $('#jobv1_editor').html();
html = Mustache.render(html, new_job);
set_modal_content('editor', html);
//update GUI
dtp_init();
//init editor
var e = new JobEditor('#editor_' + id, new_job);
//console.log("e is instance of JobEditor %o", e instanceof JobEditor);
}
function do_edit_job(id) function do_edit_job(id)
{ {
//make a copy of the job //make a copy of the job
var child = bts().job_map[id]; var child = bts().job_map[id];
var job_copy = Object.assign(Object.create(Object.getPrototypeOf(child)), child); //a shallow copy only; var job_copy = Object.assign(Object.create(Object.getPrototypeOf(child)), child); //a shallow copy only;
job_copy.editorid = Math.floor(Math.random() * Math.floor(99999)); // a random number;
job_copy.editorid = bts_random_number();
//set_modal_data('editor', {jobid: id, job_copy:job_copy}); //set_modal_data('editor', {jobid: id, job_copy:job_copy});
var html = $('#jobv1_editor').html(); var html = $('#jobv1_editor').html();
html = Mustache.render(html, job_copy); html = Mustache.render(html, job_copy);
//console.log("e is instance of JobEditor %o", e instanceof JobEditor); //console.log("e is instance of JobEditor %o", e instanceof JobEditor);
} }
$( ".boundary_datepicker" ).datepicker(); $( ".boundary_datepicker" ).datepicker();
$( ".boundary_datepicker" ).datepicker("option", "dateFormat", "yy-mm-dd"); $( ".boundary_datepicker" ).datepicker("option", "dateFormat", "yy-mm-dd");
init_ts(); init_ts();
$('div.divTableHeading div.bsave span.ticon-search').click(do_test); $('div.divTableHeading div.bsave span.ticon-search').click(do_test);
function do_test(){
function do_test(){ //TODO: remove this search function
open_modal('editor'); open_modal('editor');
set_modal_title('editor', "title"); set_modal_title('editor', "title");
set_modal_content('editor', $('div.workspace').html()); set_modal_content('editor', $('div.workspace').html());

+ 22
- 0
js/ts.js Zobrazit soubor

return bts1; return bts1;
} }


function bts_random_id()
{
return '_' + Math.random().toString(36).substr(2, 9);
}

function bts_random_number()
{
return Math.floor(Math.random() * Math.floor(99999)); // a random number;
}

//https://gist.github.com/gordonbrander/2230317
function bts_unique_ID(){
function chr4(){
return Math.random().toString(16).slice(-4);
}
return chr4() + chr4() +
'-' + chr4() +
'-' + chr4() +
'-' + chr4() +
'-' + chr4() + chr4() + chr4();
}

(function ($) { (function ($) {
$(function () { $(function () {

Načítá se…
Zrušit
Uložit