mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 20:18:38 +02:00
Suggestions + QOL changes
This commit is contained in:
parent
6a343634f4
commit
9059ce3281
6 changed files with 53 additions and 18 deletions
|
@ -3060,15 +3060,7 @@ class PortfolioAdmin(ListHeaderAdmin):
|
|||
|
||||
def change_view(self, request, object_id, form_url="", extra_context=None):
|
||||
"""Add related suborganizations and domain groups"""
|
||||
obj = self.get_object(request, object_id)
|
||||
|
||||
# ---- Domain Groups
|
||||
domain_groups = DomainGroup.objects.filter(portfolio=obj)
|
||||
|
||||
# ---- Suborganizations
|
||||
suborganizations = Suborganization.objects.filter(portfolio=obj)
|
||||
|
||||
extra_context = {"domain_groups": domain_groups, "suborganizations": suborganizations}
|
||||
extra_context = {"skip_additional_contact_info": True}
|
||||
return super().change_view(request, object_id, form_url, extra_context)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
|
|
|
@ -765,13 +765,18 @@ function initializeWidgetOnList(list, parentId) {
|
|||
*/
|
||||
(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() {
|
||||
|
||||
|
||||
let isPortfolioPage = document.getElementById("portfolio_form");
|
||||
if (!isPortfolioPage) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// $ symbolically denotes that this is using jQuery
|
||||
let $federalAgency = django.jQuery("#id_federal_agency");
|
||||
let organizationType = document.getElementById("id_organization_type");
|
||||
|
@ -797,6 +802,12 @@ function initializeWidgetOnList(list, parentId) {
|
|||
});
|
||||
|
||||
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
|
||||
let selectedText = federalAgency.find("option:selected").text();
|
||||
|
||||
|
@ -822,6 +833,10 @@ function initializeWidgetOnList(list, parentId) {
|
|||
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;
|
||||
fetch(`${seniorOfficialApi}?agency_name=${selectedText}`)
|
||||
.then(response => {
|
||||
|
@ -840,6 +855,10 @@ function initializeWidgetOnList(list, parentId) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Update the "contact details" blurb beneath senior official
|
||||
updateContactInfo(data);
|
||||
showElement(contactList.parentElement);
|
||||
|
||||
let seniorOfficialId = data.id;
|
||||
let seniorOfficialName = [data.first_name, data.last_name].join(" ");
|
||||
if (!seniorOfficialId || !seniorOfficialName || !seniorOfficialName.trim()){
|
||||
|
@ -862,6 +881,22 @@ function initializeWidgetOnList(list, parentId) {
|
|||
.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) {
|
||||
let selectedValue = stateTerritory.value;
|
||||
if (selectedValue === "PR") {
|
||||
|
|
|
@ -54,10 +54,6 @@ class SeniorOfficial(TimeStampedModel):
|
|||
names = [n for n in [self.first_name, self.last_name] if n]
|
||||
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):
|
||||
if self.first_name or self.last_name:
|
||||
return self.get_formatted_name()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% 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">
|
||||
|
||||
|
@ -12,7 +13,7 @@
|
|||
</br>
|
||||
{% endif %}
|
||||
|
||||
{% if user.has_contact_info %}
|
||||
{% if user|has_contact_info %}
|
||||
{# Title #}
|
||||
{% if user.title %}
|
||||
<span id="contact_info_title">{{ user.title }}</span>
|
||||
|
@ -42,7 +43,7 @@
|
|||
No additional contact information found.<br>
|
||||
{% endif %}
|
||||
|
||||
{% if user_verification_type %}
|
||||
{% if user_verification_type and not skip_additional_contact_info %}
|
||||
<span id="contact_info_phone">{{ user_verification_type }}</span>
|
||||
{% endif %}
|
||||
</address>
|
||||
|
|
|
@ -184,7 +184,9 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
|
|||
<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%}
|
||||
</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" %}
|
||||
<div class="flex-container tablet:margin-top-2">
|
||||
<label aria-label="Submitter contact details"></label>
|
||||
|
|
|
@ -159,3 +159,12 @@ def and_filter(value, arg):
|
|||
Usage: {{ 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)
|
Loading…
Add table
Add a link
Reference in a new issue