mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-16 22:44:11 +02:00
add view
This commit is contained in:
parent
82c9861dd5
commit
5183198d56
10 changed files with 151 additions and 9 deletions
|
@ -1978,3 +1978,36 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
showInputOnErrorFields();
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})();
|
|
@ -193,6 +193,11 @@ urlpatterns = [
|
||||||
views.DomainOrgNameAddressView.as_view(),
|
views.DomainOrgNameAddressView.as_view(),
|
||||||
name="domain-org-name-address",
|
name="domain-org-name-address",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"domain/<int:pk>/suborganization",
|
||||||
|
views.DomainSubOrganizationView.as_view(),
|
||||||
|
name="domain-suborganization",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"domain/<int:pk>/senior-official",
|
"domain/<int:pk>/senior-official",
|
||||||
views.DomainSeniorOfficialView.as_view(),
|
views.DomainSeniorOfficialView.as_view(),
|
||||||
|
|
|
@ -9,6 +9,7 @@ from .domain import (
|
||||||
DomainDnssecForm,
|
DomainDnssecForm,
|
||||||
DomainDsdataFormset,
|
DomainDsdataFormset,
|
||||||
DomainDsdataForm,
|
DomainDsdataForm,
|
||||||
|
DomainSuborganizationForm,
|
||||||
)
|
)
|
||||||
from .portfolio import (
|
from .portfolio import (
|
||||||
PortfolioOrgAddressForm,
|
PortfolioOrgAddressForm,
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator, RegexVa
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
from registrar.models import DomainRequest
|
from registrar.models import DomainRequest
|
||||||
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||||
|
from registrar.models.suborganization import Suborganization
|
||||||
from registrar.models.utility.domain_helper import DomainHelper
|
from registrar.models.utility.domain_helper import DomainHelper
|
||||||
from registrar.utility.errors import (
|
from registrar.utility.errors import (
|
||||||
NameserverError,
|
NameserverError,
|
||||||
|
@ -153,6 +154,45 @@ class DomainNameserverForm(forms.Form):
|
||||||
self.add_error("ip", str(e))
|
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):
|
class BaseNameserverFormset(forms.BaseFormSet):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="usa-combo-box">
|
||||||
|
{% include "django/forms/widgets/select.html" %}
|
||||||
|
</div>
|
|
@ -54,10 +54,8 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if is_org_user %}
|
{% if is_org_user %}
|
||||||
{% comment %} TODO - uncomment in #2352 and add to edit_link
|
|
||||||
{% url 'domain-suborganization' pk=domain.id as url %}
|
{% 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=url editable=domain.is_editable %}
|
||||||
{% include "includes/summary_item.html" with title='Suborganization' value=domain.domain_info.sub_organization edit_link="#" editable=domain.is_editable %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% url 'domain-org-name-address' pk=domain.id as url %}
|
{% 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 %}
|
{% 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 %}
|
||||||
|
|
|
@ -9,14 +9,9 @@
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
{% if is_org_user %}
|
{% if is_org_user %}
|
||||||
{% comment %} TODO - uncomment in #2352
|
|
||||||
{% with url_name="domain-suborganization" %}
|
{% with url_name="domain-suborganization" %}
|
||||||
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
|
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endcomment %}
|
|
||||||
{% with url="#" %}
|
|
||||||
{% include "includes/domain_sidenav_item.html" with item_text="Suborganization" %}
|
|
||||||
{% endwith %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% with url_name="domain-org-name-address" %}
|
{% with url_name="domain-org-name-address" %}
|
||||||
{% include "includes/domain_sidenav_item.html" with item_text="Organization name and mailing address" %}
|
{% include "includes/domain_sidenav_item.html" with item_text="Organization name and mailing address" %}
|
||||||
|
|
28
src/registrar/templates/domain_suborganization.html
Normal file
28
src/registrar/templates/domain_suborganization.html
Normal 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 %}
|
|
@ -3,6 +3,7 @@ from .domain import (
|
||||||
DomainView,
|
DomainView,
|
||||||
DomainSeniorOfficialView,
|
DomainSeniorOfficialView,
|
||||||
DomainOrgNameAddressView,
|
DomainOrgNameAddressView,
|
||||||
|
DomainSubOrganizationView,
|
||||||
DomainDNSView,
|
DomainDNSView,
|
||||||
DomainNameserversView,
|
DomainNameserversView,
|
||||||
DomainDNSSECView,
|
DomainDNSSECView,
|
||||||
|
|
|
@ -15,7 +15,7 @@ from django.shortcuts import redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views.generic.edit import FormMixin
|
from django.views.generic.edit import FormMixin
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from registrar.forms.domain import DomainSuborganizationForm
|
||||||
from registrar.models import (
|
from registrar.models import (
|
||||||
Domain,
|
Domain,
|
||||||
DomainRequest,
|
DomainRequest,
|
||||||
|
@ -222,6 +222,44 @@ class DomainOrgNameAddressView(DomainFormBaseView):
|
||||||
return super().form_valid(form)
|
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):
|
class DomainSeniorOfficialView(DomainFormBaseView):
|
||||||
"""Domain senior official editing view."""
|
"""Domain senior official editing view."""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue