mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 04:38:24 -04:00
ove organization dashboard JS to separate file
This commit is contained in:
committed by
Alex Janousek
parent
8ee2d386c7
commit
f57ad08007
@@ -60,6 +60,7 @@ import { initCurrentYear } from './date.js';
|
|||||||
import './sidenav.js';
|
import './sidenav.js';
|
||||||
import './validation.js';
|
import './validation.js';
|
||||||
import './scrollPosition.js';
|
import './scrollPosition.js';
|
||||||
|
import './organizationDashboard.js';
|
||||||
|
|
||||||
initCurrentYear();
|
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 %}
|
{% block extra_javascripts %}
|
||||||
<script nonce="{{ csp_nonce() }}">
|
<script nonce="{{ csp_nonce() }}">
|
||||||
(function() {
|
document.addEventListener('DOMContentLoaded', 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
{% if new_service_id %}
|
{% if new_service_id %}
|
||||||
var serviceRow = document.getElementById('service-{{ new_service_id }}');
|
if (window.OrganizationDashboard) {
|
||||||
if (serviceRow) {
|
window.OrganizationDashboard.highlightAndScrollToService('{{ new_service_id }}');
|
||||||
scrollToElement(serviceRow, 300);
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
serviceRow.classList.remove('is-highlighted');
|
|
||||||
if (serviceRow.className === '') {
|
|
||||||
serviceRow.removeAttribute('class');
|
|
||||||
}
|
|
||||||
}, 3300);
|
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if updated_service_id %}
|
{% if updated_service_id %}
|
||||||
var updatedServiceRow = document.getElementById('service-{{ updated_service_id }}');
|
if (window.OrganizationDashboard) {
|
||||||
if (updatedServiceRow) {
|
window.OrganizationDashboard.highlightAndScrollToService('{{ updated_service_id }}');
|
||||||
scrollToElement(updatedServiceRow, 300);
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
updatedServiceRow.classList.remove('is-highlighted');
|
|
||||||
if (updatedServiceRow.className === '') {
|
|
||||||
updatedServiceRow.removeAttribute('class');
|
|
||||||
}
|
|
||||||
}, 3300);
|
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% 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>
|
</script>
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user