ove organization dashboard JS to separate file

This commit is contained in:
Beverly Nguyen
2025-11-05 13:27:21 -08:00
parent 3beba2beaf
commit 49f5e48ffa
3 changed files with 75 additions and 60 deletions

View File

@@ -60,6 +60,7 @@ import { initCurrentYear } from './date.js';
import './sidenav.js';
import './validation.js';
import './scrollPosition.js';
import './organizationDashboard.js';
initCurrentYear();

View File

@@ -0,0 +1,68 @@
(function() {
'use strict';
function scrollToElement(element, delay) {
setTimeout(function() {
element.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest'
});
}, delay || 0);
}
function focusFirstInput(container, delay) {
setTimeout(function() {
var input = container.querySelector('input[type="text"], input[type="email"]');
if (input) input.focus();
}, delay || 0);
}
function highlightAndScrollToService(serviceId) {
var serviceRow = document.getElementById('service-' + serviceId);
if (serviceRow) {
scrollToElement(serviceRow, 300);
setTimeout(function() {
serviceRow.classList.remove('is-highlighted');
if (serviceRow.className === '') {
serviceRow.removeAttribute('class');
}
}, 3300);
}
}
function initForms() {
requestAnimationFrame(function() {
var form = document.getElementById('create-service-form') ||
document.getElementById('invite-user-form') ||
document.getElementById('edit-service-form');
if (form) {
scrollToElement(form, 50);
focusFirstInput(form, 150);
}
});
}
function initEditServiceConfirmation() {
var confirmEditButton = document.getElementById('edit-service-confirm-btn');
if (confirmEditButton) {
confirmEditButton.addEventListener('click', function() {
var editForm = document.getElementById('edit-service-form');
if (editForm) {
editForm.submit();
}
});
}
}
document.addEventListener('DOMContentLoaded', function() {
initForms();
initEditServiceConfirmation();
});
window.OrganizationDashboard = {
highlightAndScrollToService: highlightAndScrollToService
};
})();

View File

@@ -265,73 +265,19 @@
{% block extra_javascripts %}
<script nonce="{{ csp_nonce() }}">
(function() {
function scrollToElement(element, delay) {
setTimeout(function() {
element.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest'
});
}, delay || 0);
}
function focusFirstInput(container, delay) {
setTimeout(function() {
var input = container.querySelector('input[type="text"], input[type="email"]');
if (input) input.focus();
}, delay || 0);
}
document.addEventListener('DOMContentLoaded', function() {
{% if new_service_id %}
var serviceRow = document.getElementById('service-{{ new_service_id }}');
if (serviceRow) {
scrollToElement(serviceRow, 300);
setTimeout(function() {
serviceRow.classList.remove('is-highlighted');
if (serviceRow.className === '') {
serviceRow.removeAttribute('class');
}
}, 3300);
if (window.OrganizationDashboard) {
window.OrganizationDashboard.highlightAndScrollToService('{{ new_service_id }}');
}
{% endif %}
{% if updated_service_id %}
var updatedServiceRow = document.getElementById('service-{{ updated_service_id }}');
if (updatedServiceRow) {
scrollToElement(updatedServiceRow, 300);
setTimeout(function() {
updatedServiceRow.classList.remove('is-highlighted');
if (updatedServiceRow.className === '') {
updatedServiceRow.removeAttribute('class');
}
}, 3300);
if (window.OrganizationDashboard) {
window.OrganizationDashboard.highlightAndScrollToService('{{ updated_service_id }}');
}
{% endif %}
requestAnimationFrame(function() {
var form = document.getElementById('create-service-form') ||
document.getElementById('invite-user-form') ||
document.getElementById('edit-service-form');
if (form) {
scrollToElement(form, 50);
focusFirstInput(form, 150);
}
});
var confirmEditButton = document.getElementById('edit-service-confirm-btn');
if (confirmEditButton) {
confirmEditButton.addEventListener('click', function() {
var editForm = document.getElementById('edit-service-form');
if (editForm) {
editForm.submit();
}
});
}
})();
});
</script>
{{ super() }}
{% endblock %}