mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-28 13:36:30 +02:00
Make senior official readonly
This commit is contained in:
parent
2430d3ecf6
commit
02bf9c4781
4 changed files with 51 additions and 24 deletions
|
@ -2982,6 +2982,8 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
"display_admins",
|
"display_admins",
|
||||||
"display_members",
|
"display_members",
|
||||||
"creator",
|
"creator",
|
||||||
|
# As of now this means that only federal agency can update this, but this will change.
|
||||||
|
"senior_official",
|
||||||
]
|
]
|
||||||
|
|
||||||
analyst_readonly_fields = [
|
analyst_readonly_fields = [
|
||||||
|
@ -3208,6 +3210,11 @@ class PortfolioAdmin(ListHeaderAdmin):
|
||||||
is_federal = obj.organization_type == DomainRequest.OrganizationChoices.FEDERAL
|
is_federal = obj.organization_type == DomainRequest.OrganizationChoices.FEDERAL
|
||||||
if is_federal and obj.organization_name is None:
|
if is_federal and obj.organization_name is None:
|
||||||
obj.organization_name = obj.federal_agency.agency
|
obj.organization_name = obj.federal_agency.agency
|
||||||
|
|
||||||
|
# Remove this line when senior_official is no longer readonly in /admin.
|
||||||
|
if obj.federal_agency and obj.federal_agency.so_federal_agency.exists():
|
||||||
|
obj.senior_official = obj.federal_agency.so_federal_agency.first()
|
||||||
|
|
||||||
super().save_model(request, obj, form, change)
|
super().save_model(request, obj, form, change)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -937,13 +937,6 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the associated senior official with this federal agency
|
|
||||||
let $seniorOfficial = django.jQuery("#id_senior_official");
|
|
||||||
if (!$seniorOfficial) {
|
|
||||||
console.log("Could not find the senior official field");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if any changes are necessary to the display of portfolio type or federal type
|
// Determine if any changes are necessary to the display of portfolio type or federal type
|
||||||
// based on changes to the Federal Agency
|
// based on changes to the Federal Agency
|
||||||
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
|
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
|
||||||
|
@ -965,6 +958,7 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
// If we can update the contact information, it'll be shown again.
|
// If we can update the contact information, it'll be shown again.
|
||||||
hideElement(contactList.parentElement);
|
hideElement(contactList.parentElement);
|
||||||
|
|
||||||
|
let $seniorOfficial = django.jQuery("#id_senior_official");
|
||||||
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 => {
|
||||||
|
@ -986,30 +980,44 @@ function initializeWidgetOnList(list, parentId) {
|
||||||
// Update the "contact details" blurb beneath senior official
|
// Update the "contact details" blurb beneath senior official
|
||||||
updateContactInfo(data);
|
updateContactInfo(data);
|
||||||
showElement(contactList.parentElement);
|
showElement(contactList.parentElement);
|
||||||
|
|
||||||
|
// Get the associated senior official with this federal agency
|
||||||
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 (!$seniorOfficial) {
|
||||||
// Clear the field if the SO doesn't exist
|
// If the senior official is a dropdown field, edit that
|
||||||
$seniorOfficial.val("").trigger("change");
|
updateSeniorOfficialDropdown($seniorOfficial, seniorOfficialId, seniorOfficialName);
|
||||||
return;
|
}else {
|
||||||
}
|
let readonlySeniorOfficial = document.querySelector(".field-senior_official .readonly");
|
||||||
|
if (readonlySeniorOfficial) {
|
||||||
// Add the senior official to the dropdown.
|
let seniorOfficialLink = `<a href=/admin/registrar/seniorofficial/${seniorOfficialId}/change/>${seniorOfficialName}</a>`
|
||||||
// This format supports select2 - if we decide to convert this field in the future.
|
readonlySeniorOfficial.innerHTML = seniorOfficialName ? seniorOfficialLink : "-";
|
||||||
if ($seniorOfficial.find(`option[value='${seniorOfficialId}']`).length) {
|
}
|
||||||
// Select the value that is associated with the current Senior Official.
|
|
||||||
$seniorOfficial.val(seniorOfficialId).trigger("change");
|
|
||||||
} else {
|
|
||||||
// Create a DOM Option that matches the desired Senior Official. Then append it and select it.
|
|
||||||
let userOption = new Option(seniorOfficialName, seniorOfficialId, true, true);
|
|
||||||
$seniorOfficial.append(userOption).trigger("change");
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => console.error("Error fetching senior official: ", error));
|
.catch(error => console.error("Error fetching senior official: ", error));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSeniorOfficialDropdown(dropdown, seniorOfficialId, seniorOfficialName) {
|
||||||
|
if (!seniorOfficialId || !seniorOfficialName || !seniorOfficialName.trim()){
|
||||||
|
// Clear the field if the SO doesn't exist
|
||||||
|
dropdown.val("").trigger("change");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the senior official to the dropdown.
|
||||||
|
// This format supports select2 - if we decide to convert this field in the future.
|
||||||
|
if (dropdown.find(`option[value='${seniorOfficialId}']`).length) {
|
||||||
|
// Select the value that is associated with the current Senior Official.
|
||||||
|
dropdown.val(seniorOfficialId).trigger("change");
|
||||||
|
} else {
|
||||||
|
// Create a DOM Option that matches the desired Senior Official. Then append it and select it.
|
||||||
|
let userOption = new Option(seniorOfficialName, seniorOfficialId, true, true);
|
||||||
|
dropdown.append(userOption).trigger("change");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleStateTerritoryChange(stateTerritory, urbanizationField) {
|
function handleStateTerritoryChange(stateTerritory, urbanizationField) {
|
||||||
let selectedValue = stateTerritory.value;
|
let selectedValue = stateTerritory.value;
|
||||||
if (selectedValue === "PR") {
|
if (selectedValue === "PR") {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.10 on 2024-09-25 17:59
|
# Generated by Django 4.2.10 on 2024-09-26 15:09
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -45,4 +45,15 @@ class Migration(migrations.Migration):
|
||||||
null=True,
|
null=True,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="portfolio",
|
||||||
|
name="senior_official",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.PROTECT,
|
||||||
|
related_name="portfolios",
|
||||||
|
to="registrar.seniorofficial",
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -61,6 +61,7 @@ class Portfolio(TimeStampedModel):
|
||||||
unique=False,
|
unique=False,
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
related_name="portfolios",
|
||||||
)
|
)
|
||||||
|
|
||||||
address_line1 = models.CharField(
|
address_line1 = models.CharField(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue