Add conditional "confirm" logic

This commit is contained in:
zandercymatics 2024-02-08 11:43:56 -07:00
parent 612f967c6f
commit df70a179e8
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 25 additions and 19 deletions

View file

@ -44,27 +44,24 @@ function openInNewTab(el, removeAttribute = false){
domainSubmitButton.addEventListener("mouseover", () => openInNewTab(domainFormElement, true));
domainSubmitButton.addEventListener("mouseout", () => openInNewTab(domainFormElement, false));
}
let extendExpirationDateButton = document.getElementById("extend-expiration-button")
let confirmationButtons = document.querySelector(".admin-confirmation-buttons")
let cancelExpirationButton = document.getElementById("cancel-extend-button")
if (extendExpirationDateButton && confirmationButtons && cancelExpirationButton){
let extendExpirationDateButton = document.getElementById("extend_expiration_date_button")
if (extendExpirationDateButton){
// Tie logic to the extend button to show confirmation options
extendExpirationDateButton.addEventListener("click", () => {
form = document.getElementById("domain_form")
/*
For some reason, Django admin has the propensity to ignore nested
inputs and delete nested form objects.
The workaround is to manually create an element as so, after the DOM
has been generated.
extendExpirationDateButton.hidden = true
console.log("these are the buttons: ")
console.log(confirmationButtons)
confirmationButtons.hidden = false
})
Its not the most beautiful thing every, but it works.
*/
var input = document.createElement("input");
input.type = "hidden";
input.name = "_extend_expiration_date";
// The value doesn't matter, just needs to be present
input.value = "1";
// Add the hidden input to the form
form.appendChild(input);
form.submit();
// Tie logic to the cancel button to hide the confirmation options
cancelExpirationButton.addEventListener("click", () => {
confirmationButtons.hidden = true
extendExpirationDateButton.hidden = false
})
}
}

View file

@ -283,6 +283,11 @@ h1, h2, h3,
}
}
.usa-button{
font-size: 14px;
font-weight: normal;
}
// Button groups in /admin incorrectly have bullets.
// Remove that!
.usa-button-group .usa-button-group__item {

View file

@ -11,7 +11,11 @@
</div>
<div class="desktop:flex-align-self-end">
{% if original.state != original.State.DELETED %}
<input type="submit" value="Extend expiration date" name="_extend_expiration_date" class="custom-link-button">
<span class="admin-confirmation-buttons" hidden>
<button type="submit" class="usa-button" name="_extend_expiration_date">Confirm extension</button>
<button type="button" id="cancel-extend-button" class="usa-button usa-button--secondary">Cancel</button>
</span>
<input id="extend-expiration-button" type="button" value="Extend expiration date" class="custom-link-button">
{% endif %}
<span class="margin-left-05 margin-right-05 text-middle"> | </span>
{% if original.state == original.State.READY %}