mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +02:00
Add default display logic
This commit is contained in:
parent
214fbc4d5d
commit
749cbeebe3
5 changed files with 41 additions and 20 deletions
|
@ -554,14 +554,23 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
if(actionNeededReasonDropdown && actionNeededEmail) {
|
if(actionNeededReasonDropdown && actionNeededEmail) {
|
||||||
let emailContainer = actionNeededEmail.closest(".dja-readonly-textarea-container");
|
let emailContainer = actionNeededEmail.closest(".dja-readonly-textarea-container");
|
||||||
if (statusDropdown.value == "action needed") {
|
if (statusDropdown.value == "action needed") {
|
||||||
showElement(emailContainer)
|
showElement(emailContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
statusDropdown.addEventListener("change", function() {
|
statusDropdown.addEventListener("change", function() {
|
||||||
if (statusDropdown.value == "action needed") {
|
if (statusDropdown.value == "action needed") {
|
||||||
showElement(emailContainer)
|
showElement(emailContainer);
|
||||||
}else {
|
}else {
|
||||||
hideElement(emailContainer)
|
hideElement(emailContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We hide the table if there isn't any data to start with.
|
||||||
|
// If we add a value, show it.
|
||||||
|
// This edge case applies to fixtures data. Prod data will have a changelog to pull from.
|
||||||
|
let changeLog = document.querySelector(".dja-status-changelog");
|
||||||
|
console.log(`value is ===>${actionNeededReasonDropdown.value}<===`)
|
||||||
|
if(changeLog && changeLog.classList.contains("display-none") && actionNeededReasonDropdown.value){
|
||||||
|
showElement(changeLog);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -572,8 +581,16 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
function handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail) {
|
function handleChangeActionNeededEmail(actionNeededReasonDropdown, actionNeededEmail) {
|
||||||
actionNeededReasonDropdown.addEventListener("change", function() {
|
actionNeededReasonDropdown.addEventListener("change", function() {
|
||||||
// TODO on change if not actionneeded on status, hide show email button
|
// TODO on change if not actionneeded on status, hide show email button
|
||||||
const pk = document.querySelector("#domain_request_id").value
|
const pk = document.querySelector("#domain_request_id").value;
|
||||||
const reason = actionNeededReasonDropdown.value
|
const reason = actionNeededReasonDropdown.value;
|
||||||
|
|
||||||
|
// If a reason isn't specified, no email will be sent.
|
||||||
|
// You also cannot save the model in this state.
|
||||||
|
if(!reason) {
|
||||||
|
actionNeededEmail.value = "No email will be sent";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fetch(`/get-domain-requests-json/${pk}/action-needed-email/${reason}`)
|
fetch(`/get-domain-requests-json/${pk}/action-needed-email/${reason}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
@ -581,13 +598,9 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
console.log('Error in AJAX call: ' + data.error);
|
console.log('Error in AJAX call: ' + data.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let noEmailMessage = document.getElementById("no-email-message");
|
|
||||||
if(data && data.email_body_text) {
|
if(data && data.email_body_text) {
|
||||||
actionNeededEmail.value = data.email_body_text
|
actionNeededEmail.value = data.email_body_text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}else if (data && !data.email_body_text) {
|
}else if (data && !data.email_body_text) {
|
||||||
actionNeededEmail.value = "No email will be sent";
|
actionNeededEmail.value = "No email will be sent";
|
||||||
}
|
}
|
||||||
|
@ -597,7 +610,6 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -823,4 +823,4 @@ div.dja__model-description{
|
||||||
|
|
||||||
.no-border {
|
.no-border {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -614,7 +614,8 @@ class DomainRequest(TimeStampedModel):
|
||||||
|
|
||||||
def sync_action_needed_reason_email(self):
|
def sync_action_needed_reason_email(self):
|
||||||
"""If no action_needed_reason_email is defined, add a default one"""
|
"""If no action_needed_reason_email is defined, add a default one"""
|
||||||
if self.action_needed_reason and not self.action_needed_reason_email:
|
# Change this in #1901. Add a check on "not self.action_needed_reason_email"
|
||||||
|
if self.action_needed_reason:
|
||||||
text = self.get_action_needed_reason_default_email_text(self.action_needed_reason)
|
text = self.get_action_needed_reason_default_email_text(self.action_needed_reason)
|
||||||
self.action_needed_reason_email = text.get("email_body_text")
|
self.action_needed_reason_email = text.get("email_body_text")
|
||||||
|
|
||||||
|
@ -852,8 +853,6 @@ class DomainRequest(TimeStampedModel):
|
||||||
can_send_email = False
|
can_send_email = False
|
||||||
|
|
||||||
# TODO - replace this logic with self.action_needed_reason_email in #1901.
|
# 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.
|
# 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.
|
# 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:
|
if not email_template_name and not email_template_subject_name:
|
||||||
|
|
|
@ -68,11 +68,12 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
||||||
{% endblock field_readonly %}
|
{% endblock field_readonly %}
|
||||||
|
|
||||||
{% block after_help_text %}
|
{% block after_help_text %}
|
||||||
{% if field.field.name == "status" and filtered_audit_log_entries %}
|
{% if field.field.name == "status" %}
|
||||||
<div class="flex-container" id="dja-status-changelog">
|
<div class="flex-container {% if not filtered_audit_log_entries or not action_needed_reason %}display-none{% endif %}" id="dja-status-changelog">
|
||||||
<label aria-label="Status changelog"></label>
|
<label aria-label="Status changelog"></label>
|
||||||
<div>
|
<div>
|
||||||
<div class="usa-table-container--scrollable collapse--dgsimple collapsed" tabindex="0">
|
<div class="usa-table-container--scrollable collapse--dgsimple collapsed" tabindex="0">
|
||||||
|
{% if filtered_audit_log_entries %}
|
||||||
<table class="usa-table usa-table--borderless">
|
<table class="usa-table usa-table--borderless">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -105,6 +106,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="dja-readonly-textarea-container padding-1 margin-top-2 thin-border display-none">
|
<div class="dja-readonly-textarea-container padding-1 margin-top-2 thin-border display-none">
|
||||||
<label class="max-full" for="action_needed_reason_email_view_more">
|
<label class="max-full" for="action_needed_reason_email_view_more">
|
||||||
|
|
|
@ -106,9 +106,17 @@ def get_domain_requests_json(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def get_action_needed_email(request, pk, reason):
|
def get_action_needed_email(request, pk, reason):
|
||||||
has_access = request.user.is_staff or request.user.is_superuser
|
"""
|
||||||
# TODO also check the perm group
|
Given the primary key of a DomainRequest and the action_needed reason,
|
||||||
if not has_access:
|
this will return the email that would be generated for the given user.
|
||||||
|
"""
|
||||||
|
# Q: Do we need both checks? I'd think we can just check on the group, right?
|
||||||
|
staff_or_superuser = request.user.is_staff or request.user.is_superuser
|
||||||
|
has_access = (
|
||||||
|
request.user.has_perm("registrar.full_access_permission") or
|
||||||
|
request.user.has_perm("registrar.analyst_access_permission")
|
||||||
|
)
|
||||||
|
if staff_or_superuser and not has_access:
|
||||||
raise PermissionDenied("You do not have permission to access this resource.")
|
raise PermissionDenied("You do not have permission to access this resource.")
|
||||||
|
|
||||||
domain_request = DomainRequest.objects.filter(id=pk).first()
|
domain_request = DomainRequest.objects.filter(id=pk).first()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue