mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-18 07:24:10 +02:00
Code cleanup
This commit is contained in:
parent
60c4f54e63
commit
b59a624391
3 changed files with 18 additions and 16 deletions
|
@ -1996,26 +1996,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
var isTyping = false;
|
var isTyping = false;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', (event) => {
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
// The file location for the #undo svg
|
handleAllComboBoxElements();
|
||||||
const undoIcon = document.querySelector("#uswds-undo-icon-url");
|
|
||||||
const undoIconUrl = undoIcon ? undoIcon.getAttribute("data-undo-icon-url") : null;
|
|
||||||
if (undoIconUrl) {
|
|
||||||
handleAllComboBoxElements(undoIconUrl);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleAllComboBoxElements(undoIconUrl) {
|
function handleAllComboBoxElements() {
|
||||||
const comboBoxElements = document.querySelectorAll(".usa-combo-box");
|
const comboBoxElements = document.querySelectorAll(".usa-combo-box");
|
||||||
comboBoxElements.forEach(comboBox => {
|
comboBoxElements.forEach(comboBox => {
|
||||||
const input = comboBox.querySelector('input');
|
const input = comboBox.querySelector("input");
|
||||||
const select = comboBox.querySelector("select");
|
const select = comboBox.querySelector("select");
|
||||||
if (!input || !undoIconUrl || !select) {
|
if (!input || !select) {
|
||||||
console.warn("No combobox element found");
|
console.warn("No combobox element found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Set the initial value of the combobox
|
// Set the initial value of the combobox
|
||||||
let initialValue = select.getAttribute("data-default-value");
|
let initialValue = select.getAttribute("data-default-value");
|
||||||
|
|
||||||
let clearInputButton = comboBox.querySelector(".usa-combo-box__clear-input");
|
let clearInputButton = comboBox.querySelector(".usa-combo-box__clear-input");
|
||||||
if (!clearInputButton) {
|
if (!clearInputButton) {
|
||||||
console.warn("No clear element found");
|
console.warn("No clear element found");
|
||||||
|
@ -2041,13 +2035,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
const config = { childList: true, subtree: true };
|
const config = { childList: true, subtree: true };
|
||||||
observer.observe(dropdownList, config);
|
observer.observe(dropdownList, config);
|
||||||
|
|
||||||
// Add input event listener to detect typing
|
// Input event listener to detect typing
|
||||||
input.addEventListener('input', () => {
|
input.addEventListener("input", () => {
|
||||||
isTyping = true;
|
isTyping = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add blur event listener to reset typing state
|
// Blur event listener to reset typing state
|
||||||
input.addEventListener('blur', () => {
|
input.addEventListener("blur", () => {
|
||||||
isTyping = false;
|
isTyping = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{% if has_domains_portfolio_permission and request.user.has_edit_suborganization %}
|
{% 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">
|
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% input_with_errors form.sub_organization %}
|
{% input_with_errors form.sub_organization %}
|
||||||
|
|
|
@ -250,6 +250,16 @@ class DomainSubOrganizationView(DomainFormBaseView):
|
||||||
context_object_name = "domain"
|
context_object_name = "domain"
|
||||||
form_class = DomainSuborganizationForm
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
"""Adds custom context."""
|
"""Adds custom context."""
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue