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