Code cleanup

This commit is contained in:
zandercymatics 2024-08-12 10:42:52 -06:00
parent 60c4f54e63
commit b59a624391
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 18 additions and 16 deletions

View file

@ -1996,26 +1996,20 @@ document.addEventListener('DOMContentLoaded', function() {
var isTyping = false;
document.addEventListener('DOMContentLoaded', (event) => {
// The file location for the #undo svg
const undoIcon = document.querySelector("#uswds-undo-icon-url");
const undoIconUrl = undoIcon ? undoIcon.getAttribute("data-undo-icon-url") : null;
if (undoIconUrl) {
handleAllComboBoxElements(undoIconUrl);
}
handleAllComboBoxElements();
});
function handleAllComboBoxElements(undoIconUrl) {
function handleAllComboBoxElements() {
const comboBoxElements = document.querySelectorAll(".usa-combo-box");
comboBoxElements.forEach(comboBox => {
const input = comboBox.querySelector('input');
const input = comboBox.querySelector("input");
const select = comboBox.querySelector("select");
if (!input || !undoIconUrl || !select) {
if (!input || !select) {
console.warn("No combobox element found");
return;
}
// Set the initial value of the combobox
let initialValue = select.getAttribute("data-default-value");
let clearInputButton = comboBox.querySelector(".usa-combo-box__clear-input");
if (!clearInputButton) {
console.warn("No clear element found");
@ -2041,13 +2035,13 @@ document.addEventListener('DOMContentLoaded', function() {
const config = { childList: true, subtree: true };
observer.observe(dropdownList, config);
// Add input event listener to detect typing
input.addEventListener('input', () => {
// Input event listener to detect typing
input.addEventListener("input", () => {
isTyping = true;
});
// Add blur event listener to reset typing state
input.addEventListener('blur', () => {
// Blur event listener to reset typing state
input.addEventListener("blur", () => {
isTyping = false;
});

View file

@ -16,8 +16,6 @@
</p>
{% if has_domains_portfolio_permission and request.user.has_edit_suborganization %}
{% comment %} Store the undo icon for reference in js - since this is dynamic {% endcomment %}
<div id="uswds-undo-icon-url" class="display-none" data-undo-icon-url="{% static 'img/usa-icons/undo.svg' %}"></div>
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
{% input_with_errors form.sub_organization %}

View file

@ -250,6 +250,16 @@ class DomainSubOrganizationView(DomainFormBaseView):
context_object_name = "domain"
form_class = DomainSuborganizationForm
def has_permission(self):
"""Override for the has_permission class to exclude non-portfolio users"""
# non-org users shouldn't have access to this page
is_org_user = self.request.user.is_org_user(self.request)
if self.request.user.portfolio and is_org_user:
return super().has_permission()
else:
return False
def get_context_data(self, **kwargs):
"""Adds custom context."""
context = super().get_context_data(**kwargs)