PR suggestions (slight refactor)

This commit is contained in:
zandercymatics 2024-03-28 09:15:48 -06:00
parent 3e740f4668
commit ea59232cef
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
6 changed files with 73 additions and 98 deletions

View file

@ -1123,7 +1123,7 @@ class DomainRequestAdmin(ListHeaderAdmin):
]
# Readonly fields for analysts and superusers
readonly_fields = ("other_contacts", "current_websites")
readonly_fields = ("other_contacts", "current_websites", "alternative_domains")
# Read only that we'll leverage for CISA Analysts
analyst_readonly_fields = [

View file

@ -170,35 +170,6 @@ function checkToListThenInitWidget(toListId, attempts) {
}
}
(function() {
function addUrlsToOtherContacts() {
document.addEventListener('DOMContentLoaded', function() {
// Select all table rows that have a data-contact-id attribute
let contactRows = document.querySelectorAll("tr[data-contact-url]");
if (!contactRows || contactRows.length == 0) {
contactRows = document.querySelectorAll(".other-contact-id")
}
if (contactRows){
// Add a click event listener to each row
let index = 1;
contactRows.forEach(function(row) {
let otherContactUrl = row.getAttribute("data-contact-url");
if (otherContactUrl){
let otherContact = document.querySelector(`.other-contact__${index}`);
if (otherContact) {
otherContact.href = otherContactUrl;
}
}
index++;
});
}
});
}
addUrlsToOtherContacts()
})();
// Initialize the widget:
// add related buttons to the widget for edit, delete and view
// add event listeners on the from list, the to list, and selector buttons which either enable or disable the related buttons

View file

@ -351,6 +351,7 @@ details.dja-detail-table {
display: inline-table;
background-color: var(--body-bg);
.dja-details-summary {
cursor: pointer;
color: var(--body-quiet-color);
}
@ -378,21 +379,15 @@ details.dja-detail-table {
}
ul.padding-left-0__detail-list {
padding-left: 0 !important;
}
ul.margin-left-0__detail-list {
margin-left: 0 !important;
}
ul.margin-top-neg-1__detail-list {
address.margin-top-neg-1__detail-list {
margin-top: -8px !important;
}
.dja-detail-list {
dl {
padding-left: 0px !important;
margin-top: 5px !important;
}
// Mimic the normal label size
dt {
@ -406,6 +401,11 @@ ul.margin-top-neg-1__detail-list {
}
}
address.dja-address-contact-list {
font-size: 0.8125rem;
color: var(--body-quiet-color);
}
// Mimic the normal label size
@media (max-width: 1024px){
.dja-detail-list dt {

View file

@ -1,42 +1,51 @@
{% load i18n static %}
<address class="{% if no_title_top_padding %}margin-top-neg-1__detail-list{% endif %} dja-address-contact-list">
{% if show_formatted_name %}
{% if contact.get_formatted_name %}
<a href="{% url 'admin:registrar_contact_change' user.id %}">{{ user.get_formatted_name }}</a><br />
{% else %}
None<br />
{% endif %}
{% endif %}
<ul class="{% if no_title_top_padding %}margin-top-neg-1__detail-list{% endif %} padding-top-0 padding-left-0__detail-list margin-left-0__detail-list" {% if field_name %} id="id_detail_list__{{field_name}}" {% endif %}>
{% if user.title or user.contact.title or user.email or user.contact.email or user.phone or user.contact.phone %}
{# Title #}
{% if user.title or user.contact.title %}
{% if user.contact.title %}
<li>{{ user.contact.title }}</li>
{{ user.contact.title }}
{% else %}
<li>{{ user.title }}</li>
{{ user.title }}
{% endif %}
<br>
{% else %}
<li>None</li>
None<br>
{% endif %}
{# Email #}
{% if user.email or user.contact.email %}
{% if user.contact.email %}
<li>{{ user.contact.email }}</li>
{{ user.contact.email }}
{% else %}
<li>{{ user.email }}</li>
{{ user.email }}
{% endif %}
<br>
{% else %}
<li>None</li>
None<br>
{% endif %}
{# Phone #}
{% if user.phone or user.contact.phone %}
{% if user.contact.phone %}</li>
<li>{{ user.contact.phone }}</li>
{% if user.contact.phone %}
{{ user.contact.phone }}
{% else %}
<li>{{ user.phone }}</li>
{{ user.phone }}
{% endif %}
<br>
{% else %}
<li>None</li>
None<br>
{% endif %}
{% else %}
<li>
No additional contact information found.
</li>
No additional contact information found.
{% endif %}
</ul>
</address>

View file

@ -9,24 +9,19 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% if field.field.name == "other_contacts" %}
{% if all_contacts.count > 2 %}
<div class="readonly">
{% for contact in field.contents|split:", " %}
<a href="#" class="other-contact__{{forloop.counter}}">{{ contact }}</a>{% if not forloop.last %}, {% endif %}
{% for contact in all_contacts %}
<a href="{% url 'admin:registrar_contact_change' contact.id %}">{{ contact.get_formatted_name }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</div>
{% else %}
<div class="flex-container dja-detail-list">
<dl class="usa-list usa-list--unstyled margin-0 margin-top-1">
<dl class="usa-list usa-list--unstyled margin-0">
{% for contact in all_contacts %}
<dt class="{% if forloop.counter == 1%}margin-top-0{% endif %}">
Organization contact {{forloop.counter}}
</dt>
<dd>
<address>
{% if contact.get_formatted_name %}<a href="{% url 'admin:registrar_contact_change' contact.id %}">{{ contact.get_formatted_name }}</a><br />{% else %}None<br />{% endif %}
{% if contact.title %}{{ contact.title }}<br />{% else %}None<br />{% endif %}
{% if contact.email %}{{ contact.email }}<br />{% else %}None<br />{% endif %}
{% if contact.phone %}{{ contact.phone }}{% else %}None{% endif %}
</address>
{% include "django/admin/includes/contact_detail_list.html" with user=contact show_formatted_name=True %}
</dd>
{% endfor %}
</dl>
@ -52,6 +47,12 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% endfor %}
{% endwith %}
</div>
{% elif field.field.name == "alternative_domains" %}
<div class="readonly">
{% for alt_domain in original.alternative_domains.all %}
<a href="{% url 'admin:registrar_website_change' alt_domain.id %}">{{ alt_domain }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</div>
{% else %}
<div class="readonly">{{ field.contents }}</div>
{% endif %}
@ -62,17 +63,17 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
{% if field.field.name == "creator" %}
<div class="flex-container">
<label aria-label="Creator contact details"></label>
{% include "django/admin/includes/contact_detail_list.html" with user=original.creator field_name="creator" no_title_top_padding=field.is_readonly %}
{% include "django/admin/includes/contact_detail_list.html" with user=original.creator no_title_top_padding=field.is_readonly %}
</div>
{% elif field.field.name == "submitter" %}
<div class="flex-container">
<label aria-label="Submitter contact details"></label>
{% include "django/admin/includes/contact_detail_list.html" with user=original.submitter field_name="submitter" no_title_top_padding=field.is_readonly %}
{% include "django/admin/includes/contact_detail_list.html" with user=original.submitter no_title_top_padding=field.is_readonly %}
</div>
{% elif field.field.name == "authorizing_official" %}
<div class="flex-container">
<label aria-label="Authorizing official contact details"></label>
{% include "django/admin/includes/contact_detail_list.html" with user=original.authorizing_official field_name="authorizing_official" no_title_top_padding=field.is_readonly %}
{% include "django/admin/includes/contact_detail_list.html" with user=original.authorizing_official no_title_top_padding=field.is_readonly %}
</div>
{% elif field.field.name == "other_contacts" and original.other_contacts.all %}
{% with all_contacts=original.other_contacts.all %}
@ -83,17 +84,13 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
<table>
<thead>
<tr>
<th colspan="4">Contact information</th>
<th colspan="4">Other contact information</th>
<tr>
</thead>
<tbody>
{% for contact in all_contacts %}
{% comment %}
Since we can't get the id from field, we can embed this information here.
Then we can link these two fields using javascript.
{% endcomment %}
<tr data-contact-id="{{ contact.id }}" data-contact-url="{% url 'admin:registrar_contact_change' contact.id %}">
<th class="padding-left-1" scope="row">{{contact.first_name}} {{contact.last_name}}</th>
<tr>
<th class="padding-left-1" scope="row">{{ contact.get_formatted_name }}</th>
<td class="padding-left-1">{{ contact.title }}</td>
<td class="padding-left-1">{{ contact.email }}</td>
<td class="padding-left-1">{{ contact.phone }}</td>

View file

@ -1303,13 +1303,11 @@ class TestDomainRequestAdmin(MockEppLib):
# == Check for the creator == #
# Check for the right title, email, and phone number in the response.
# We only need to check for the end tag
# (Otherwise this test will fail if we change classes, etc)
expected_creator_fields = [
# Field, expected value
("title", "Treat inspector</li>"),
("email", "meoward.jones@igorville.gov</li>"),
("phone", "(555) 123 12345</li>"),
("title", "Treat inspector"),
("email", "meoward.jones@igorville.gov"),
("phone", "(555) 123 12345"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields)
@ -1319,9 +1317,9 @@ class TestDomainRequestAdmin(MockEppLib):
# == Check for the submitter == #
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester</li>"),
("email", "mayor@igorville.gov</li>"),
("phone", "(555) 555 5556</li>"),
("title", "Admin Tester"),
("email", "mayor@igorville.gov"),
("phone", "(555) 555 5556"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
@ -1329,15 +1327,15 @@ class TestDomainRequestAdmin(MockEppLib):
# == Check for the authorizing_official == #
expected_ao_fields = [
# Field, expected value
("title", "Chief Tester</li>"),
("email", "testy@town.com</li>"),
("phone", "(555) 555 5555</li>"),
("title", "Chief Tester"),
("email", "testy@town.com"),
("phone", "(555) 555 5555"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields)
# count=3 because the underlying domain has two users with this name.
# The dropdown has 2 of these.
self.assertContains(response, "Testy Tester", count=3)
# count=5 because the underlying domain has two users with this name.
# The dropdown has 3 of these.
self.assertContains(response, "Testy Tester", count=5)
# == Test the other_employees field == #
expected_other_employees_fields = [
@ -2022,9 +2020,9 @@ class TestDomainInformationAdmin(TestCase):
# (Otherwise this test will fail if we change classes, etc)
expected_creator_fields = [
# Field, expected value
("title", "Treat inspector</li>"),
("email", "meoward.jones@igorville.gov</li>"),
("phone", "(555) 123 12345</li>"),
("title", "Treat inspector"),
("email", "meoward.jones@igorville.gov"),
("phone", "(555) 123 12345"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields)
@ -2034,9 +2032,9 @@ class TestDomainInformationAdmin(TestCase):
# == Check for the submitter == #
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester</li>"),
("email", "mayor@igorville.gov</li>"),
("phone", "(555) 555 5556</li>"),
("title", "Admin Tester"),
("email", "mayor@igorville.gov"),
("phone", "(555) 555 5556"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
@ -2044,15 +2042,15 @@ class TestDomainInformationAdmin(TestCase):
# == Check for the authorizing_official == #
expected_ao_fields = [
# Field, expected value
("title", "Chief Tester</li>"),
("email", "testy@town.com</li>"),
("phone", "(555) 555 5555</li>"),
("title", "Chief Tester"),
("email", "testy@town.com"),
("phone", "(555) 555 5555"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields)
# count=3 because the underlying domain has two users with this name.
# The dropdown has 2 of these.
self.assertContains(response, "Testy Tester", count=3)
# count=5 because the underlying domain has two users with this name.
# The dropdown has 3 of these.
self.assertContains(response, "Testy Tester", count=5)
# == Test the other_employees field == #
expected_other_employees_fields = [