- {{tos_name}}
+ {{tos_name}}
{{start}}
{{finish}}
@@ -16,23 +16,22 @@
-
-
e tos
-
-
es
-
ef
-
er
-
estaf
-
ecli
-
econfirm
-
e rat
-
edel
-
eeave
+
+
+
+
+
+
+
+
+
+
diff --git a/js/bts_office.js b/js/bts_office.js
index d91a946..ab0b213 100644
--- a/js/bts_office.js
+++ b/js/bts_office.js
@@ -291,16 +291,17 @@
});
$(document).on('click', 'div.divTableCell.bdelete', function(){
- var job = $(this).closest('.divTable').data().job;
- var el = $(this).closest('div.divTable');
- if ( job.get_job_id() == '')
+ var el = $(this).closest('div.jobTable');
+ var data = el.data();
+ if (typeof data.id =='undefined' || data.id == '')
el.remove();
else{
+ var id = data.id;
if (confirm('delete this job?')){
$.post(bts().ajax_url, { // POST request
_ajax_nonce: bts().nonce, // nonce
action: "delete_job", // action
- jobid: job.data.id,
+ jobid: id,
}, function(response, status, xhr){
if (response.status=='success'){
el.addClass('blink_me');
@@ -350,12 +351,10 @@
});
class Job{ //save data for the record, and display it as GUI
- constructor(data){
- var html = jQuery("#jobv1_item").html();
- this.el = $(html);
- //jQuery('div.workspace').append(this.el);
- this.load_data(data);
- this.init_start_rating();
+ constructor(selector, data){
+ this.el = $(selector);
+ //this.load_data(data);
+ //this.init_start_rating();
}
init_start_rating(){
@@ -405,40 +404,45 @@
return this.el.find('input[name="id"]').attr('value');
}
set_job_id(val){
- return this.el.find('input[name="id"]').attr('value', val);
+ if (typeof val == 'undefined' || val == '')
+ {//remove data-id and id
+ this.el.removeAttr('data-id');
+ this.el.removeAttr('id');
+ }else{
+ this.el.attr('data-id', val);
+ this.el.attr('id', 'job_' + val);
+ }
}
get_tos()
{
- return this.el.find('div.btos select').children("option:selected").val();
+ this.el.find('div.btos select').children("option:selected").val();
}
set_tos(val)
{
if (typeof(val) =="undefined")
return;
- this.el.find('div.btos select option[value="'+val+'"]').prop('selected',true);
+ this.el.find('input.tos_name').attr('value', bts().tos[val].tos_full_str);
}
get_start(){
- return this.el.find('div.bstart input').attr('value');
+ return this.el.find('div.bstart').html();
}
set_start(val)
{
- if (typeof(val) =="undefined")
- return;
- this.el.find('div.bstart input').attr('value', val);
+ this.el.find('div.bstart').html(val);
}
get_finish()
{
- return this.el.find('div.bfinish input').attr('value');
+ return this.el.find('div.bfinish').html();
}
set_finish(val)
{
if (typeof(val) == "undefined")
return;
- this.el.find('div.bfinish input').attr('value', val);
+ this.el.find('div.bfinish').html(val);
}
get_rate()
{
- return this.el.find('div.brate select').children("option:selected").val();
+ return this.el.find('div.brate').children("option:selected").val();
}
set_rate(val)
{
@@ -1180,19 +1184,32 @@
var b = bts();
if ((typeof b.staff_map != "undefined" && Object.keys(b.staff_map).length > 0) &&
(typeof b.client_map != "undefined" && Object.keys(b.client_map).length > 0) &&
- (typeof b.tos != "undefined" && Object.keys(b.tos).length > 0 ))
+ (typeof b.tos != "undefined" && Object.keys(b.tos).length > 0 ) &&
+ (typeof b.earnings_rate != "undefined" && Object.keys(b.earnings_rate).length > 0 ))
{
- //we do works, load timesheets
- var template = $("#jobv1_item").html();
- var html = Mustache.render(template, response);
- $('div.workspace').append(html);
- hide_loading_jobs();
-
- //filter it if reqired
- //debounced_filter_workspace();
- return;
+ //map data for each jobTable
+ response.jobs.forEach(function(e){
+ e.tos_name = bts().tos[e.tos].tos_full_str;
+ e.staff_name = bts().staff_map[e.staff].display_name;
+ e.client_name = bts().client_map[e.client].display_name;
+ e.rate_name = bts().earnings_rate[e.rate].RatePerUnit + "-" + bts().earnings_rate[e.rate].Name;
+ e.saved = true;
+ if (e.ack != 0){
+ e.is_confirmed = true;
+ }
+ //console.log('attach %s %o to %o ', e.id, e, div);
+ });
+
+ //we do works, load timesheets
+ var template = $("#jobv1_item").html();
+ var html = Mustache.render(template, response);
+ $('div.workspace').append(html);
+ hide_loading_jobs();
+ //filter it if reqired
+ debounced_filter_workspace();
+ return;
}
- console.log('wating staff/client/tos info to be ready');
+ //console.log('wating staff/client/tos info to be ready');
setTimeout(function(){
display_jobs_after_staff_client_tos_info_ready(response);
}, 500); //try it half seconds later
@@ -1318,45 +1335,46 @@
function filter_workspace_by_staff(staffs)
{
+ var class_name='to_be_shown';
//filter some of them;
- $('div.workspace div.divTable').each(function(i,e){
- var job = $(e).data().job;
- var s = job.get_staff();
-
- if (staffs.indexOf(s) ==-1)
- $(this).fadeOut();
- else
- $(this).fadeIn();
+ staffs.forEach(function(e){
+ $('div.workspace div.jobTable[data-staff="' + e + '"]').addClass(class_name);
});
+
+ $('div.workspace div.jobTable.' + class_name).fadeIn();
+ $('div.workspace div.jobTable:not(.'+ class_name +')').hide();
+ $('.' + class_name).removeClass(class_name);
}
function filter_workspace_by_client(clients)
{
+ var class_name='to_be_shown';
//filter some of them;
- $('div.workspace div.divTable').each(function(i,e){
- var job = $(e).data().job;
- var c = job.get_client();
-
- if (clients.indexOf(c) ==-1)
- $(this).fadeOut();
- else
- $(this).fadeIn();
+ clients.forEach(function(e){
+ $('div.workspace div.jobTable[data-client="' + e + '"]').addClass(class_name);
});
+
+ $('div.workspace div.jobTable.' + class_name).fadeIn();
+ $('div.workspace div.jobTable:not(.'+ class_name +')').hide();
+ $('.' + class_name).removeClass(class_name);
}
function filter_workspace_by_both(staffs, clients)
{
+ var class_name='hide';
//filter some of them;
- $('div.workspace div.divTable').each(function(i,e){
- var job = $(e).data().job;
- var s = job.get_staff();
- var c = job.get_client();
-
- if (staffs.indexOf(s) ==-1 || clients.indexOf(c) ==-1)
- $(this).fadeOut();
- else
- $(this).fadeIn();
- });
+ clients.forEach(function(e){
+ $('div.workspace div.jobTable:not([data-client="' + e + '"])').addClass(class_name);
+ });
+
+ staffs.forEach(function(e){
+ $('div.workspace div.jobTable:not([data-staff="' + e + '"])').addClass(class_name);
+ });
+
+ $('div.workspace div.jobTable.' + class_name).hide();
+ $('div.workspace div.jobTable:not(.'+ class_name +')').show();
+ $('.' + class_name).removeClass(class_name);
+
}
function filter_workspace_by_weeks(){
@@ -1427,16 +1445,18 @@
});
function init_ts(){
- show_loading_jobs();
- setTimeout(list_staff, 5000); // for testing delayed loading of jobs only
- //list_staff();
- //list_clients();
- setTimeout(list_clients, 8000); // for testing delayed loading of jobs only
- //list_tos();
- setTimeout(list_tos, 10000); // for testing delayed loading of jobs only
xero(false);
wifi(false);
csv(false);
+
+ show_loading_jobs();
+ list_staff();
+ list_clients();
+ list_tos();
+ ajax_earning_rate();
+ //setTimeout(list_staff, 5000); // for testing delayed loading of jobs only
+ //setTimeout(list_clients, 8000); // for testing delayed loading of jobs only
+ //setTimeout(list_tos, 10000); // for testing delayed loading of jobs only
init_user_search();
reset_title_to_today();
load_timesheet();
@@ -1496,15 +1516,18 @@
do_staff();
}
-// function ajax_earning_rate(){
-// $.post(bts().ajax_url, { // POST request
-// _ajax_nonce: bts().nonce, // nonce
-// action: "earnings_rate", // action
-// }, function(response, status, xhr){
-// bts().earnings_rate = response;
-// console.log("%o", bts().earnings_rate);
-// });
-// }
+ function ajax_earning_rate(){
+ $.post(bts().ajax_url, { // POST request
+ _ajax_nonce: bts().nonce, // nonce
+ action: "earnings_rate", // action
+ }, function(response, status, xhr){
+ bts().earnings_rate = {};
+ response.options.forEach(function(e){
+ bts().earnings_rate[e.EarningsRateID]=e;
+ });
+ console.log("%o", bts().earnings_rate);
+ });
+ }
$( ".boundary_datepicker" ).datepicker();
diff --git a/ts.php b/ts.php
index 39a80b2..c3bc7f6 100644
--- a/ts.php
+++ b/ts.php
@@ -434,7 +434,6 @@ class AcareOffice{
'userid'=> $this->bts_user_id,
'load_user_img'=> plugins_url('img/loading_user.gif', __FILE__),
'load_job_img'=> plugins_url('img/loading_job.gif', __FILE__),
- 'earnings_rate'=> get_option('bts_payitem_earnings_rate'),
'high_pay_keywords' => ['sat ', 'sun ', 'high ', 'public holiday'], //space is important
) );
}
@@ -762,6 +761,7 @@ ZOT;
'login' => $s->user_login,
'firstname'=> $s->first_name,
'lastname'=> $s->last_name,
+ 'display_name' => $s->display_name,
'mobile'=> get_user_meta($s->ID, 'mobile', true),
'email'=> $s->user_email,
'wages'=> 0,