-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn the user if they forgot to set install/abandon date (#806)
* Warn the user if they forgot to set install/abandon date * Move DOM element construction into HTML template * Add node support
- Loading branch information
1 parent
8feaa16
commit b9367ae
Showing
7 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.field-validate_install_abandon_date_set_widget { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
$(document).ready(function($) { | ||
const getCurrentISODate = () => { | ||
const now = new Date(); | ||
const year = now.getFullYear(); | ||
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed | ||
const date = String(now.getDate()).padStart(2, '0'); | ||
return `${year}-${month}-${date}`; | ||
}; | ||
|
||
function submitAdminForm(saveAction) { | ||
const adminForm = document.querySelector('#content-main form'); | ||
|
||
// Create a hidden input to simulate the button action | ||
const hiddenInput = document.createElement('input'); | ||
hiddenInput.type = 'hidden'; | ||
hiddenInput.name = saveAction; | ||
hiddenInput.value = '1'; | ||
adminForm.appendChild(hiddenInput); | ||
adminForm.submit(); | ||
|
||
return true; | ||
} | ||
|
||
const saveButtons = $('.submit-row input[value*="Save"]'); | ||
|
||
|
||
function hideWarning(){ | ||
$('#dateMissingWarning').remove(); | ||
saveButtons.each((i, button) => { | ||
$(button).removeClass("disabled-button"); | ||
}) | ||
} | ||
|
||
function showWarning(dateField, statusField, saveAction, dateType){ | ||
const errorNotice = $("#dateMissingWarningTemplate").clone(); | ||
errorNotice.prop("id", "dateMissingWarning"); | ||
|
||
errorNotice.find("#saveCurrentDateButton").on("click", () => { | ||
dateField.val(getCurrentISODate()) | ||
submitAdminForm(saveAction); | ||
return false; | ||
}); | ||
|
||
errorNotice.find("#saveNoDateButton").on("click", () => { | ||
submitAdminForm(saveAction); | ||
return false; | ||
}); | ||
|
||
errorNotice.find("#statusText").text(statusField.val()); | ||
errorNotice.find("#dateTypeText").text(dateType); | ||
|
||
saveButtons.each((i, button) => { | ||
$(button).addClass("disabled-button"); | ||
}) | ||
|
||
errorNotice.insertBefore($('.submit-row').first()) | ||
} | ||
|
||
$('#id_install_date').on("input", (e) => { | ||
hideWarning(); | ||
}); | ||
|
||
$('#id_abandon_date').on("input", (e) => { | ||
hideWarning(); | ||
}); | ||
|
||
$('#id_status').on("change", (e) => { | ||
hideWarning(); | ||
}); | ||
|
||
saveButtons.on('click', (e) => { | ||
const status = $('#id_status').val(); | ||
const installDate = $('#id_install_date').val(); | ||
const abandonDate = $('#id_abandon_date').val(); | ||
|
||
$('.datetimeshortcuts a').on("click", (e) => { | ||
hideWarning(); | ||
}); | ||
|
||
if (status === "Active") { | ||
if (!installDate) { | ||
hideWarning(); | ||
showWarning($("#id_install_date"), $('#id_status'), e.target.name, "Install") | ||
|
||
return false; | ||
} | ||
} else if (["Closed", "Inactive"].indexOf(status) !== -1){ | ||
if (installDate && !abandonDate) { | ||
hideWarning(); | ||
showWarning($("#id_abandon_date"), $('#id_status'), e.target.name, "Abandon") | ||
|
||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div id="dateMissingWarningTemplate" class="warning-box"> | ||
<p> | ||
<b>Warning</b>: Status set to <span id="statusText"></span> without setting <span id="dateTypeText"></span> Date | ||
</p> | ||
<a id="saveCurrentDateButton" class="button" href="#" style="padding: 10px 15px; display: inline-block; text-decoration: none;"> | ||
Use Today's Date | ||
</a> | ||
<a id="saveNoDateButton" class="button" href="#" style="padding: 10px 15px; display: inline-block; margin-left: 10px; text-decoration: none;"> | ||
Continue Without Setting Date | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters