From 8f06266838937dc678d6014118ded5344cb3087c Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 21 Mar 2018 22:20:11 +0530 Subject: [PATCH] all fields editable --- .../projects/doctype/timesheet/timesheet.js | 16 +++---- erpnext/public/js/projects/timer.js | 48 +++++++++---------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js index 94dd35d2d9..40c0af969f 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.js +++ b/erpnext/projects/doctype/timesheet/timesheet.js @@ -63,30 +63,26 @@ frappe.ui.form.on("Timesheet", { frm.refresh_fields(); }); - let button; + let button = 'Start Timer'; $.each(frm.doc.time_logs || [], function(i, row) { - if (row.from_time <= frappe.datetime.now_datetime() && row.completed == 0) { + if ((row.from_time <= frappe.datetime.now_datetime()) && !row.completed) { button = 'Resume Timer'; } - else { - button = 'Start Timer'; - } }) + frm.add_custom_button(__(button), function() { var flag = true; - var disabled = 1; // Fetch the row for timer where activity is not completed and from_time is not <= now_time $.each(frm.doc.time_logs || [], function(i, row) { - if (flag && row.from_time <= frappe.datetime.now_datetime() && row.completed == 0) { + if (flag && row.from_time <= frappe.datetime.now_datetime() && !row.completed) { let timestamp = moment(frappe.datetime.now_datetime()).diff(moment(row.from_time),"seconds"); - erpnext.timesheet.timer(frm, disabled, row, timestamp); + erpnext.timesheet.timer(frm, row, timestamp); flag = false; } }) // If no activities found to start a timer, create new if (flag) { - disabled = 0; - erpnext.timesheet.timer(frm, disabled); + erpnext.timesheet.timer(frm); } }).addClass("btn-primary"); } diff --git a/erpnext/public/js/projects/timer.js b/erpnext/public/js/projects/timer.js index 1b75b94c19..dd8f210fca 100644 --- a/erpnext/public/js/projects/timer.js +++ b/erpnext/public/js/projects/timer.js @@ -1,19 +1,19 @@ frappe.provide("erpnext.timesheet") -erpnext.timesheet.timer = function(frm, disabled, row, timestamp=0) { +erpnext.timesheet.timer = function(frm, row, timestamp=0) { let dialog = new frappe.ui.Dialog({ title: __("Timer"), fields: [ {"fieldtype": "Link", "label": __("Activity Type"), "fieldname": "activity_type", - "reqd": 1, "options": "Activity Type", "read_only": disabled}, - {"fieldtype": "Link", "label": __("Project"), "fieldname": "project", "read_only": disabled}, + "reqd": 1, "options": "Activity Type"}, + {"fieldtype": "Link", "label": __("Project"), "fieldname": "project", "options": "Project"}, {"fieldtype": "Float", "label": __("Expected Hrs"), "fieldname": "expected_hours"}, {"fieldtype": "Section Break"}, {"fieldtype": "HTML", "fieldname": "timer_html"} ] - }); + if (row) { dialog.set_values({ 'activity_type': row.activity_type, @@ -28,19 +28,24 @@ erpnext.timesheet.timer = function(frm, disabled, row, timestamp=0) { var control_timer = function(frm, dialog, row, timestamp=0) { var $btn_start = $(".playpause .btn-start"); + var $btn_complete = $(".playpause .btn-complete"); var interval = null; var currentIncrement = timestamp var isPaused = false; var initialised = row ? true : 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) { initialised = true; - $btn_start.attr("disabled", true); + $btn_start.hide(); + $btn_complete.show(); initialiseTimer(); } - + if (!initialised) { + $btn_complete.hide(); + } $btn_start.click(function(e) { if (!initialised) { // New activity if no activities found @@ -60,7 +65,9 @@ var control_timer = function(frm, dialog, row, timestamp=0) { row.to_time = d.format(moment.defaultDatetimeFormat); } frm.refresh_field("time_logs"); + frm.save(); } + if (clicked) { e.preventDefault(); return false; @@ -69,31 +76,23 @@ var control_timer = function(frm, dialog, row, timestamp=0) { if (!initialised) { initialised = true; isPaused = false; - $btn_start.attr("disabled", true); + $btn_start.hide(); + $btn_complete.show(); initialiseTimer(); } - else { - if (isPaused) { - isPaused = false; - $btn_start.attr("disabled", true); - } - else { - isPaused = true; - $btn_start.attr("disabled", false); - paused_time = currentIncrement; - } - } }); - // Stop the timer and save the time logged by the timer on click of 'Complete' button - dialog.set_primary_action(__("Complete"), function() { + // Stop the timer and update the time logged by the timer on click of 'Complete' button + $btn_complete.click(function() { var grid_row = cur_frm.fields_dict['time_logs'].grid.grid_rows_by_docname[row.name]; + var args = dialog.get_values(); grid_row.doc.completed = 1; - // grid_row.doc.expected_hours = args.expected_hours; + grid_row.doc.activity_type = args.activity_type; + grid_row.doc.project = args.project; + grid_row.doc.expected_hours = args.expected_hours; grid_row.doc.hours = currentIncrement / 3600; grid_row.doc.to_time = frappe.datetime.now_datetime(); grid_row.refresh(); - // Save the form frm.save(); reset(); dialog.hide(); @@ -111,7 +110,7 @@ var control_timer = function(frm, dialog, row, timestamp=0) { var minutes = Math.floor((increment - (hours * 3600)) / 60); var seconds = increment - (hours * 3600) - (minutes * 60); - // If modal is closed by clicking outside anywhere the modal, reset the timer + // If modal is closed by clicking anywhere outside, reset the timer if (!$('.modal-dialog').is(':visible')) { reset(); } @@ -135,6 +134,7 @@ var control_timer = function(frm, dialog, row, timestamp=0) { $(".hours").text("00"); $(".minutes").text("00"); $(".seconds").text("00"); - $btn_start.attr("disabled", false); + $btn_complete.hide(); + $btn_start.show(); } } \ No newline at end of file