From 055f42e68404b0d052165cf30e9fec67d259c898 Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 9 Jul 2019 01:21:26 +1000 Subject: [PATCH] job row can load and save now --- html/job.html | 4 +- js/bts_timesheet.js | 185 ++++++++++++++++++++++++-------------------- ts.php | 2 +- 3 files changed, 106 insertions(+), 85 deletions(-) diff --git a/html/job.html b/html/job.html index d14eb06..ec58727 100644 --- a/html/job.html +++ b/html/job.html @@ -14,8 +14,8 @@ -
-
+
+
[bts_rate_options]
[bts_select_staff]
[bts_select_client]
diff --git a/js/bts_timesheet.js b/js/bts_timesheet.js index 464273a..2c7ea70 100644 --- a/js/bts_timesheet.js +++ b/js/bts_timesheet.js @@ -226,19 +226,10 @@ $(document).on('click', 'div.divTableHead.bdelete', function(){ for (var i=1; i<10; i++){ -// var html = jQuery("#job_item").html(); -// var o = jQuery('div.workspace').append(html); var o = new Job({i:i}); - o.debug(); } - reset_date_time_picker(); }); - function reset_date_time_picker(){ - //$('div.xdsoft_datetimepicker.xdsoft_noselect.xdsoft_default').remove(); - dtp_init(); - } - $(document).on('click', 'div.divTableCell.bdelete', function(){ if (confirm('delete this job?')) $(this).closest('div.divTable').remove(); @@ -253,105 +244,135 @@ $(document).on('click', 'span.ticon.ticon-save', function(){ var table = $(this).closest('div.divTable') - console.log('clicked table data = %o', $(table).data()); - var r = get_record_from_ui(table); - do_save_record(r); + table.data().job.do_save_record(); }); - function do_save_record(r){ - $.post(bts().ajax_url, { // POST request - _ajax_nonce: bts().nonce, // nonce - action: "save_job", // action - record: r, - }, function(response, status, xhr){ - console.log("response for save %o", response); - }); - } - - function get_record_from_ui(table){ - var record = {}; - record.id = get_job_id(table); - record.tos = get_tos(table); - record.start = get_start(table); - record.finish = get_finish(table); - record.rate = get_rate(table); - record.staff = get_staff(table); - record.client = get_client(table); - record.ack = get_ack(table); - return record; - } - - class Job{ + class Job{ //save data for the record, and display it as GUI constructor(data){ var html = jQuery("#job_item").html(); this.el = $(html); - this.data = data; - this.el.data({obj:this, data:data}); jQuery('div.workspace').append(this.el); - } - - debug(){ - console.log("data %o", this.el.data()); + this.load_data(data); + dtp_init(); } load_data(data) { - $(selector).data(data);//save data to object - //update gui; - set_job_id(data.id); + this.set_job_id(data.id); + this.set_tos(data.tos); + this.set_start(data.start); + this.set_finish(data.finish); + this.set_rate(data.rate); + this.set_staff(data.staff); + this.set_client(data.client); + this.set_ack(data.ack); + + //save to html element + this.data = data; + this.el.data({job:this, data:data}); } get_job_id(){ - return $(this.selector).find('input[name="id"]').attr('value'); + return this.el.find('input[name="id"]').attr('value'); } set_job_id(val){ - return $(this.selector).find('input[name="id"]').attr('value', val); + return this.el.find('input[name="id"]').attr('value', val); } get_tos() { - return $(this.selector).find('div.btos select').children("option:selected").val(); + return this.el.find('div.btos select').children("option:selected").val(); } set_tos(val) { - return $(this.selector).find('div.btos select').children("option:selected").val(); + if (typeof(val) =="undefined") + return; + this.el.find('div.btos select option[value="'+val+'"]').prop('selected',true); } get_start(){ + return this.el.find('div.bstart input').attr('value'); + } + set_start(val) + { + if (typeof(val) =="undefined") + return; + this.el.find('div.bstart input').attr('value', val); + } + get_finish() + { + return this.el.find('div.bfinish input').attr('value'); + } + set_finish(val) + { + if (typeof(val) == "undefined") + return; + this.el.find('div.bfinish input').attr('value', val); + } + get_rate() + { + return this.el.find('div.brate select').children("option:selected").val(); + } + set_rate(val) + { + if (typeof(val) =="undefined") + return; + this.el.find('div.brate select option[value="'+val+'"]').prop('selected',true); + } + get_staff() + { + return this.el.find('div.bstaff select').children("option:selected").val(); + } + set_staff(val) + { + if (typeof(val) =="undefined") + return; + this.el.find('div.bstaff select option[value="'+val+'"]').prop('selected',true); + } + get_client() + { + return this.el.find('div.bclient select').children("option:selected").val(); + } + set_client(val) + { + if (typeof(val) =="undefined") + return; + this.el.find('div.bclient select option[value="'+val+'"]').prop('selected',true); + } + get_ack() + { + return this.el.find('div.bconfirmed input:checked').length > 0; + } + set_ack(val) + { + if (typeof(val) =="undefined") + return; + return this.el.find('div.bconfirmed input').prop('checked', val!=0); + } + get_record_from_ui(){ + var record = {}; + record.id = this.get_job_id(); + record.tos = this.get_tos(); + record.start = this.get_start(); + record.finish = this.get_finish(); + record.rate = this.get_rate(); + record.staff = this.get_staff(); + record.client = this.get_client(); + record.ack = this.get_ack(); + return record; } - } - - function get_job_id(table) - { - $(table).find('input[name="id"]').attr('value'); - } - function get_tos(table) - { - return $(table).find('div.btos select').children("option:selected").val(); - } - function get_start(table){ - return $(table).find('div.bstart input').attr('value'); - } - function get_finish(table) - { - return $(table).find('div.bfinish input').attr('value'); - } - function get_rate(table) - { - return $(table).find('div.brate select').children("option:selected").val(); - } - function get_staff(table) - { - return $(table).find('div.bstaff select').children("option:selected").val(); - } - function get_client(table) - { - return $(table).find('div.bclient select').children("option:selected").val(); - } - function get_ack(table) - { - return $(table).find('div.bconfirmed input:checked').length > 0; - } + do_save_record(){ + var self = this; + $.post(bts().ajax_url, { // POST request + _ajax_nonce: bts().nonce, // nonce + action: "save_job", // action + record: this.get_record_from_ui(), + }, function(response, status, xhr){ + console.log("response for save %o", response); + self.load_data(response.newdata); + }); + } + }//end of class Job /*________________________________________________________________________*/ }); diff --git a/ts.php b/ts.php index eea487f..668c101 100644 --- a/ts.php +++ b/ts.php @@ -335,7 +335,7 @@ class AcareOffice{ //this is an update if ( isset($r['id']) && trim($r['id']) !='' && is_numeric($r['id'])){ $response['isNew'] = false; //add or update? - $result = $this->update($d, array('id' =>$r['id'])); + $result = $this->db->update($this->table_name, $d, array('id' =>$r['id'])); if ($result !== false && $this->db->last_error == ''){ $d['id'] = $r['id']; $response['status'] = 'success';