fix "x"
This commit is contained in:
136
public/js/app.js
136
public/js/app.js
@@ -2182,10 +2182,7 @@ class AccountManager {
|
||||
}
|
||||
|
||||
setupEventListeners() {
|
||||
// Modal close buttons
|
||||
document.querySelectorAll('[data-close-modal]').forEach(btn => {
|
||||
btn.addEventListener('click', () => this.closeModals());
|
||||
});
|
||||
this.setupModalCloseListeners();
|
||||
|
||||
// Close with Escape key
|
||||
document.addEventListener('keydown', (e) => {
|
||||
@@ -2336,30 +2333,12 @@ class AccountManager {
|
||||
confirmAssetRequestDeleteBtn.dataset.boundClick = 'true';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.cancel-asset-request-delete-confirm').forEach(btn => {
|
||||
if (btn.dataset.boundClick === 'true') {
|
||||
return;
|
||||
}
|
||||
|
||||
btn.addEventListener('click', () => this.resolveAssetRequestDeleteConfirm(false));
|
||||
btn.dataset.boundClick = 'true';
|
||||
});
|
||||
|
||||
const confirmBulkAssetDeleteBtn = document.getElementById('confirmBulkAssetDeleteBtn');
|
||||
if (confirmBulkAssetDeleteBtn && confirmBulkAssetDeleteBtn.dataset.boundClick !== 'true') {
|
||||
confirmBulkAssetDeleteBtn.addEventListener('click', () => this.resolveBulkAssetDeleteConfirm(true));
|
||||
confirmBulkAssetDeleteBtn.dataset.boundClick = 'true';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.cancel-bulk-asset-delete-confirm').forEach(btn => {
|
||||
if (btn.dataset.boundClick === 'true') {
|
||||
return;
|
||||
}
|
||||
|
||||
btn.addEventListener('click', () => this.resolveBulkAssetDeleteConfirm(false));
|
||||
btn.dataset.boundClick = 'true';
|
||||
});
|
||||
|
||||
this.setupAssetBorrowRequestModalListeners();
|
||||
|
||||
const assetDepartmentForm = document.getElementById('assetDepartmentForm');
|
||||
@@ -2396,14 +2375,6 @@ class AccountManager {
|
||||
btn.dataset.boundClick = 'true';
|
||||
});
|
||||
|
||||
// Close when clicking backdrop outside modal content
|
||||
document.querySelectorAll('.modal-backdrop').forEach(backdrop => {
|
||||
backdrop.addEventListener('click', (evt) => {
|
||||
if (evt.target === backdrop) {
|
||||
this.closeModals();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
updateAccountDisplay() {
|
||||
@@ -5250,7 +5221,7 @@ class AccountManager {
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded ${selectedStatusMeta.className}">${selectedStatusMeta.label}</span>
|
||||
</div>
|
||||
</div>
|
||||
<button class="p-1.5 rounded-lg hover:bg-slate-200 text-slate-400 transition-colors" onclick="closeAssetBorrowDetailsModal()" title="Đóng">
|
||||
<button type="button" class="p-1.5 rounded-lg hover:bg-slate-200 text-slate-400 transition-colors" data-close-modal="assetBorrowDetailsModal" title="Đóng">
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -5273,20 +5244,12 @@ class AccountManager {
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4 border-t border-slate-100 bg-white flex justify-end">
|
||||
<button type="button" class="px-4 py-2 text-xs font-bold text-slate-600 border border-slate-200 rounded-lg hover:bg-slate-50" onclick="closeAssetBorrowDetailsModal()">Đóng</button>
|
||||
<button type="button" class="px-4 py-2 text-xs font-bold text-slate-600 border border-slate-200 rounded-lg hover:bg-slate-50" data-close-modal="assetBorrowDetailsModal">Đóng</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const modal = document.getElementById('assetBorrowDetailsModal');
|
||||
if (modal) {
|
||||
modal.addEventListener('click', event => {
|
||||
if (event.target === modal) {
|
||||
closeAssetBorrowDetailsModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setupAssetBorrowPagerListeners() {
|
||||
@@ -10827,6 +10790,53 @@ class AccountManager {
|
||||
document.getElementById('appModal').classList.add('open');
|
||||
}
|
||||
|
||||
setupModalCloseListeners() {
|
||||
if (this.modalCloseListenersBound) return;
|
||||
|
||||
// Modals are loaded asynchronously and some forms are recreated on each open.
|
||||
// Delegate clicks so both work without inline handlers blocked by CSP.
|
||||
document.addEventListener('click', event => {
|
||||
const closeButton = event.target.closest?.('[data-close-modal]');
|
||||
if (closeButton) {
|
||||
event.preventDefault();
|
||||
const modalId = closeButton.dataset.closeModal
|
||||
|| closeButton.closest('.modal-backdrop')?.id;
|
||||
if (modalId) this.closeModal(modalId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.classList?.contains('modal-backdrop')) {
|
||||
this.closeModal(event.target.id);
|
||||
}
|
||||
});
|
||||
this.modalCloseListenersBound = true;
|
||||
}
|
||||
|
||||
closeModal(modalId) {
|
||||
// These dialogs also own temporary state, child dialogs, or pending promises.
|
||||
const closeHandlers = {
|
||||
consumableBorrowRequestModal: closeConsumableBorrowRequestModal,
|
||||
consumableBorrowRequestsModal: closeConsumableBorrowRequestsModal,
|
||||
consumableRequestRejectModal: closeConsumableRequestRejectModal,
|
||||
consumableReturnModal: closeConsumableReturnModal,
|
||||
bulkDeleteAssetsConfirmModal: closeBulkDeleteAssetsConfirmModal,
|
||||
assetBorrowRequestModal: closeAssetBorrowRequestModal,
|
||||
assetPendingRequestsModal: closeAssetPendingRequestsModal,
|
||||
assetRequestDeleteConfirmModal: closeAssetRequestDeleteConfirmModal,
|
||||
userModal: closeUserModal,
|
||||
roleModal: closeRoleModal,
|
||||
userDetailsModal: closeUserDetailsModal,
|
||||
profileModal: closeProfileModal,
|
||||
notificationComposerModal: () => document.getElementById('notificationComposerModal')?.remove()
|
||||
};
|
||||
|
||||
if (Object.hasOwn(closeHandlers, modalId)) {
|
||||
closeHandlers[modalId]();
|
||||
} else {
|
||||
document.getElementById(modalId)?.classList.remove('open');
|
||||
}
|
||||
}
|
||||
|
||||
closeModals() {
|
||||
if (this.pendingAssetRequestDeleteConfirmResolver) {
|
||||
this.resolveAssetRequestDeleteConfirm(false);
|
||||
@@ -10834,10 +10844,9 @@ class AccountManager {
|
||||
if (this.pendingBulkAssetDeleteConfirmResolver) {
|
||||
this.resolveBulkAssetDeleteConfirm(false);
|
||||
}
|
||||
document.querySelectorAll('.modal-backdrop').forEach(modal => {
|
||||
modal.classList.remove('open');
|
||||
document.querySelectorAll('.modal-backdrop.open').forEach(modal => {
|
||||
this.closeModal(modal.id);
|
||||
});
|
||||
document.getElementById('notificationComposerModal')?.remove();
|
||||
this.pendingConsumableRequestRejectId = undefined;
|
||||
}
|
||||
|
||||
@@ -10926,7 +10935,7 @@ class AccountManager {
|
||||
</div>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<button type="button" onclick="closeProfileModal()" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Cancel</button>
|
||||
<button type="button" data-close-modal="profileModal" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Cancel</button>
|
||||
<button type="submit" class="flex-1 px-4 py-2 bg-primary hover:bg-primary-dim text-on-primary font-bold rounded-lg transition-colors">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -10950,14 +10959,6 @@ class AccountManager {
|
||||
|
||||
this.setupProfilePasswordToggles();
|
||||
|
||||
const modal = document.getElementById('profileModal');
|
||||
if (modal) {
|
||||
modal.addEventListener('click', (e) => {
|
||||
if (e.target === modal) {
|
||||
closeProfileModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setupProfilePasswordToggles() {
|
||||
@@ -11336,7 +11337,7 @@ class AccountManager {
|
||||
<textarea id="roleDescription" placeholder="Describe this role permissions" class="w-full px-3 py-2 border border-outline-variant/30 rounded-lg bg-surface-container-low dark:bg-slate-800 min-h-[90px]"></textarea>
|
||||
</div>
|
||||
<div class="flex gap-3 pt-2">
|
||||
<button type="button" onclick="closeRoleModal()" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Cancel</button>
|
||||
<button type="button" data-close-modal="roleModal" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Cancel</button>
|
||||
<button type="submit" class="flex-1 px-4 py-2 bg-primary hover:bg-primary-dim text-on-primary font-bold rounded-lg transition-colors">Save Role</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -11359,14 +11360,6 @@ class AccountManager {
|
||||
form.addEventListener('submit', (e) => this.saveRole(e));
|
||||
}
|
||||
|
||||
const modal = document.getElementById('roleModal');
|
||||
if (modal) {
|
||||
modal.addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeRoleModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async saveRole(e) {
|
||||
@@ -11456,7 +11449,7 @@ class AccountManager {
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex gap-3 pt-4">
|
||||
<button type="button" onclick="closeUserModal()" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Cancel</button>
|
||||
<button type="button" data-close-modal="userModal" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Cancel</button>
|
||||
<button type="submit" class="flex-1 px-4 py-2 bg-primary hover:bg-primary-dim text-on-primary font-bold rounded-lg transition-colors">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -11494,15 +11487,6 @@ class AccountManager {
|
||||
});
|
||||
}
|
||||
|
||||
// Close on backdrop click
|
||||
const modal = document.getElementById('userModal');
|
||||
if (modal) {
|
||||
modal.addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeUserModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async saveUser(e, userId) {
|
||||
@@ -11633,7 +11617,7 @@ class AccountManager {
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex gap-3 pt-2">
|
||||
<button type="button" onclick="closeUserDetailsModal()" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Close</button>
|
||||
<button type="button" data-close-modal="userDetailsModal" class="flex-1 px-4 py-2 bg-outline/10 hover:bg-outline/20 rounded-lg transition-colors">Close</button>
|
||||
<button type="button" id="userDetailEditBtn" class="flex-1 px-4 py-2 bg-primary hover:bg-primary-dim text-on-primary font-bold rounded-lg transition-colors">Edit</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -11659,7 +11643,6 @@ class AccountManager {
|
||||
const createdDateEl = document.getElementById('userDetailCreatedDate');
|
||||
const lastLoginEl = document.getElementById('userDetailLastLogin');
|
||||
const editBtn = document.getElementById('userDetailEditBtn');
|
||||
const detailsModal = document.getElementById('userDetailsModal');
|
||||
|
||||
if (usernameEl) usernameEl.textContent = user?.Username || '-';
|
||||
if (fullNameEl) fullNameEl.textContent = user?.FullName || '-';
|
||||
@@ -11675,13 +11658,6 @@ class AccountManager {
|
||||
});
|
||||
}
|
||||
|
||||
if (detailsModal) {
|
||||
detailsModal.addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeUserDetailsModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async deleteUserConfirm(userId) {
|
||||
|
||||
Reference in New Issue
Block a user