mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-09 14:45:00 -05:00
Converted more files
This commit is contained in:
@@ -1 +1 @@
|
||||
{"esversion": 8, "esnext": false}
|
||||
{"esversion": 11, "esnext": false}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
export const ErrorBanner = {
|
||||
hideBanner: () => $('.banner-dangerous').addClass('display-none'),
|
||||
showBanner: () => $('.banner-dangerous').removeClass('display-none')
|
||||
hideBanner: () => {
|
||||
document.querySelectorAll('.banner-dangerous').forEach(el => el.classList.add('display-none'));
|
||||
},
|
||||
showBanner: () => {
|
||||
document.querySelectorAll('.banner-dangerous').forEach(el => el.classList.remove('display-none'));
|
||||
}
|
||||
};
|
||||
|
||||
window.NotifyModules = window.NotifyModules || {};
|
||||
|
||||
@@ -28,30 +28,38 @@ function initUploadStatusAnnouncer() {
|
||||
"use strict";
|
||||
|
||||
window.NotifyModules['file-upload'] = function() {
|
||||
this.submit = () => this.$form.trigger('submit');
|
||||
this.submit = () => this.form.submit();
|
||||
|
||||
this.showCancelButton = () => {
|
||||
$('.file-upload-button', this.$form).replaceWith(`
|
||||
<button class='usa-button uploading-button' aria-disabled="true" tabindex="0">
|
||||
Uploading<span class="loading-spinner" role="status" aria-label="Uploading"></span>
|
||||
</button>
|
||||
`);
|
||||
const uploadButton = this.form.querySelector('.file-upload-button');
|
||||
if (uploadButton) {
|
||||
uploadButton.outerHTML = `
|
||||
<button class='usa-button uploading-button' aria-disabled="true" tabindex="0">
|
||||
Uploading<span class="loading-spinner" role="status" aria-label="Uploading"></span>
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
};
|
||||
|
||||
this.start = function(component) {
|
||||
this.$form = $(component);
|
||||
this.form = component;
|
||||
|
||||
this.$form.on('click', '[data-module="upload-trigger"]', function () {
|
||||
const inputId = $(this).data('file-input-id');
|
||||
const fileInput = document.getElementById(inputId);
|
||||
if (fileInput) fileInput.click();
|
||||
this.form.addEventListener('click', (event) => {
|
||||
const trigger = event.target.closest('[data-module="upload-trigger"]');
|
||||
if (trigger) {
|
||||
const inputId = trigger.dataset.fileInputId;
|
||||
const fileInput = document.getElementById(inputId);
|
||||
if (fileInput) fileInput.click();
|
||||
}
|
||||
});
|
||||
|
||||
$(window).on("pageshow", () => this.$form[0].reset());
|
||||
window.addEventListener("pageshow", () => this.form.reset());
|
||||
|
||||
this.$form.on('change', '.file-upload-field', () => {
|
||||
this.submit();
|
||||
this.showCancelButton();
|
||||
this.form.addEventListener('change', (event) => {
|
||||
if (event.target.closest('.file-upload-field')) {
|
||||
this.submit();
|
||||
this.showCancelButton();
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,45 +2,51 @@
|
||||
"use strict";
|
||||
|
||||
const disableSubmitButtons = function (event) {
|
||||
const $submitButton = $(this).find(':submit');
|
||||
const form = event.currentTarget;
|
||||
const submitButton = form.querySelector('input[type="submit"], button[type="submit"]');
|
||||
|
||||
if ($submitButton.data('clicked') === 'true') {
|
||||
if (!submitButton) return;
|
||||
|
||||
if (submitButton.dataset.clicked === 'true') {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
$submitButton.data('clicked', 'true');
|
||||
submitButton.dataset.clicked = 'true';
|
||||
|
||||
// Add loading spinner for Send/Schedule/Cancel buttons
|
||||
const buttonName = $submitButton.attr('name')?.toLowerCase();
|
||||
const buttonName = submitButton.getAttribute('name')?.toLowerCase();
|
||||
if (["send", "schedule", "cancel"].includes(buttonName)) {
|
||||
// Use setTimeout with minimal delay to allow form submission to proceed first
|
||||
setTimeout(() => {
|
||||
$submitButton.prop('disabled', true);
|
||||
submitButton.disabled = true;
|
||||
|
||||
// Add loading spinner and aria-busy attribute for accessibility
|
||||
if ($submitButton.find('.loading-spinner').length === 0) {
|
||||
$submitButton.attr('aria-busy', 'true');
|
||||
$submitButton.append('<span class="loading-spinner" role="status" aria-label="Sending"></span>');
|
||||
if (submitButton.querySelector('.loading-spinner') === null) {
|
||||
submitButton.setAttribute('aria-busy', 'true');
|
||||
submitButton.insertAdjacentHTML('beforeend', '<span class="loading-spinner" role="status" aria-label="Sending"></span>');
|
||||
}
|
||||
|
||||
// Disable Cancel button too
|
||||
const $cancelButton = $('button[name]').filter(function () {
|
||||
return $(this).attr('name')?.toLowerCase() === 'cancel';
|
||||
const cancelButtons = Array.from(document.querySelectorAll('button[name]')).filter(button => {
|
||||
return button.getAttribute('name')?.toLowerCase() === 'cancel';
|
||||
});
|
||||
$cancelButton.prop('disabled', true);
|
||||
cancelButtons.forEach(button => button.disabled = true);
|
||||
}, 50); // Small delay to ensure form submits first
|
||||
} else {
|
||||
setTimeout(() => renableSubmitButton($submitButton)(), 1500);
|
||||
setTimeout(() => renableSubmitButton(submitButton)(), 1500);
|
||||
}
|
||||
};
|
||||
|
||||
const renableSubmitButton = ($submitButton) => () => {
|
||||
$submitButton.data('clicked', '');
|
||||
$submitButton.prop('disabled', false);
|
||||
$submitButton.attr('aria-busy', 'false');
|
||||
$submitButton.find('.loading-spinner').remove(); // clean up spinner
|
||||
const renableSubmitButton = (submitButton) => () => {
|
||||
submitButton.dataset.clicked = '';
|
||||
submitButton.disabled = false;
|
||||
submitButton.setAttribute('aria-busy', 'false');
|
||||
const spinner = submitButton.querySelector('.loading-spinner');
|
||||
if (spinner) spinner.remove(); // clean up spinner
|
||||
};
|
||||
|
||||
$('form').on('submit', disableSubmitButtons);
|
||||
document.querySelectorAll('form').forEach(form => {
|
||||
form.addEventListener('submit', disableSubmitButtons);
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user