Suggestions + QOL changes

This commit is contained in:
zandercymatics 2024-08-15 08:59:05 -06:00
parent 6a343634f4
commit 9059ce3281
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
6 changed files with 53 additions and 18 deletions

View file

@ -3060,15 +3060,7 @@ class PortfolioAdmin(ListHeaderAdmin):
def change_view(self, request, object_id, form_url="", extra_context=None): def change_view(self, request, object_id, form_url="", extra_context=None):
"""Add related suborganizations and domain groups""" """Add related suborganizations and domain groups"""
obj = self.get_object(request, object_id) extra_context = {"skip_additional_contact_info": True}
# ---- Domain Groups
domain_groups = DomainGroup.objects.filter(portfolio=obj)
# ---- Suborganizations
suborganizations = Suborganization.objects.filter(portfolio=obj)
extra_context = {"domain_groups": domain_groups, "suborganizations": suborganizations}
return super().change_view(request, object_id, form_url, extra_context) return super().change_view(request, object_id, form_url, extra_context)
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):

View file

@ -765,13 +765,18 @@ function initializeWidgetOnList(list, parentId) {
*/ */
(function dynamicPortfolioFields(){ (function dynamicPortfolioFields(){
// the federal agency change listener fires on page load, which we don't want.
var isInitialPageLoad = true
// This is the additional information that exists beneath the SO element.
var contactList = document.querySelector(".field-senior_official .dja-address-contact-list");
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
let isPortfolioPage = document.getElementById("portfolio_form"); let isPortfolioPage = document.getElementById("portfolio_form");
if (!isPortfolioPage) { if (!isPortfolioPage) {
return; return;
} }
// $ symbolically denotes that this is using jQuery // $ symbolically denotes that this is using jQuery
let $federalAgency = django.jQuery("#id_federal_agency"); let $federalAgency = django.jQuery("#id_federal_agency");
let organizationType = document.getElementById("id_organization_type"); let organizationType = document.getElementById("id_organization_type");
@ -797,6 +802,12 @@ function initializeWidgetOnList(list, parentId) {
}); });
function handleFederalAgencyChange(federalAgency, organizationType) { function handleFederalAgencyChange(federalAgency, organizationType) {
// Don't do anything on page load
if (isInitialPageLoad) {
isInitialPageLoad = false;
return;
}
// Set the org type to federal if an agency is selected // Set the org type to federal if an agency is selected
let selectedText = federalAgency.find("option:selected").text(); let selectedText = federalAgency.find("option:selected").text();
@ -822,6 +833,10 @@ function initializeWidgetOnList(list, parentId) {
return; return;
} }
// Hide the contactList initially.
// If we can update the contact information, it'll be shown again.
hideElement(contactList.parentElement);
let seniorOfficialApi = document.getElementById("senior_official_from_agency_json_url").value; let seniorOfficialApi = document.getElementById("senior_official_from_agency_json_url").value;
fetch(`${seniorOfficialApi}?agency_name=${selectedText}`) fetch(`${seniorOfficialApi}?agency_name=${selectedText}`)
.then(response => { .then(response => {
@ -840,6 +855,10 @@ function initializeWidgetOnList(list, parentId) {
return; return;
} }
// Update the "contact details" blurb beneath senior official
updateContactInfo(data);
showElement(contactList.parentElement);
let seniorOfficialId = data.id; let seniorOfficialId = data.id;
let seniorOfficialName = [data.first_name, data.last_name].join(" "); let seniorOfficialName = [data.first_name, data.last_name].join(" ");
if (!seniorOfficialId || !seniorOfficialName || !seniorOfficialName.trim()){ if (!seniorOfficialId || !seniorOfficialName || !seniorOfficialName.trim()){
@ -862,6 +881,22 @@ function initializeWidgetOnList(list, parentId) {
.catch(error => console.error("Error fetching senior official: ", error)); .catch(error => console.error("Error fetching senior official: ", error));
} }
function updateContactInfo(data) {
if (!contactList) return;
const titleSpan = contactList.querySelector("#contact_info_title");
const emailSpan = contactList.querySelector("#contact_info_email");
const phoneSpan = contactList.querySelector("#contact_info_phone");
if (titleSpan) titleSpan.textContent = data.title || "";
if (emailSpan) {
emailSpan.textContent = data.email || "";
const clipboardInput = contactList.querySelector(".admin-icon-group input");
if (clipboardInput) clipboardInput.value = data.email || "";
}
if (phoneSpan) phoneSpan.textContent = data.phone || "";
}
function handleStateTerritoryChange(stateTerritory, urbanizationField) { function handleStateTerritoryChange(stateTerritory, urbanizationField) {
let selectedValue = stateTerritory.value; let selectedValue = stateTerritory.value;
if (selectedValue === "PR") { if (selectedValue === "PR") {

View file

@ -54,10 +54,6 @@ class SeniorOfficial(TimeStampedModel):
names = [n for n in [self.first_name, self.last_name] if n] names = [n for n in [self.first_name, self.last_name] if n]
return " ".join(names) if names else "Unknown" return " ".join(names) if names else "Unknown"
def has_contact_info(self):
"""Determines if this user has contact information, such as an email or phone number."""
return bool(self.title or self.email or self.phone)
def __str__(self): def __str__(self):
if self.first_name or self.last_name: if self.first_name or self.last_name:
return self.get_formatted_name() return self.get_formatted_name()

View file

@ -1,4 +1,5 @@
{% load i18n static %} {% load i18n static %}
{% load custom_filters %}
<address class="{% if no_title_top_padding %}margin-top-neg-1__detail-list{% endif %} {% if user.has_contact_info %}margin-bottom-1{% endif %} dja-address-contact-list"> <address class="{% if no_title_top_padding %}margin-top-neg-1__detail-list{% endif %} {% if user.has_contact_info %}margin-bottom-1{% endif %} dja-address-contact-list">
@ -12,7 +13,7 @@
</br> </br>
{% endif %} {% endif %}
{% if user.has_contact_info %} {% if user|has_contact_info %}
{# Title #} {# Title #}
{% if user.title %} {% if user.title %}
<span id="contact_info_title">{{ user.title }}</span> <span id="contact_info_title">{{ user.title }}</span>
@ -42,7 +43,7 @@
No additional contact information found.<br> No additional contact information found.<br>
{% endif %} {% endif %}
{% if user_verification_type %} {% if user_verification_type and not skip_additional_contact_info %}
<span id="contact_info_phone">{{ user_verification_type }}</span> <span id="contact_info_phone">{{ user_verification_type }}</span>
{% endif %} {% endif %}
</address> </address>

View file

@ -184,7 +184,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
<label aria-label="Creator contact details"></label> <label aria-label="Creator contact details"></label>
{% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly user_verification_type=original_object.creator.get_verification_type_display%} {% include "django/admin/includes/contact_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly user_verification_type=original_object.creator.get_verification_type_display%}
</div> </div>
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %} {% if not skip_additional_contact_info %}
{% include "django/admin/includes/user_detail_list.html" with user=original_object.creator no_title_top_padding=field.is_readonly %}
{% endif%}
{% elif field.field.name == "submitter" %} {% elif field.field.name == "submitter" %}
<div class="flex-container tablet:margin-top-2"> <div class="flex-container tablet:margin-top-2">
<label aria-label="Submitter contact details"></label> <label aria-label="Submitter contact details"></label>

View file

@ -159,3 +159,12 @@ def and_filter(value, arg):
Usage: {{ value|and:arg }} Usage: {{ value|and:arg }}
""" """
return bool(value and arg) return bool(value and arg)
@register.filter(name="has_contact_info")
def has_contact_info(user):
"""Checks if the given object has the attributes: title, email, phone
and checks if at least one of those is not null."""
if not hasattr(user, "title") or not hasattr(user, "email") or not hasattr(user, "phone"):
return False
else:
return bool(user.title or user.email or user.phone)