mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 19:03:30 -05:00
ove organization dashboard JS to separate file
This commit is contained in:
@@ -60,6 +60,7 @@ import { initCurrentYear } from './date.js';
|
||||
import './sidenav.js';
|
||||
import './validation.js';
|
||||
import './scrollPosition.js';
|
||||
import './organizationDashboard.js';
|
||||
|
||||
initCurrentYear();
|
||||
|
||||
|
||||
68
app/assets/javascripts/organizationDashboard.js
Normal file
68
app/assets/javascripts/organizationDashboard.js
Normal 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
|
||||
};
|
||||
})();
|
||||
@@ -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 %}
|
||||
|
||||
Reference in New Issue
Block a user