Sfoglia il codice sorgente

job row can load and save now

master
patrick 6 anni fa
parent
commit
055f42e684
3 ha cambiato i file con 106 aggiunte e 85 eliminazioni
  1. +2
    -2
      html/job.html
  2. +103
    -82
      js/bts_timesheet.js
  3. +1
    -1
      ts.php

+ 2
- 2
html/job.html Vedi File

@@ -14,8 +14,8 @@
<option value="turn_h">Turn(Complex)</option>
</select>
</div>
<div class="divTableCell bstart"><input class="datepicker" placeholder="2019:03-02-11:30am"></input></div>
<div class="divTableCell bfinish"><input class="datepicker" placeholder="2019:03-02-11:30am"></input></div>
<div class="divTableCell bstart"><input class="datepicker" placeholder="2019-07-10 01:00:00" value=""></input></div>
<div class="divTableCell bfinish"><input class="datepicker" placeholder="2019-07-10 01:00:00" value=""></input></div>
<div class="divTableCell brate">[bts_rate_options]</div>
<div class="divTableCell bstaff">[bts_select_staff]</div>
<div class="divTableCell bclient">[bts_select_client]</div>

+ 103
- 82
js/bts_timesheet.js Vedi File

@@ -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
/*________________________________________________________________________*/
});

+ 1
- 1
ts.php Vedi File

@@ -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';

Loading…
Annulla
Salva