|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
frappe.provide("erpnext.timesheet")
|
|
|
|
frappe.provide("erpnext.timesheet");
|
|
|
|
|
|
|
|
|
|
|
|
erpnext.timesheet.timer = function(frm, row, timestamp=0) {
|
|
|
|
erpnext.timesheet.timer = function(frm, row, timestamp=0) {
|
|
|
|
let dialog = new frappe.ui.Dialog({
|
|
|
|
let dialog = new frappe.ui.Dialog({
|
|
|
|
@@ -24,17 +24,15 @@ erpnext.timesheet.timer = function(frm, row, timestamp=0) {
|
|
|
|
dialog.get_field("timer_html").$wrapper.append(frappe.render_template("timesheet"));
|
|
|
|
dialog.get_field("timer_html").$wrapper.append(frappe.render_template("timesheet"));
|
|
|
|
control_timer(frm, dialog, row, timestamp);
|
|
|
|
control_timer(frm, dialog, row, timestamp);
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
var $btn_start = $(".playpause .btn-start");
|
|
|
|
var $btn_start = $(".playpause .btn-start");
|
|
|
|
var $btn_complete = $(".playpause .btn-complete");
|
|
|
|
var $btn_complete = $(".playpause .btn-complete");
|
|
|
|
var interval = null;
|
|
|
|
var interval = null;
|
|
|
|
var currentIncrement = timestamp
|
|
|
|
var currentIncrement = timestamp;
|
|
|
|
var isPaused = false;
|
|
|
|
|
|
|
|
var initialised = row ? true : false;
|
|
|
|
var initialised = row ? true : false;
|
|
|
|
var clicked = false;
|
|
|
|
var clicked = false;
|
|
|
|
var paused_time = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If row with not completed status, initialize timer with the time elapsed on click of 'Start Timer'.
|
|
|
|
// If row with not completed status, initialize timer with the time elapsed on click of 'Start Timer'.
|
|
|
|
if (row) {
|
|
|
|
if (row) {
|
|
|
|
@@ -59,7 +57,7 @@ var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
row.from_time = frappe.datetime.get_datetime_as_string();
|
|
|
|
row.from_time = frappe.datetime.get_datetime_as_string();
|
|
|
|
row.expected_hours = args.expected_hours;
|
|
|
|
row.expected_hours = args.expected_hours;
|
|
|
|
row.completed = 0;
|
|
|
|
row.completed = 0;
|
|
|
|
let d = moment(row.from_time)
|
|
|
|
let d = moment(row.from_time);
|
|
|
|
if(row.expected_hours) {
|
|
|
|
if(row.expected_hours) {
|
|
|
|
d.add(row.expected_hours, "hours");
|
|
|
|
d.add(row.expected_hours, "hours");
|
|
|
|
row.to_time = d.format(moment.defaultDatetimeFormat);
|
|
|
|
row.to_time = d.format(moment.defaultDatetimeFormat);
|
|
|
|
@@ -75,7 +73,6 @@ var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
|
|
|
|
|
|
|
|
if (!initialised) {
|
|
|
|
if (!initialised) {
|
|
|
|
initialised = true;
|
|
|
|
initialised = true;
|
|
|
|
isPaused = false;
|
|
|
|
|
|
|
|
$btn_start.hide();
|
|
|
|
$btn_start.hide();
|
|
|
|
$btn_complete.show();
|
|
|
|
$btn_complete.show();
|
|
|
|
initialiseTimer();
|
|
|
|
initialiseTimer();
|
|
|
|
@@ -96,10 +93,9 @@ var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
frm.save();
|
|
|
|
frm.save();
|
|
|
|
reset();
|
|
|
|
reset();
|
|
|
|
dialog.hide();
|
|
|
|
dialog.hide();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
function initialiseTimer() {
|
|
|
|
function initialiseTimer() {
|
|
|
|
interval = setInterval(function() {
|
|
|
|
interval = setInterval(function() {
|
|
|
|
if (isPaused) return;
|
|
|
|
|
|
|
|
var current = setCurrentIncrement();
|
|
|
|
var current = setCurrentIncrement();
|
|
|
|
updateStopwatch(current);
|
|
|
|
updateStopwatch(current);
|
|
|
|
}, 1000);
|
|
|
|
}, 1000);
|
|
|
|
@@ -115,7 +111,7 @@ var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
reset();
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hours > 99)
|
|
|
|
if(hours > 99)
|
|
|
|
reset();
|
|
|
|
reset();
|
|
|
|
$(".hours").text(hours < 10 ? ("0" + hours.toString()) : hours.toString());
|
|
|
|
$(".hours").text(hours < 10 ? ("0" + hours.toString()) : hours.toString());
|
|
|
|
$(".minutes").text(minutes < 10 ? ("0" + minutes.toString()) : minutes.toString());
|
|
|
|
$(".minutes").text(minutes < 10 ? ("0" + minutes.toString()) : minutes.toString());
|
|
|
|
$(".seconds").text(seconds < 10 ? ("0" + seconds.toString()) : seconds.toString());
|
|
|
|
$(".seconds").text(seconds < 10 ? ("0" + seconds.toString()) : seconds.toString());
|
|
|
|
@@ -128,7 +124,6 @@ var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
|
|
|
|
|
|
|
|
function reset() {
|
|
|
|
function reset() {
|
|
|
|
currentIncrement = 0;
|
|
|
|
currentIncrement = 0;
|
|
|
|
isPaused = true;
|
|
|
|
|
|
|
|
initialised = false;
|
|
|
|
initialised = false;
|
|
|
|
clearInterval(interval);
|
|
|
|
clearInterval(interval);
|
|
|
|
$(".hours").text("00");
|
|
|
|
$(".hours").text("00");
|
|
|
|
@@ -137,4 +132,4 @@ var control_timer = function(frm, dialog, row, timestamp=0) {
|
|
|
|
$btn_complete.hide();
|
|
|
|
$btn_complete.hide();
|
|
|
|
$btn_start.show();
|
|
|
|
$btn_start.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|