forked from UKSOURCE/cms.hailearning.edu.vn
Merge pull request 'refactor(header): improve code formatting and add JSON response support' (#30) from refactor/huy-06022026-header-code-formatting into main
Reviewed-on: UKSOURCE/cms.hailearning.edu.vn#30
This commit is contained in:
@@ -268,6 +268,11 @@
|
||||
tab.addEventListener('shown.bs.tab', function (event) {
|
||||
const targetId = event.target.getAttribute('href').substring(1);
|
||||
document.getElementById('activeTabInput').value = targetId;
|
||||
|
||||
// Update URL without reload to preserve tab state
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('tab', targetId);
|
||||
window.history.replaceState({}, '', url);
|
||||
|
||||
// Only load Menu Tree if clicking on the menu tab
|
||||
if (targetId === 'menu') {
|
||||
@@ -365,6 +370,12 @@
|
||||
showNotification('All changes saved successfully', 'success');
|
||||
submitBtn.classList.remove('btn-primary');
|
||||
submitBtn.classList.add('btn-outline-primary');
|
||||
|
||||
// Reload to refresh data, preserve current tab
|
||||
const currentTab = document.getElementById('activeTabInput').value;
|
||||
setTimeout(() => {
|
||||
window.location.href = window.location.pathname + '?tab=' + currentTab;
|
||||
}, 1000);
|
||||
} else {
|
||||
const errorMsg = (!headerResult.success ? headerResult.message : '') || (!menuResult.success ? menuResult.message : '') || 'Unable to save some changes';
|
||||
showNotification('Error: ' + errorMsg, 'error');
|
||||
@@ -1113,19 +1124,29 @@
|
||||
console.log('Response:', response.data);
|
||||
|
||||
if (response.data.success || response.status === 200) {
|
||||
showToast('Success', 'Menu information has been updated', 'success');
|
||||
showNotification('Menu item saved successfully', 'success');
|
||||
|
||||
// Hide modal
|
||||
const modalElement = document.getElementById('modalAddMenu');
|
||||
const modal = bootstrap.Modal.getOrCreateInstance(modalElement);
|
||||
modal.hide();
|
||||
// Refresh data or reload tab
|
||||
setTimeout(() => window.location.reload(), 1000);
|
||||
|
||||
// Mark as changed so user needs to click Save Changes
|
||||
if (typeof window.markHeaderChanged === 'function') {
|
||||
window.markHeaderChanged();
|
||||
}
|
||||
|
||||
// Reload page to show updated menu structure, preserve current tab
|
||||
const currentTab = document.getElementById('activeTabInput').value;
|
||||
setTimeout(() => {
|
||||
window.location.href = window.location.pathname + '?tab=' + currentTab;
|
||||
}, 1000);
|
||||
} else {
|
||||
showToast('Error', response.data.message || 'Unable to save menu', 'error');
|
||||
showNotification(response.data.message || 'Unable to save menu', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('AJAX Error:', error);
|
||||
showToast('Error', 'Server connection error: ' + (error.response?.data?.message || error.message), 'error');
|
||||
showNotification('Server connection error: ' + (error.response?.data?.message || error.message), 'error');
|
||||
} finally {
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = false;
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<span class="badge bg-light text-dark border ms-2" style="font-size: 0.7rem;">External</span>
|
||||
<% } %>
|
||||
<% if (item.status === 'inactive') { %>
|
||||
<span class="badge bg-soft-secondary ms-2">Inactive</span>
|
||||
<span class="badge ms-2 bg-soft-danger text-danger">Inactive</span>
|
||||
<% } else { %>
|
||||
<span class="badge bg-soft-success ms-2">Active</span>
|
||||
<% } %>
|
||||
|
||||
Reference in New Issue
Block a user