diff --git a/src/registrar/assets/src/js/getgov/domain-dnssec.js b/src/registrar/assets/src/js/getgov/domain-dnssec.js new file mode 100644 index 000000000..860359fe0 --- /dev/null +++ b/src/registrar/assets/src/js/getgov/domain-dnssec.js @@ -0,0 +1,15 @@ +import { submitForm } from './helpers.js'; + +export function initDomainDNSSEC() { + document.addEventListener('DOMContentLoaded', function() { + let domain_dnssec_page = document.getElementById("domain-dnssec"); + if (domain_dnssec_page) { + const button = document.getElementById("disable-dnssec-button"); + if (button) { + button.addEventListener("click", function () { + submitForm("disable-dnssec-form"); + }); + } + } + }); +} \ No newline at end of file diff --git a/src/registrar/assets/src/js/getgov/domain-dsdata.js b/src/registrar/assets/src/js/getgov/domain-dsdata.js new file mode 100644 index 000000000..7c0871bec --- /dev/null +++ b/src/registrar/assets/src/js/getgov/domain-dsdata.js @@ -0,0 +1,27 @@ +import { submitForm } from './helpers.js'; + +export function initDomainDSData() { + document.addEventListener('DOMContentLoaded', function() { + let domain_dsdata_page = document.getElementById("domain-dsdata"); + if (domain_dsdata_page) { + const override_button = document.getElementById("disable-override-click-button"); + const cancel_button = document.getElementById("btn-cancel-click-button"); + const cancel_close_button = document.getElementById("btn-cancel-click-close-button"); + if (override_button) { + override_button.addEventListener("click", function () { + submitForm("disable-override-click-form"); + }); + } + if (cancel_button) { + cancel_button.addEventListener("click", function () { + submitForm("btn-cancel-click-form"); + }); + } + if (cancel_close_button) { + cancel_close_button.addEventListener("click", function () { + submitForm("btn-cancel-click-form"); + }); + } + } + }); +} \ No newline at end of file diff --git a/src/registrar/assets/src/js/getgov/domain-managers.js b/src/registrar/assets/src/js/getgov/domain-managers.js new file mode 100644 index 000000000..26eccd8cd --- /dev/null +++ b/src/registrar/assets/src/js/getgov/domain-managers.js @@ -0,0 +1,20 @@ +import { submitForm } from './helpers.js'; + +export function initDomainManagersPage() { + document.addEventListener('DOMContentLoaded', function() { + let domain_managers_page = document.getElementById("domain-managers"); + if (domain_managers_page) { + // Add event listeners for all buttons matching user-delete-button-{NUMBER} + const deleteButtons = document.querySelectorAll('[id^="user-delete-button-"]'); // Select buttons with ID starting with "user-delete-button-" + deleteButtons.forEach((button) => { + const buttonId = button.id; // e.g., "user-delete-button-1" + const number = buttonId.split('-').pop(); // Extract the NUMBER part + const formId = `user-delete-form-${number}`; // Generate the corresponding form ID + + button.addEventListener("click", function () { + submitForm(formId); // Pass the form ID to submitForm + }); + }); + } + }); +} \ No newline at end of file diff --git a/src/registrar/assets/src/js/getgov/domain-request-form.js b/src/registrar/assets/src/js/getgov/domain-request-form.js new file mode 100644 index 000000000..d9b660a50 --- /dev/null +++ b/src/registrar/assets/src/js/getgov/domain-request-form.js @@ -0,0 +1,12 @@ +import { submitForm } from './helpers.js'; + +export function initDomainRequestForm() { + document.addEventListener('DOMContentLoaded', function() { + const button = document.getElementById("domain-request-form-submit-button"); + if (button) { + button.addEventListener("click", function () { + submitForm("submit-domain-request-form"); + }); + } + }); +} \ No newline at end of file diff --git a/src/registrar/assets/src/js/getgov/form-errors.js b/src/registrar/assets/src/js/getgov/form-errors.js new file mode 100644 index 000000000..ec1faaccf --- /dev/null +++ b/src/registrar/assets/src/js/getgov/form-errors.js @@ -0,0 +1,19 @@ +export function initFormErrorHandling() { + document.addEventListener('DOMContentLoaded', function() { + const errorSummary = document.getElementById('form-errors'); + const firstErrorField = document.querySelector('.usa-input--error'); + if (firstErrorField) { + // Scroll to the first field in error + firstErrorField.scrollIntoView({ behavior: 'smooth', block: 'center' }); + + // Add focus to the first field in error + setTimeout(() => { + firstErrorField.focus(); + }, 50); + } else if (errorSummary) { + // Scroll to the error summary + errorSummary.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } + + }); +} \ No newline at end of file diff --git a/src/registrar/assets/src/js/getgov/helpers.js b/src/registrar/assets/src/js/getgov/helpers.js index 1afd84520..93c25ee45 100644 --- a/src/registrar/assets/src/js/getgov/helpers.js +++ b/src/registrar/assets/src/js/getgov/helpers.js @@ -75,3 +75,16 @@ export function debounce(handler, cooldown=600) { export function getCsrfToken() { return document.querySelector('input[name="csrfmiddlewaretoken"]').value; } + +/** + * Helper function to submit a form + * @param {} form_id - the id of the form to be submitted + */ +export function submitForm(form_id) { + let form = document.getElementById(form_id); + if (form) { + form.submit(); + } else { + console.error("Form '" + form_id + "' not found."); + } +} diff --git a/src/registrar/assets/src/js/getgov/main.js b/src/registrar/assets/src/js/getgov/main.js index f5ebc83a3..6ff402aa4 100644 --- a/src/registrar/assets/src/js/getgov/main.js +++ b/src/registrar/assets/src/js/getgov/main.js @@ -11,6 +11,11 @@ import { initMembersTable } from './table-members.js'; import { initMemberDomainsTable } from './table-member-domains.js'; import { initEditMemberDomainsTable } from './table-edit-member-domains.js'; import { initPortfolioNewMemberPageToggle, initAddNewMemberPageListeners, initPortfolioMemberPageRadio } from './portfolio-member-page.js'; +import { initDomainRequestForm } from './domain-request-form.js'; +import { initDomainManagersPage } from './domain-managers.js'; +import { initDomainDSData } from './domain-dsdata.js'; +import { initDomainDNSSEC } from './domain-dnssec.js'; +import { initFormErrorHandling } from './form-errors.js'; initDomainValidators(); @@ -36,6 +41,13 @@ initMembersTable(); initMemberDomainsTable(); initEditMemberDomainsTable(); +initDomainRequestForm(); +initDomainManagersPage(); +initDomainDSData(); +initDomainDNSSEC(); + +initFormErrorHandling(); + // Init the portfolio new member page initPortfolioMemberPageRadio(); initPortfolioNewMemberPageToggle(); diff --git a/src/registrar/assets/src/js/getgov/table-base.js b/src/registrar/assets/src/js/getgov/table-base.js index e526c6b5f..97c256734 100644 --- a/src/registrar/assets/src/js/getgov/table-base.js +++ b/src/registrar/assets/src/js/getgov/table-base.js @@ -495,7 +495,8 @@ export class BaseTable { // Add event listeners to table headers for sorting initializeTableHeaders() { this.tableHeaders.forEach(header => { - header.addEventListener('click', () => { + header.addEventListener('click', event => { + let button = header.querySelector('.usa-table__header__button') const sortBy = header.getAttribute('data-sortable'); let order = 'asc'; // sort order will be ascending, unless the currently sorted column is ascending, and the user @@ -505,6 +506,13 @@ export class BaseTable { } // load the results with the updated sort this.loadTable(1, sortBy, order); + // If the click occurs outside of the button, need to simulate a button click in order + // for USWDS listener on the button to execute. + // Check first to see if click occurs outside of the button + if (!button.contains(event.target)) { + // Simulate a button click + button.click(); + } }); }); } diff --git a/src/registrar/assets/src/sass/_theme/_tables.scss b/src/registrar/assets/src/sass/_theme/_tables.scss index 45f0b5245..ea160396e 100644 --- a/src/registrar/assets/src/sass/_theme/_tables.scss +++ b/src/registrar/assets/src/sass/_theme/_tables.scss @@ -88,8 +88,14 @@ th { } @include at-media(tablet-lg) { - th[data-sortable]:not([aria-sort]) .usa-table__header__button { + th[data-sortable] .usa-table__header__button { right: auto; + + &[aria-sort=ascending], + &[aria-sort=descending], + &:not([aria-sort]) { + right: auto; + } } } } diff --git a/src/registrar/templates/domain_add_user.html b/src/registrar/templates/domain_add_user.html index 1429127e6..b09f1f814 100644 --- a/src/registrar/templates/domain_add_user.html +++ b/src/registrar/templates/domain_add_user.html @@ -37,6 +37,9 @@ {% endif %} {% endblock breadcrumb %} + + {% include "includes/form_errors.html" with form=form %} +

Add a domain manager

{% if has_organization_feature_flag %}

diff --git a/src/registrar/templates/domain_dnssec.html b/src/registrar/templates/domain_dnssec.html index cfec053c2..a795fb2fc 100644 --- a/src/registrar/templates/domain_dnssec.html +++ b/src/registrar/templates/domain_dnssec.html @@ -27,7 +27,7 @@ {% endif %} {% endblock breadcrumb %} -

DNSSEC

+

DNSSEC

DNSSEC, or DNS Security Extensions, is an additional security layer to protect your website. Enabling DNSSEC ensures that when someone visits your domain, they can be certain that it’s connecting to the correct server, preventing potential hijacking or tampering with your domain's records.

@@ -78,7 +78,11 @@

DNSSEC is enabled on your domain

aria-labelledby="Are you sure you want to continue?" aria-describedby="Your DNSSEC records will be deleted from the registry." > - {% include 'includes/modal.html' with modal_heading="Are you sure you want to disable DNSSEC?" modal_button=modal_button|safe %} + {% include 'includes/modal.html' with modal_heading="Are you sure you want to disable DNSSEC?" modal_button_id="disable-dnssec-button" modal_button_text="Confirm" modal_button_class="usa-button--secondary" %} +
+ {% csrf_token %} + +
{% endblock %} {# domain_content #} diff --git a/src/registrar/templates/domain_dsdata.html b/src/registrar/templates/domain_dsdata.html index 0f60235e1..5ebb264c4 100644 --- a/src/registrar/templates/domain_dsdata.html +++ b/src/registrar/templates/domain_dsdata.html @@ -42,7 +42,7 @@ {% include "includes/form_errors.html" with form=form %} {% endfor %} -

DS data

+

DS data

In order to enable DNSSEC, you must first configure it with your DNS hosting service.

@@ -141,7 +141,15 @@

DS data record {{forloop.counter}}

aria-describedby="Your DNSSEC records will be deleted from the registry." data-force-action > - {% include 'includes/modal.html' with cancel_button_resets_ds_form=True modal_heading="Warning: You are about to remove all DS records on your domain." modal_description="To fully disable DNSSEC: In addition to removing your DS records here, you’ll need to delete the DS records at your DNS host. To avoid causing your domain to appear offline, you should wait to delete your DS records at your DNS host until the Time to Live (TTL) expires. This is often less than 24 hours, but confirm with your provider." modal_button=modal_button|safe %} + {% include 'includes/modal.html' with cancel_button_resets_ds_form=True modal_heading="Warning: You are about to remove all DS records on your domain." modal_description="To fully disable DNSSEC: In addition to removing your DS records here, you’ll need to delete the DS records at your DNS host. To avoid causing your domain to appear offline, you should wait to delete your DS records at your DNS host until the Time to Live (TTL) expires. This is often less than 24 hours, but confirm with your provider." modal_button_id="disable-override-click-button" modal_button_text="Remove all DS data" modal_button_class="usa-button--secondary" %} +
+ {% csrf_token %} + +
+
+ {% csrf_token %} + +
{% endblock %} {# domain_content #} diff --git a/src/registrar/templates/domain_request_form.html b/src/registrar/templates/domain_request_form.html index a076220cb..2c2716a3c 100644 --- a/src/registrar/templates/domain_request_form.html +++ b/src/registrar/templates/domain_request_form.html @@ -130,9 +130,17 @@

{{form_titles|get_item:steps.current}}

aria-describedby="Are you sure you want to submit a domain request?" data-force-action > - {% include 'includes/modal.html' with is_domain_request_form=True review_form_is_complete=review_form_is_complete modal_heading=modal_heading|safe modal_description=modal_description|safe modal_button=modal_button|safe %} + {% if review_form_is_complete %} + {% include 'includes/modal.html' with modal_heading="You are about to submit a domain request for " domain_name_modal=requested_domain__name modal_description="Once you submit this request, you won’t be able to edit it until we review it. You’ll only be able to withdraw your request." modal_button_id="domain-request-form-submit-button" modal_button_text="Submit request" %} + {% else %} + {% include 'includes/modal.html' with modal_heading="Your request form is incomplete" modal_description='This request cannot be submitted yet. Return to the request and visit the steps that are marked as "incomplete."' modal_button_text="Return to request" cancel_button_only=True %} + {% endif %} +
+ {% csrf_token %} +
+ {% block after_form_content %}{% endblock %} diff --git a/src/registrar/templates/domain_users.html b/src/registrar/templates/domain_users.html index af292d9d5..f42e738e1 100644 --- a/src/registrar/templates/domain_users.html +++ b/src/registrar/templates/domain_users.html @@ -49,7 +49,7 @@

Domain managers

{% if domain_manager_roles %} -
+

Domain managers

@@ -89,12 +89,13 @@

Domain managers

aria-describedby="You will be removed from this domain" data-force-action > - - {% with domain_name=domain.name|force_escape %} - {% include 'includes/modal.html' with modal_heading="Are you sure you want to remove yourself as a domain manager?" modal_description="You will no longer be able to manage the domain "|add:domain_name|add:"."|safe modal_button=modal_button_self|safe %} - {% endwith %} - + {% with domain_name=domain.name|force_escape counter_str=forloop.counter|stringformat:"s" %} + {% include 'includes/modal.html' with modal_heading="Are you sure you want to remove yourself as a domain manager?" modal_description="You will no longer be able to manage the domain "|add:domain_name|add:"."|safe modal_button_id="user-delete-button-"|add:counter_str|safe modal_button_text="Yes, remove myself" modal_button_class="usa-button--secondary" %} + {% endwith %} + + {% csrf_token %} + {% else %}
Domain managers aria-describedby="{{ item.permission.user.email }} will be removed" data-force-action > -
- {% with email=item.permission.user.email|default:item.permission.user|force_escape domain_name=domain.name|force_escape %} - {% include 'includes/modal.html' with modal_heading="Are you sure you want to remove " heading_value=email|add:"?" modal_description=""|add:email|add:" will no longer be able to manage the domain "|add:domain_name|add:"."|safe modal_button=modal_button|safe %} - {% endwith %} - + {% with email=item.permission.user.email|default:item.permission.user|force_escape domain_name=domain.name|force_escape counter_str=forloop.counter|stringformat:"s" %} + {% include 'includes/modal.html' with modal_heading="Are you sure you want to remove " heading_value=email|add:"?" modal_description=""|add:email|add:" will no longer be able to manage the domain "|add:domain_name|add:"."|safe modal_button_id="user-delete-button-"|add:counter_str|safe modal_button_text="Yes, remove domain manager" modal_button_class="usa-button--secondary" %} + {% endwith %}
+ + {% csrf_token %} + {% endif %} {% else %} {% for error in form.non_field_errors %} -
+
{% endfor %} -{% endfor %} + {% endfor %} + {% endif %} diff --git a/src/registrar/templates/includes/modal.html b/src/registrar/templates/includes/modal.html index 625044585..643878eb0 100644 --- a/src/registrar/templates/includes/modal.html +++ b/src/registrar/templates/includes/modal.html @@ -1,4 +1,5 @@ {% load static form_helpers url_helpers %} +{% load custom_filters %}
@@ -24,39 +25,51 @@

{% elif not form.full_name.value and not form.title.value and not form.email.value %}

- Your senior official is a person within your organization who can authorize domain requests. We don't have information about your organization's senior official. To suggest an update, email help@get.gov.

{% else %} diff --git a/src/registrar/templates/portfolio_organization.html b/src/registrar/templates/portfolio_organization.html index 712d1a6ca..ce32555a5 100644 --- a/src/registrar/templates/portfolio_organization.html +++ b/src/registrar/templates/portfolio_organization.html @@ -23,6 +23,8 @@ {% include "includes/form_messages.html" %} {% endblock %} + {% include "includes/form_errors.html" with form=form %} +

Organization

The name of your organization will be publicly listed as the domain registrant.

@@ -33,7 +35,6 @@

Organization

To suggest an update, email help@get.gov.

- {% include "includes/form_errors.html" with form=form %} {% include "includes/required_fields.html" %}
{% csrf_token %} diff --git a/src/registrar/templatetags/custom_filters.py b/src/registrar/templatetags/custom_filters.py index 6140130c8..b750af599 100644 --- a/src/registrar/templatetags/custom_filters.py +++ b/src/registrar/templatetags/custom_filters.py @@ -290,3 +290,9 @@ def get_dict_value(dictionary, key): if isinstance(dictionary, dict): return dictionary.get(key, "") return "" + + +@register.filter +def button_class(custom_class): + default_class = "usa-button" + return f"{default_class} {custom_class}" if custom_class else default_class diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index cb3da1f83..45f1e6ad2 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -805,15 +805,6 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) has_dnssec_records = self.object.dnssecdata is not None - - # Create HTML for the modal button - modal_button = ( - '' - ) - - context["modal_button"] = modal_button context["has_dnssec_records"] = has_dnssec_records context["dnssec_enabled"] = self.request.session.pop("dnssec_enabled", False) @@ -906,15 +897,6 @@ def post(self, request, *args, **kwargs): # to preserve the context["form"] context = super().get_context_data(form=formset) context["trigger_modal"] = True - # Create HTML for the modal button - modal_button = ( - '' - ) - - # context to back out of a broken form on all fields delete - context["modal_button"] = modal_button return self.render_to_response(context) if formset.is_valid() or override: @@ -1050,9 +1032,6 @@ def get_context_data(self, **kwargs): # Add conditionals to the context (such as "can_delete_users") context = self._add_booleans_to_context(context) - # Add modal buttons to the context (such as for delete) - context = self._add_modal_buttons_to_context(context) - # Get portfolio from session (if set) portfolio = self.request.session.get("portfolio") @@ -1149,26 +1128,6 @@ def _add_booleans_to_context(self, context): context["can_delete_users"] = can_delete_users return context - def _add_modal_buttons_to_context(self, context): - """Adds modal buttons (and their HTML) to the context""" - # Create HTML for the modal button - modal_button = ( - '' - ) - context["modal_button"] = modal_button - - # Create HTML for the modal button when deleting yourself - modal_button_self = ( - '' - ) - context["modal_button_self"] = modal_button_self - - return context - class DomainAddUserView(DomainFormBaseView): """Inside of a domain's user management, a form for adding users. diff --git a/src/registrar/views/domain_request.py b/src/registrar/views/domain_request.py index 85f7576d0..9754b0d0c 100644 --- a/src/registrar/views/domain_request.py +++ b/src/registrar/views/domain_request.py @@ -448,34 +448,21 @@ def get_context_data(self): non_org_steps_complete = DomainRequest._form_complete(self.domain_request, self.request) org_steps_complete = len(self.db_check_for_unlocking_steps()) == len(self.steps) if (not self.is_portfolio and non_org_steps_complete) or (self.is_portfolio and org_steps_complete): - modal_button = '" context = { - "not_form": False, "form_titles": self.titles, "steps": self.steps, "visited": self.storage.get("step_history", []), "is_federal": self.domain_request.is_federal(), - "modal_button": modal_button, - "modal_heading": "You are about to submit a domain request for ", - "domain_name_modal": str(self.domain_request.requested_domain), - "modal_description": "Once you submit this request, you won’t be able to edit it until we review it.\ - You’ll only be able to withdraw your request.", "review_form_is_complete": True, "user": self.request.user, "requested_domain__name": requested_domain_name, } else: # form is not complete - modal_button = '' context = { - "not_form": True, "form_titles": self.titles, "steps": self.steps, "visited": self.storage.get("step_history", []), "is_federal": self.domain_request.is_federal(), - "modal_button": modal_button, - "modal_heading": "Your request form is incomplete", - "modal_description": 'This request cannot be submitted yet.\ - Return to the request and visit the steps that are marked as "incomplete."', "review_form_is_complete": False, "user": self.request.user, "requested_domain__name": requested_domain_name, diff --git a/src/registrar/views/domain_requests_json.py b/src/registrar/views/domain_requests_json.py index d0e673adf..6dffc534e 100644 --- a/src/registrar/views/domain_requests_json.py +++ b/src/registrar/views/domain_requests_json.py @@ -109,6 +109,10 @@ def apply_sorting(queryset, request): sort_by = request.GET.get("sort_by", "id") # Default to 'id' order = request.GET.get("order", "asc") # Default to 'asc' + # Handle special case for 'creator' + if sort_by == "creator": + sort_by = "creator__email" + if order == "desc": sort_by = f"-{sort_by}" return queryset.order_by(sort_by)
Domain managers