fixed
This commit is contained in:
@@ -211,34 +211,65 @@
|
||||
</details>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.querySelectorAll('[data-helpdesk-status-form]').forEach(function (form) {
|
||||
const statusSelect = form.querySelector('[data-dusk="ticket-show-status"]');
|
||||
const dialog = form.querySelector('[data-helpdesk-close-ticket-dialog]');
|
||||
const comment = form.querySelector('[data-helpdesk-closure-comment]');
|
||||
const cancel = form.querySelector('[data-helpdesk-close-dialog-cancel]');
|
||||
|
||||
if (!statusSelect || !dialog || !comment) {
|
||||
return;
|
||||
}
|
||||
|
||||
form.addEventListener('submit', function (event) {
|
||||
const selectedOption = statusSelect.options[statusSelect.selectedIndex];
|
||||
const isClosing = selectedOption?.dataset?.isClosed === '1';
|
||||
|
||||
if (!isClosing || comment.value.trim().length >= 10) {
|
||||
(() => {
|
||||
const initialiseCloseTicketDialogs = () => {
|
||||
document.querySelectorAll('[data-helpdesk-status-form]').forEach((form) => {
|
||||
if (form.dataset.helpdeskCloseDialogInitialised === '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
dialog.showModal();
|
||||
comment.focus();
|
||||
});
|
||||
form.dataset.helpdeskCloseDialogInitialised = '1';
|
||||
|
||||
cancel?.addEventListener('click', function () {
|
||||
dialog.close();
|
||||
const statusSelect = form.querySelector('[data-dusk="ticket-show-status"]');
|
||||
const dialog = form.querySelector('[data-helpdesk-close-ticket-dialog]');
|
||||
const comment = form.querySelector('[data-helpdesk-closure-comment]');
|
||||
const cancel = form.querySelector('[data-helpdesk-close-dialog-cancel]');
|
||||
const originalStatus = statusSelect?.value || '';
|
||||
|
||||
if (!statusSelect || !dialog || !comment) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedStatusIsClosed = () => {
|
||||
const selectedOption = statusSelect.options[statusSelect.selectedIndex];
|
||||
|
||||
return selectedOption?.dataset?.isClosed === '1';
|
||||
};
|
||||
|
||||
const openDialog = () => {
|
||||
if (!dialog.open) {
|
||||
dialog.showModal();
|
||||
}
|
||||
|
||||
window.setTimeout(() => comment.focus(), 50);
|
||||
};
|
||||
|
||||
statusSelect.addEventListener('change', () => {
|
||||
if (selectedStatusIsClosed()) {
|
||||
openDialog();
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener('submit', (event) => {
|
||||
if (!selectedStatusIsClosed() || comment.value.trim().length >= 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
openDialog();
|
||||
});
|
||||
|
||||
cancel?.addEventListener('click', () => {
|
||||
dialog.close();
|
||||
statusSelect.value = originalStatus;
|
||||
statusSelect.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initialiseCloseTicketDialogs);
|
||||
document.addEventListener('livewire:navigated', initialiseCloseTicketDialogs);
|
||||
initialiseCloseTicketDialogs();
|
||||
})();
|
||||
</script>
|
||||
@endcan
|
||||
|
||||
Reference in New Issue
Block a user