mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-25 18:43:49 +02:00
working code
This commit is contained in:
parent
ff7a745ffa
commit
1445bba954
4 changed files with 83 additions and 67 deletions
|
@ -1301,6 +1301,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An IIFE that displays confirmation modal on the user profile page
|
||||||
|
*/
|
||||||
|
(function userProfileListener() {
|
||||||
|
|
||||||
|
const showConfirmationModalTrigger = document.querySelector('.show-confirmation-modal');
|
||||||
|
if (showConfirmationModalTrigger) {
|
||||||
|
showConfirmationModalTrigger.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An IIFE that hooks up the edit buttons on the finish-user-setup page
|
* An IIFE that hooks up the edit buttons on the finish-user-setup page
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -44,10 +44,12 @@ class CheckUserProfileMiddleware:
|
||||||
self.regular_excluded_pages = [
|
self.regular_excluded_pages = [
|
||||||
self.setup_page,
|
self.setup_page,
|
||||||
self.logout_page,
|
self.logout_page,
|
||||||
|
'/admin',
|
||||||
]
|
]
|
||||||
self.other_excluded_pages = [
|
self.other_excluded_pages = [
|
||||||
self.profile_page,
|
self.profile_page,
|
||||||
self.logout_page,
|
self.logout_page,
|
||||||
|
'/admin',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
|
@ -92,7 +94,7 @@ class CheckUserProfileMiddleware:
|
||||||
custom_redirect = "domain-request:" if request.path == "/request/" else None
|
custom_redirect = "domain-request:" if request.path == "/request/" else None
|
||||||
|
|
||||||
# Don't redirect on excluded pages (such as the setup page itself)
|
# Don't redirect on excluded pages (such as the setup page itself)
|
||||||
if not any(request.path.startswith(page) for page in self.excluded_pages):
|
if not any(request.path.startswith(page) for page in self.regular_excluded_pages):
|
||||||
|
|
||||||
# Preserve the original query parameters, and coerce them into a dict
|
# Preserve the original query parameters, and coerce them into a dict
|
||||||
query_params = parse_qs(request.META["QUERY_STRING"])
|
query_params = parse_qs(request.META["QUERY_STRING"])
|
||||||
|
@ -114,7 +116,7 @@ class CheckUserProfileMiddleware:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Don't redirect on excluded pages (such as the setup page itself)
|
# Don't redirect on excluded pages (such as the setup page itself)
|
||||||
if not any(request.path.startswith(page) for page in self.excluded_pages):
|
if not any(request.path.startswith(page) for page in self.other_excluded_pages):
|
||||||
return HttpResponseRedirect(self.profile_page)
|
return HttpResponseRedirect(self.profile_page)
|
||||||
else:
|
else:
|
||||||
# Process the view as normal
|
# Process the view as normal
|
||||||
|
|
|
@ -5,6 +5,11 @@ Edit your User Profile |
|
||||||
{% endblock title %}
|
{% endblock title %}
|
||||||
{% load static url_helpers %}
|
{% load static url_helpers %}
|
||||||
|
|
||||||
|
{# Disable the redirect #}
|
||||||
|
{% block logo %}
|
||||||
|
{% include "includes/gov_extended_logo.html" with logo_clickable=user_finished_setup %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<main id="main-content" class="grid-container">
|
<main id="main-content" class="grid-container">
|
||||||
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
||||||
|
@ -37,67 +42,49 @@ Edit your User Profile |
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if show_confirmation_modal %}
|
{% if show_confirmation_modal %}
|
||||||
<div class="usa-modal__content">
|
<a
|
||||||
<div class="usa-modal__main">
|
href="#toggle-confirmation-modal"
|
||||||
<h2 class="usa-modal__heading" id="modal-1-heading">
|
class="usa-button display-none show-confirmation-modal"
|
||||||
{{ modal_heading }}
|
aria-controls="toggle-confirmation-modal"
|
||||||
{% if heading_value is not None %}
|
data-open-modal
|
||||||
{# Add a breakpoint #}
|
>Open confirmation modal</a>
|
||||||
<div aria-hidden="true"></div>
|
<div
|
||||||
{{ heading_value }}
|
class="usa-modal is-visible"
|
||||||
{% endif %}
|
id="toggle-confirmation-modal"
|
||||||
</h2>
|
aria-labelledby="Add contact information"
|
||||||
<div class="usa-prose">
|
aria-describedby="Add contact information"
|
||||||
<p id="modal-1-description">
|
>
|
||||||
{{ modal_description }}
|
<div class="usa-modal__content">
|
||||||
</p>
|
<div class="usa-modal__main">
|
||||||
</div>
|
<h2 class="usa-modal__heading" id="modal-1-heading">
|
||||||
|
Add contact information
|
||||||
<div class="usa-modal__footer">
|
</h2>
|
||||||
<ul class="usa-button-group">
|
<div class="usa-prose">
|
||||||
{% if not_form %}
|
<p id="modal-1-description">
|
||||||
<li class="usa-button-group__item">
|
.Gov domain registrants must maintain accurate contact information in the .gov registrar.
|
||||||
{{ modal_button }}
|
Before you can manage your domain, we need you to add your contact information.
|
||||||
</li>
|
</p>
|
||||||
{% else %}
|
</div>
|
||||||
<li class="usa-button-group__item">
|
<div class="usa-modal__footer">
|
||||||
<form method="post">
|
<ul class="usa-button-group">
|
||||||
{% csrf_token %}
|
<li class="usa-button-group__item">
|
||||||
{{ modal_button }}
|
<button
|
||||||
</form>
|
type="button"
|
||||||
</li>
|
class="usa-button padding-105 text-center"
|
||||||
{% endif %}
|
data-close-modal
|
||||||
<li class="usa-button-group__item">
|
>
|
||||||
{% comment %} The cancel button the DS form actually triggers a context change in the view,
|
Add contact information
|
||||||
in addition to being a close modal hook {% endcomment %}
|
</button>
|
||||||
{% if cancel_button_resets_ds_form %}
|
</li>
|
||||||
<form method="post">
|
</ul>
|
||||||
{% csrf_token %}
|
</div>
|
||||||
<button
|
</div>
|
||||||
type="submit"
|
</div>
|
||||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
</div>
|
||||||
name="btn-cancel-click"
|
|
||||||
data-close-modal
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
{% elif not is_domain_request_form or review_form_is_complete %}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
|
||||||
data-close-modal
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block content_bottom %}
|
{% block content_bottom %}
|
||||||
|
@ -105,3 +92,7 @@ Edit your User Profile |
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{% endblock content_bottom %}
|
{% endblock content_bottom %}
|
||||||
|
|
||||||
|
{% block footer %}
|
||||||
|
{% include "includes/footer.html" with show_manage_your_domains=user_finished_setup %}
|
||||||
|
{% endblock footer %}
|
||||||
|
|
|
@ -41,8 +41,8 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
form = self.form_class(instance=self.object)
|
form = self.form_class(instance=self.object)
|
||||||
context = self.get_context_data(object=self.object, form=form)
|
context = self.get_context_data(object=self.object, form=form)
|
||||||
|
|
||||||
if hasattr(self.object, "finished_setup") and not self.object.finished_setup:
|
if hasattr(self.user, "finished_setup") and not self.user.finished_setup:
|
||||||
context["show_confirmation_modal"]
|
context["show_confirmation_modal"] = True
|
||||||
|
|
||||||
return_to_request = request.GET.get("return_to_request")
|
return_to_request = request.GET.get("return_to_request")
|
||||||
if return_to_request:
|
if return_to_request:
|
||||||
|
@ -70,10 +70,15 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
|
|
||||||
# The text for the back button on this page
|
# The text for the back button on this page
|
||||||
context["profile_back_button_text"] = "Go to manage your domains"
|
context["profile_back_button_text"] = "Go to manage your domains"
|
||||||
context["show_back_button"] = True
|
context["show_back_button"] = False
|
||||||
|
|
||||||
|
if hasattr(self.user, "finished_setup") and self.user.finished_setup:
|
||||||
|
context["user_finished_setup"] = True
|
||||||
|
context["show_back_button"] = True
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
"""Redirect to the user's profile page."""
|
"""Redirect to the user's profile page."""
|
||||||
|
|
||||||
|
@ -96,6 +101,12 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
return self.form_valid(form)
|
return self.form_valid(form)
|
||||||
else:
|
else:
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
def form_invalid(self, form):
|
||||||
|
"""If the form is invalid, conditionally display an additional error."""
|
||||||
|
if hasattr(self.user, "finished_setup") and not self.user.finished_setup:
|
||||||
|
messages.error(self.request, "Before you can manage your domain, we need you to add contact information.")
|
||||||
|
return super().form_invalid(form)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""Handle successful and valid form submissions."""
|
"""Handle successful and valid form submissions."""
|
||||||
|
@ -108,9 +119,9 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
"""Override get_object to return the logged-in user's contact"""
|
"""Override get_object to return the logged-in user's contact"""
|
||||||
user = self.request.user # get the logged in user
|
self.user = self.request.user # get the logged in user
|
||||||
if hasattr(user, "contact"): # Check if the user has a contact instance
|
if hasattr(self.user, "contact"): # Check if the user has a contact instance
|
||||||
return user.contact
|
return self.user.contact
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue