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 @@