From dda0ba7eb90fd196c0f56c38ada2b307608d64c1 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Fri, 12 Jan 2018 23:19:24 -0500 Subject: [PATCH] Only allow dashboard edit-item submission and confirm that the user wants to go back when the user presses the back button after changes have been made --- resources/assets/js/dashboard.js | 19 +++++++++++++++---- resources/assets/sass/dashboard.scss | 9 ++++++++- resources/views/dashboard/edit-item.blade.php | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/resources/assets/js/dashboard.js b/resources/assets/js/dashboard.js index 6cecfae..77b1fc2 100644 --- a/resources/assets/js/dashboard.js +++ b/resources/assets/js/dashboard.js @@ -269,7 +269,8 @@ function editItemInit() { formData = {}, submitting = false, hours, - minutes; + minutes, + changes = false; // show the loading modal const showLoadingModal = function() { @@ -430,18 +431,28 @@ function editItemInit() { }, 100); }); + // initialize change events for back button + $editItem.find("input, textarea, select").on("input change", function() { + changes = true; + $submit.removeClass("disabled"); + }); + // initialize back button $backButton.on("click", function() { if (!submitting) { - askConfirmation("Cancel and return to the " + path + " list?", function() { + if (changes) { + askConfirmation("Cancel changes and return to the list?", function() { + window.location.href = "/dashboard/" + path; + }); + } else { window.location.href = "/dashboard/" + path; - }); + } } }); // initialize submit button $submit.on("click", function() { - if (!submitting) { + if (!submitting && changes) { submitting = true; // show the loading modal diff --git a/resources/assets/sass/dashboard.scss b/resources/assets/sass/dashboard.scss index 4ed61e6..0215cb7 100644 --- a/resources/assets/sass/dashboard.scss +++ b/resources/assets/sass/dashboard.scss @@ -367,7 +367,14 @@ body { } .back-button { float: left; } - .submit-button { float: right; } + + .submit-button { + float: right; + + &.disabled { + pointer-events: none; + } + } .back-button, .submit-button { margin: 25px 15px 15px 15px; diff --git a/resources/views/dashboard/edit-item.blade.php b/resources/views/dashboard/edit-item.blade.php index 2c29fef..fde660e 100644 --- a/resources/views/dashboard/edit-item.blade.php +++ b/resources/views/dashboard/edit-item.blade.php @@ -65,7 +65,7 @@
- +