diff --git a/css/bts_timesheet.css b/css/bts_timesheet.css
index 07563fa..5b0486f 100644
--- a/css/bts_timesheet.css
+++ b/css/bts_timesheet.css
@@ -413,13 +413,15 @@ div.weekly div.copyprogress {
div.copyprogress div[name='copyschedule'] {
position: relative;
- top: 0px;
+ top: -5px;
width: 100px;
- height: 15px;
+ height: 25px;
padding: 0px;
border-radius: 10px;
background-color: black;
+ color: white;
margin:auto;
+ z-index:1;
}
div.weekdays {
@@ -562,13 +564,17 @@ span.badge.pink {
/* div table */
div.blueTable {
border: 1px solid #1C6EA4;
- background-color: #EEEEEE;
+ background-color: white;
width: 100%;
text-align: left;
border-collapse: collapse;
border:0px;
}
+div.blueTable.emptyrecord{
+ background-color: #eeeeee;
+}
+
.divTable.blueTable .divTableCell,
.divTable.blueTable .divTableHead,
{
diff --git a/html/job.html b/html/job.html
index 7369381..1c0f840 100644
--- a/html/job.html
+++ b/html/job.html
@@ -5,12 +5,12 @@
[bts_type_of_service]
-
-
+
+
[bts_rate_options]
[bts_select_staff]
[bts_select_client]
-
+
☆
☆
diff --git a/js/bts_timesheet.js b/js/bts_timesheet.js
index 0064fd7..d07bab0 100644
--- a/js/bts_timesheet.js
+++ b/js/bts_timesheet.js
@@ -225,14 +225,40 @@
init_ts();
$(document).on('click', 'div.divTableHead.bdelete', function(){
+ var o = new Job({empty:true});
+ });
+
+ $(document).on('click', 'div.copyprogress', function(){
for (var i=1; i<10; i++){
- var o = new Job({i:i});
+ var o = new Job({empty:true});
}
- });
+ });
$(document).on('click', 'div.divTableCell.bdelete', function(){
- if (confirm('delete this job?'))
- $(this).closest('div.divTable').remove();
+ var job = $(this).closest('.divTable').data().job;
+ var el = $(this).closest('div.divTable');
+ if ( job.get_job_id() == '')
+ el.remove();
+ else{
+ if (confirm('delete this job?')){
+ $.post(bts().ajax_url, { // POST request
+ _ajax_nonce: bts().nonce, // nonce
+ action: "delete_job", // action
+ jobid: job.data.id,
+ }, function(response, status, xhr){
+ if (response.status=='success'){
+ el.addClass('blink_me');
+ el.fadeOut(900);
+ setTimeout(function(){
+ el.remove();
+ }, 900);
+
+ }else{
+ alert( 'error saving data, please check your network');
+ }
+ });
+ }
+ }
});
$(document).on('mouseenter', 'div.divTableCell', function(){
@@ -254,14 +280,14 @@
jQuery('div.workspace').append(this.el);
this.load_data(data);
dtp_init();
- this.init_start_rating();
+ this.init_start_rating()
+
}
init_start_rating(){
var self = this;
this.el.find("div.brating span").click(function(){
var r = $(this).attr('data-rating');
- self.data.rating = r;
self.mark_dirty();
self.set_rating(r);
@@ -293,6 +319,14 @@
//save to html element
this.data = data;
this.el.data({job:this, data:data});
+
+ if (typeof(data.id) === 'undefined' || data.id == ''){
+ this.mark_dirty();
+ this.mark_new();
+ }
+ else{
+ this.mark_saved();
+ }
}
get_job_id(){
@@ -415,6 +449,7 @@
if (response.status=='success'){
self.load_data(response.newdata);
self.mark_saved();
+ self.mark_old();
}else{
alert( 'error saving data, please check your network');
}
@@ -441,6 +476,40 @@
d.addClass('saved');
},1000);
}
+
+ //newly created empty record
+ mark_new()
+ {
+ this.el.addClass('emptyrecord');
+ }
+ mark_old()
+ {
+ this.el.removeClass('emptyrecord');
+ }
+
+ is_start_valid(){
+ var s = this.get_start();
+ return is_valid_date_str(s);
+
+ }
+ is_finish_valid(){
+ var f = this.get_finish();
+ if (!is_valid_date_str(f))
+ return false;
+ }
+
+ is_finish_resonable(){
+ var f = this.get_finish();
+ if (!is_valid_date_str(f))
+ return false;
+ var s = this.get_start();
+
+ s = new Date(s);
+ f = new Date(f);
+
+ return (s < f);
+ }
+
}//end of class Job
//global GUI summary
@@ -494,10 +563,12 @@
$(document).on('mouseenter', 'div.week1 div', function(){
$(this).addClass('blink_me');
get_week2_partner(this).addClass('blink_me');
+ blink_same_date_by_div(this);
});
$(document).on('mouseleave', 'div.week1 div', function(){
$(this).removeClass('blink_me');
get_week2_partner(this).removeClass('blink_me');
+ unblink_all_date();
});
function get_week2_partner(div){
@@ -531,20 +602,6 @@
$(selector).data({date:date});
}
- function format_date(date) {
- var monthNames = [
- "January", "February", "March",
- "April", "May", "June", "July",
- "August", "September", "October",
- "November", "December"
- ];
-
- var day = date.getDate();
- var monthIndex = date.getMonth();
- var year = date.getFullYear();
-
- return day + ' ' + monthNames[monthIndex] + ' ' + year;
- }
function set_today(){
var selector = 'div.sheettitle span[name="today"]';
var curr = new Date;
@@ -561,13 +618,26 @@
function set_week_number(){
var date = $('span[name="w1d1"]').data().date;
- console.log("date %o", date);
+ //console.log("date %o", date);
var num = date.get_week_number();
$('div.weekly span[name="week1"]').html(num);
$('div.weekly span[name="week2"]').html(num+1);
}
+ function number_of_unsaved_job(){
+ var count =0;
+ var total_job = $('div.bsave').length -1;//remove table header
+ var total_saved = $('div.bsave.saved').length;
+ var empty = $('div.emptyrecord').length;
+ count = total_job - total_saved - empty;
+ return count;
+ }
+
$('div.prevweek.left').click(function(){
+ if (number_of_unsaved_job() > 0){
+ alert ("you have unsaved jobs,please save it before proceed");
+ return;
+ }
$('div.weekdays span.weekday').each(function(i, e){
var date = $(e).data().date;
var newdate = new Date(date.setDate(date.getDate() -7 ));
@@ -578,6 +648,11 @@
load_timesheet();
});
$('div.nextweek.right').click(function(){
+ if (number_of_unsaved_job() > 0){
+ alert ("you have unsaved jobs,please save it before proceed");
+ return;
+ }
+
$('div.weekdays span.weekday').each(function(i, e){
var date = $(e).data().date;
var newdate = new Date(date.setDate(date.getDate() +7 ));
@@ -591,18 +666,100 @@
$('div.weekly div.weekname.prev').click(function(){
if (!confirm ('copy entire week to next week? '))
return;
+ var jobs = [];
+ $('div.week1 >div').each(function(i,e){
+ var date = new Date($(e).find('span.weekday').data().date);
+ var strDate = format_date(date); //yyyy-mm-dd
+ $('div.bstart input').each(function(i,e){
+ var value = $(e).attr('value');
+ if( -1 != value.indexOf(strDate) ) //found
+ {
+ var j = $(e).closest('div.divTable').data().job;
+ jobs.push(j);
+ }
+ });
+ });
+
+ jobs.forEach(function(e){
+ clone_data_create_new_job(e.data);
+ });
});
$('div.weekly div.weekname.next').click(function(){
- if (!confirm ('copy entire week to previous week? '))
- return;
+ alert('you can only copy from past to future (left to right)');
});
$('div.week1 > div').click(function(){
+ if ($('div.bstart input.blink_me').length == 0){
+ alert("nothing to copy");
+ return;
+ }
if (!confirm ('copy to next week'))
return;
+ $('div.bstart input.blink_me').each(function(i,e){
+ copy_single_day_to_next_week(e);
+ });
+ unblink_all_date();
});
+ function copy_single_day_to_next_week(el){
+ var j = $(el).closest('div.divTable').data().job;
+ clone_data_create_new_job(j.data);
+ }
+
+ function clone_data_create_new_job(val){
+ var data = $.extend(true, {}, val);//make a copy
+ //reset
+ data.id='';
+ data.ack = 0;
+ data.rating = 0;
+
+ if (is_valid_date_str(data.start)){
+ var s = new Date(data.start);
+ var s1 = s.getDate() + 7;
+ s = new Date(s.setDate(s1));
+ data.start = format_date_time(s);
+ }
+ if (is_valid_date_str(data.finish)){
+ var f = new Date(data.finish);
+ var f1 = f.getDate() + 7;
+ f = new Date(f.setDate(f1));
+ data.finish = format_date_time(f);
+ }
+ new Job(data);
+ }
+
+ function is_valid_date_str(val){
+ var d = new Date(val);
+ if (d.toString()== 'Invalid Date')
+ return false;
+ return true;
+ }
+
+ function blink_same_date_by_div(div){
+ var date = new Date($(div).find('span.weekday').data().date);
+ blink_same_date(date);
+ }
+
+ function blink_same_date(date){
+ var strDate = format_date(date); //yyyy-mm-dd
+ var els=[];
+ unblink_all_date();
+ $('div.bstart input').each(function(i,e){
+ var value = $(e).attr('value');
+ if( -1 != value.indexOf(strDate) ) //found
+ {
+ els.push(e);
+ $(e).addClass('blink_me');
+ }
+ });
+ }
+
+
+ function unblink_all_date(){
+ $('div.bstart input').removeClass('blink_me');
+ }
+
$('div.sheettitle h1').click(function(){
reset_title_to_today();
})
@@ -653,6 +810,19 @@
return yyyy + '-' + mm + '-' +dd ;
}
+ function format_date_time(date){
+ var strdate = format_date(date);
+ var hh = date.getHours();
+ if (hh<10){
+ hh= '0' + hh;
+ }
+ var mm = date.getMinutes();
+ if (mm<10){
+ mm='0' + mm;
+ }
+ return strdate + ' ' + hh + ":" + mm;
+ }
+
function clear_workspace()//clear all timesheet jobs
{
$('div.workspace > div.divTable').remove();
@@ -710,7 +880,46 @@
$(this).fadeIn();
});
}
+
+ function calculate_total_working_hour()
+ {
+
+ }
+
+ function calculate_total_money()
+ {
+
+ }
+
+
+ //visually hint whether start is correct;
+ $(document).on('change','div.bstart input', function(){
+ var str = $(this).attr('value');
+ if ( ! is_valid_date_str(str) )
+ $(this).css('background-color', 'orange');
+ else
+ $(this).css('background-color', 'white');
+ });
+
+ //visually hint whether finish date is correct;
+ $(document).on('change','div.bfinish input', function(){
+ var job = $(this).closest('div.divTable').data().job;
+ var str = $(this).attr('value');
+ if ( ! is_valid_date_str(str) ){
+ $(this).css('background-color', 'orange');
+ return;
+ }else
+ $(this).css('background-color', 'white');
+ //must be later than start
+ if (! job.is_finish_resonable()){
+ alert('finish date should be bigger than start date');
+ $(this).css('background-color', 'orange');
+ }else{
+ $(this).css('background-color', 'white');
+ }
+
+ });
$(document).on('change', '.divTableRow select, .divTableRow input', function() {
diff --git a/ts.php b/ts.php
index 053b339..b6987bd 100644
--- a/ts.php
+++ b/ts.php
@@ -389,7 +389,7 @@ class AcareOffice{
//ajax delete job
function delete_job(){
check_ajax_referer('acaresydney');
- $id = $_POST['recordid'];
+ $id = $_POST['jobid'];
$result = $this->db->delete($this->table_name, array('id'=> $id));
$response=array(
'status' => 'success',
@@ -417,7 +417,7 @@ class AcareOffice{
'jobs' => [],
);
- $sql = "SELECT * FROM $this->table_name WHERE start>='%s' and start <='%s'";
+ $sql = "SELECT * FROM $this->table_name WHERE start>='%s' and start <='%s' order by staff";
$jobs = $this->db->get_results($this->db->prepare ($sql, array($start, $finish)));
if (! empty($jobs)){