Przeglądaj źródła

copy single existing job works.

master
patrick 6 lat temu
rodzic
commit
093131ee21
3 zmienionych plików z 158 dodań i 40 usunięć
  1. +3
    -3
      html/jobv1.html
  2. +133
    -37
      js/bts_office.js
  3. +22
    -0
      js/ts.js

+ 3
- 3
html/jobv1.html Wyświetl plik

@@ -1,6 +1,7 @@
{{#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="divTableRow">
<div class="divTableCell btos {{#tos_err}}error{{/tos_err}}" title="{{tos_err}}">
@@ -20,7 +21,6 @@
<span class="ticon ticon-trash"></span>
</div>
<div class="divTableCell bsave ">
<span class="ticon ticon-save"></span>
<span class="ticon ticon-copy"></span>
</div>
</div>

+ 133
- 37
js/bts_office.js Wyświetl plik

@@ -285,8 +285,15 @@
$(document).on('click', 'div.workspace div.bedit span.ticon-edit', function(){
var el = $(this).closest('div.jobTable');
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(){
@@ -314,7 +321,7 @@
var templ = $("#jobv1_item").html();
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);
$('#job_'+job.id).get(0).scrollIntoView();
}else{
@@ -375,18 +382,24 @@
},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;

//show editor
var html = $('#jobv1_editor').html();
html = Mustache.render(html, job);
set_modal_content('editor', html);
//update GUI
open_modal('editor');
set_modal_title('editor', "Create New Job ");
set_modal_title('editor', title);
dtp_init();
//init editor
var e = new JobEditor('#editor_' + job.editorid, job);
@@ -413,7 +426,7 @@
if (response.status=='success'){
var id = el.attr('data-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.fadeOut(900);
setTimeout(function(){
@@ -447,18 +460,27 @@
});
});
$(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{
constructor(record)
{
@@ -709,7 +731,62 @@
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(){
return this.el.attr('data-id');
@@ -911,17 +988,7 @@
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(){
var s = this.get_start();
@@ -1467,10 +1534,11 @@
});
function copy_single_day_to_next_week(el){
var tb = $(el).closest('div.divTable');
var tb = $(el).closest('div.jobTable');
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 false;
@@ -1497,9 +1565,20 @@
data.finish = format_date_time(f);
}
var newj = new Job(data);
//return;
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){
var d = new Date(val);
if (d.toString()== 'Invalid Date')
@@ -2020,6 +2099,23 @@
});
}
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)
{
@@ -2029,7 +2125,7 @@
//make a copy of the job
var child = bts().job_map[id];
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});
var html = $('#jobv1_editor').html();
html = Mustache.render(html, job_copy);
@@ -2041,7 +2137,7 @@
//console.log("e is instance of JobEditor %o", e instanceof JobEditor);
}
$( ".boundary_datepicker" ).datepicker();
$( ".boundary_datepicker" ).datepicker("option", "dateFormat", "yy-mm-dd");
@@ -2067,7 +2163,7 @@
init_ts();
$('div.divTableHeading div.bsave span.ticon-search').click(do_test);
function do_test(){
function do_test(){ //TODO: remove this search function
open_modal('editor');
set_modal_title('editor', "title");
set_modal_content('editor', $('div.workspace').html());

+ 22
- 0
js/ts.js Wyświetl plik

@@ -7,6 +7,28 @@ function bts(){
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 () {

Ładowanie…
Anuluj
Zapisz