This commit is contained in:
zandercymatics 2024-07-30 10:30:01 -06:00
parent 82c9861dd5
commit 5183198d56
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
10 changed files with 151 additions and 9 deletions

View file

@ -1978,3 +1978,36 @@ document.addEventListener('DOMContentLoaded', function() {
showInputOnErrorFields();
})();
/**
* An IIFE that adds the default selection on comboboxes to the input field.
* This is because this action doesn't get fired by the time the page loads
* TODO: Will be refined in #2352
*/
(function loadInitialValuesForComboBoxes() {
document.addEventListener('DOMContentLoaded', (event) => {
const comboBoxElements = document.querySelectorAll('.usa-combo-box');
comboBoxElements.forEach(comboBox => {
const select = comboBox.querySelector('select');
const input = comboBox.querySelector('input');
// Find the selected option
const selectedOption = select.querySelector('option[selected]');
// If there's a selected option, set its text as the input value.
// If the default name is "------", then this indicates that the field is blank.
// Don't populate in this case.
if (selectedOption) {
// Check to make sure the value isn't just a line of dashes.
// Caveat: we can't have any suborgs named "------". This is OK.
const isEmptyValue = /^-+$/.test(selectedOption.textContent);
if (!isEmptyValue) {
input.value = selectedOption.textContent;
comboBox.classList.add('usa-combo-box--pristine');
}
}
});
});
})();

View file

@ -193,6 +193,11 @@ urlpatterns = [
views.DomainOrgNameAddressView.as_view(),
name="domain-org-name-address",
),
path(
"domain/<int:pk>/suborganization",
views.DomainSubOrganizationView.as_view(),
name="domain-suborganization",
),
path(
"domain/<int:pk>/senior-official",
views.DomainSeniorOfficialView.as_view(),

View file

@ -9,6 +9,7 @@ from .domain import (
DomainDnssecForm,
DomainDsdataFormset,
DomainDsdataForm,
DomainSuborganizationForm,
)
from .portfolio import (
PortfolioOrgAddressForm,

View file

@ -6,6 +6,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator, RegexVa
from django.forms import formset_factory
from registrar.models import DomainRequest
from phonenumber_field.widgets import RegionalPhoneNumberWidget
from registrar.models.suborganization import Suborganization
from registrar.models.utility.domain_helper import DomainHelper
from registrar.utility.errors import (
NameserverError,
@ -153,6 +154,45 @@ class DomainNameserverForm(forms.Form):
self.add_error("ip", str(e))
class DomainSuborganizationForm(forms.ModelForm):
"""Form for updating the suborganization"""
sub_organization = forms.ModelChoiceField(
queryset=Suborganization.objects.none(),
required=True,
widget=forms.Select(),
)
class Meta:
model = DomainInformation
fields = [
"sub_organization",
]
def __init__(self, *args, **kwargs):
# Get the incoming request object
self.request = kwargs.pop("request", None)
super().__init__(*args, **kwargs)
portfolio = None
if self.instance and self.instance.portfolio:
# Get suborgs under the portfolio that this is associated with first
portfolio = self.instance.portfolio
elif self.request and self.request.user and self.request.user.portfolio:
# Question: If no portfolio is associated with this record,
# should we default to the user one?
# portfolio = self.request.user.portfolio
logger.warning(f"No portfolio was found for {self.instance}.")
self.fields["sub_organization"].queryset = Suborganization.objects.filter(portfolio=portfolio)
# Set custom form label
self.fields["sub_organization"].label = "Suborganization name"
# Use the combobox rather than the regular select widget
self.fields["sub_organization"].widget.template_name = "django/forms/widgets/combobox.html"
class BaseNameserverFormset(forms.BaseFormSet):
def clean(self):
"""

View file

@ -0,0 +1,3 @@
<div class="usa-combo-box">
{% include "django/forms/widgets/select.html" %}
</div>

View file

@ -54,10 +54,8 @@
{% endif %}
{% if is_org_user %}
{% comment %} TODO - uncomment in #2352 and add to edit_link
{% url 'domain-suborganization' pk=domain.id as url %}
{% endcomment %}
{% include "includes/summary_item.html" with title='Suborganization' value=domain.domain_info.sub_organization edit_link="#" editable=domain.is_editable %}
{% include "includes/summary_item.html" with title='Suborganization' value=domain.domain_info.sub_organization edit_link=url editable=domain.is_editable %}
{% else %}
{% url 'domain-org-name-address' pk=domain.id as url %}
{% include "includes/summary_item.html" with title='Organization name and mailing address' value=domain.domain_info address='true' edit_link=url editable=domain.is_editable %}

View file

@ -9,14 +9,9 @@
{% endwith %}
{% if is_org_user %}
{% comment %} TODO - uncomment in #2352
{% with url_name="domain-suborganization" %}
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
{% endwith %}
{% endcomment %}
{% with url="#" %}
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
{% endwith %}
{% else %}
{% with url_name="domain-org-name-address" %}
{% include "includes/domain_sidenav_item.html" with item_text="Organization name and mailing address" %}

View file

@ -0,0 +1,28 @@
{% extends "domain_base.html" %}
{% load static field_helpers%}
{% block title %}Suborganization{% endblock %}
{% block domain_content %}
{# this is right after the messages block in the parent template #}
{% include "includes/form_errors.html" with form=form %}
<h1>Organization name and mailing address </h1>
<p>
The name of your suborganization will be publicly listed as the domain registrant.
This list of suborganizations has been populated the .gov program.
If you believe there is an error please contact <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a>.
</p>
{% if suborganization_is_editable %}
{% include "includes/required_fields.html" %}
{% endif %}
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
{% input_with_errors form.sub_organization %}
<button type="submit" class="usa-button">Save</button>
</form>
{% endblock %}

View file

@ -3,6 +3,7 @@ from .domain import (
DomainView,
DomainSeniorOfficialView,
DomainOrgNameAddressView,
DomainSubOrganizationView,
DomainDNSView,
DomainNameserversView,
DomainDNSSECView,

View file

@ -15,7 +15,7 @@ from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic.edit import FormMixin
from django.conf import settings
from registrar.forms.domain import DomainSuborganizationForm
from registrar.models import (
Domain,
DomainRequest,
@ -222,6 +222,44 @@ class DomainOrgNameAddressView(DomainFormBaseView):
return super().form_valid(form)
class DomainSubOrganizationView(DomainFormBaseView):
"""Suborganization view"""
model = Domain
template_name = "domain_suborganization.html"
context_object_name = "domain"
form_class = DomainSuborganizationForm
def get_form_kwargs(self, *args, **kwargs):
"""Add domain_info.organization_name instance to make a bound form."""
form_kwargs = super().get_form_kwargs(*args, **kwargs)
form_kwargs["instance"] = self.object.domain_info
form_kwargs["request"] = self.request
return form_kwargs
def get_success_url(self):
"""Redirect to the overview page for the domain."""
return reverse("domain-suborganization", kwargs={"pk": self.object.pk})
def form_valid(self, form):
"""The form is valid, save the organization name and mailing address."""
form.save()
messages.success(self.request, "The suborganization name for this domain has been updated.")
# superclass has the redirect
return super().form_valid(form)
def get_context_data(self, **kwargs):
"""Adds custom context."""
context = super().get_context_data(**kwargs)
# TODO: Switch to True #2352
suborganization_is_editable = False
context["suborganization_is_editable"] = suborganization_is_editable
return context
class DomainSeniorOfficialView(DomainFormBaseView):
"""Domain senior official editing view."""