mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Add field
This commit is contained in:
parent
9f89f2e2ff
commit
2e5f564ae6
6 changed files with 140 additions and 3 deletions
|
@ -1485,6 +1485,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
"status",
|
||||
"rejection_reason",
|
||||
"action_needed_reason",
|
||||
"action_needed_reason_email",
|
||||
"investigator",
|
||||
"creator",
|
||||
"submitter",
|
||||
|
|
|
@ -57,6 +57,7 @@ function openInNewTab(el, removeAttribute = false){
|
|||
createPhantomModalFormButtons();
|
||||
})();
|
||||
|
||||
|
||||
/** An IIFE for DomainRequest to hook a modal to a dropdown option.
|
||||
* This intentionally does not interact with createPhantomModalFormButtons()
|
||||
*/
|
||||
|
@ -518,3 +519,79 @@ function initializeWidgetOnList(list, parentId) {
|
|||
handleShowMoreButton(toggleButton, descriptionDiv)
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
|
||||
/** An IIFE that hooks up to the "show email" button
|
||||
* which shows the auto generated email on action needed reason
|
||||
*/
|
||||
(function () {
|
||||
let statusDropdown = document.getElementById("id_status");
|
||||
|
||||
statusDropdown.addEventListener('change', function() {
|
||||
// TODO we should also handle when action needed
|
||||
if (statusDropdown.value != "action needed"){
|
||||
formRow.classList.add("display-none")
|
||||
}
|
||||
});
|
||||
|
||||
let actionNeededDropdownReason = document.getElementById("id_action_needed_reason");
|
||||
// Store the domain request id on this record for simplicity
|
||||
let showEmailButton = document.getElementById("show_action_needed_email");
|
||||
let actionNeededEmail = document.getElementById("id_action_needed_reason_email")
|
||||
let formRow = actionNeededEmail.closest('.form-row');
|
||||
if(actionNeededDropdownReason && showEmailButton && actionNeededEmail && formRow) {
|
||||
actionNeededDropdownReason.addEventListener('change', function() {
|
||||
// TODO on change if not actionneeded on status, hide show email button
|
||||
const pk = showEmailButton.getAttribute("domain-request-id")
|
||||
const reason = actionNeededDropdownReason.value
|
||||
fetch(`/get-domain-requests-json/${pk}/action-needed-email/${reason}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.error) {
|
||||
console.log('Error in AJAX call: ' + data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
let noEmailMessage = document.getElementById("no-email-message");
|
||||
if(data && data.email_body_text) {
|
||||
actionNeededEmail.value = data.email_body_text
|
||||
|
||||
// Show the text field
|
||||
if(actionNeededEmail.classList.contains("display-none")) {
|
||||
actionNeededEmail.classList.remove("display-none")
|
||||
}
|
||||
|
||||
// Hide the message
|
||||
if(noEmailMessage && !noEmailMessage.classList.contains("display-none")) {
|
||||
noEmailMessage.classList.add("display-none")
|
||||
}
|
||||
|
||||
}else if (data && !data.email_body_text) {
|
||||
if (!noEmailMessage) {
|
||||
noEmailMessage = document.createElement("p");
|
||||
noEmailMessage.id = "no-email-message";
|
||||
noEmailMessage.textContent = "No email will be sent";
|
||||
actionNeededEmail.parentNode.appendChild(noEmailMessage);
|
||||
}
|
||||
|
||||
// Hide the text field
|
||||
if(!actionNeededEmail.classList.contains("display-none")) {
|
||||
actionNeededEmail.classList.add("display-none")
|
||||
}
|
||||
|
||||
// Show the message
|
||||
if(noEmailMessage.classList.contains("display-none")) {
|
||||
noEmailMessage.classList.remove("display-none")
|
||||
}
|
||||
}
|
||||
console.log(data)
|
||||
});
|
||||
});
|
||||
|
||||
showEmailButton.addEventListener('click', function() {
|
||||
formRow.classList.remove("display-none")
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.2.10 on 2024-06-18 20:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("registrar", "0102_domain_dsdata_last_change"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="domainrequest",
|
||||
name="action_needed_reason_email",
|
||||
field=models.TextField(blank=True, null=True),
|
||||
),
|
||||
]
|
|
@ -295,6 +295,11 @@ class DomainRequest(TimeStampedModel):
|
|||
blank=True,
|
||||
)
|
||||
|
||||
action_needed_reason_email = models.TextField(
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
federal_agency = models.ForeignKey(
|
||||
"registrar.FederalAgency",
|
||||
on_delete=models.PROTECT,
|
||||
|
@ -547,7 +552,10 @@ class DomainRequest(TimeStampedModel):
|
|||
"""Returns the default email associated with the given action needed reason"""
|
||||
logger.info(f"reason? {action_needed_reason}")
|
||||
if action_needed_reason is None or action_needed_reason == self.ActionNeededReasons.OTHER:
|
||||
return {}
|
||||
return {
|
||||
"subject_text": None,
|
||||
"email_body_text": None,
|
||||
}
|
||||
|
||||
# Get the email body
|
||||
template_path = f"emails/action_needed_reasons/{action_needed_reason}.txt"
|
||||
|
@ -606,6 +614,11 @@ class DomainRequest(TimeStampedModel):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
"""Save override for custom properties"""
|
||||
|
||||
if self.action_needed_reason and not self.action_needed_reason_email:
|
||||
text = self.get_action_needed_reason_default_email_text(self.action_needed_reason)
|
||||
self.action_needed_reason_email = text.get("email_body_text")
|
||||
|
||||
self.sync_organization_type()
|
||||
self.sync_yes_no_form_fields()
|
||||
|
||||
|
@ -851,6 +864,9 @@ class DomainRequest(TimeStampedModel):
|
|||
# Unknown and other are default cases - do nothing
|
||||
can_send_email = False
|
||||
|
||||
# TODO - replace this logic with self.action_needed_reason_email in #1901.
|
||||
# The email content should be dependent on that field.
|
||||
|
||||
# Assumes that the template name matches the action needed reason if nothing is specified.
|
||||
# This is so you can override if you need, or have this taken care of for you.
|
||||
if not email_template_name and not email_template_subject_name:
|
||||
|
|
|
@ -106,12 +106,39 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<button type="button" class="collapse-toggle--dgsimple usa-button usa-button--unstyled margin-top-2 margin-bottom-1 margin-left-1">
|
||||
<span>Show details</span>
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
|
||||
<use xlink:href="/public/img/sprite.svg#expand_more"></use>
|
||||
</svg>
|
||||
</button>
|
||||
<button id="show_action_needed_email" domain-request-id="{{original_object.id}}" type="button" class="{% if field.field.value != "action needed" %}display-none{% endif %} collapse-toggle--dgsimple usa-button usa-button--unstyled margin-top-2 margin-bottom-1 margin-left-1">
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
|
||||
<use xlink:href="/public/img/sprite.svg#mail"></use>
|
||||
</svg>
|
||||
<span>Show email</span>
|
||||
</button>
|
||||
{% comment %}
|
||||
<div class="usa-button-group">
|
||||
<li class="usa-button-group__item">
|
||||
<button type="button" class="collapse-toggle--dgsimple usa-button usa-button--unstyled margin-top-2 margin-bottom-1 margin-left-1">
|
||||
<span>Show details</span>
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
|
||||
<use xlink:href="/public/img/sprite.svg#expand_more"></use>
|
||||
</svg>
|
||||
</button>
|
||||
</li>
|
||||
<li class="usa-button-group__item">
|
||||
<button id="show_action_needed_email" domain-request-id="{{original_object.id}}" type="button" class="{% if field.field.value != "action needed" %}display-none{% endif %} collapse-toggle--dgsimple usa-button usa-button--unstyled margin-top-2 margin-bottom-1 margin-left-1">
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
|
||||
<use xlink:href="/public/img/sprite.svg#mail"></use>
|
||||
</svg>
|
||||
<span>Show email</span>
|
||||
</button>
|
||||
</li>
|
||||
</div>
|
||||
{% endcomment %}
|
||||
</div>
|
||||
</div>
|
||||
{% elif field.field.name == "creator" %}
|
||||
|
|
|
@ -112,9 +112,7 @@ def get_action_needed_email(request, pk, reason):
|
|||
if not has_access:
|
||||
raise PermissionDenied("You do not have permission to access this resource.")
|
||||
|
||||
logger.info(f"pk: {pk} reason: {reason}")
|
||||
domain_request = DomainRequest.objects.filter(id=pk).first()
|
||||
|
||||
reason_dict = domain_request.get_action_needed_reason_default_email_text(reason)
|
||||
|
||||
return JsonResponse(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue