feat: dynamic menu reload on login/logout
- shell.ui: add id to menu urlwidget, binds for sage_login/sage_logout events - shell_theme.js: add sageReloadMenu() to rebuild menu urlwidget - global_menu.ui: complete with all 22 modules and role-based visibility
This commit is contained in:
parent
dfe6c0e14f
commit
cbe725bcee
@ -110,10 +110,27 @@
|
|||||||
"subwidgets": [
|
"subwidgets": [
|
||||||
{
|
{
|
||||||
"widgettype": "urlwidget",
|
"widgettype": "urlwidget",
|
||||||
|
"id": "global_menu_widget",
|
||||||
"options": {
|
"options": {
|
||||||
"url": "{{entire_url('global_menu.ui')}}"
|
"url": "{{entire_url('global_menu.ui')}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"binds": [
|
||||||
|
{
|
||||||
|
"wid": "app",
|
||||||
|
"event": "sage_login",
|
||||||
|
"actiontype": "script",
|
||||||
|
"target": "self",
|
||||||
|
"script": "sageReloadMenu()"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wid": "app",
|
||||||
|
"event": "sage_logout",
|
||||||
|
"actiontype": "script",
|
||||||
|
"target": "self",
|
||||||
|
"script": "sageReloadMenu()"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -80,6 +80,36 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reload global menu after login/logout
|
||||||
|
window.sageReloadMenu = async function() {
|
||||||
|
if (typeof bricks === 'undefined') return;
|
||||||
|
var sidebar = bricks.getWidgetById('sage_sidebar', bricks.app);
|
||||||
|
if (!sidebar) {
|
||||||
|
console.log('[Shell] sage_sidebar not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Clear existing children
|
||||||
|
sidebar.subwidgets.forEach(function(w) { w.destroy && w.destroy(); });
|
||||||
|
sidebar.subwidgets = [];
|
||||||
|
sidebar.el.innerHTML = '';
|
||||||
|
// Rebuild menu urlwidget
|
||||||
|
var menuUrl = bricks.app.baseUrl + '/global_menu.ui?_webbricks_=1';
|
||||||
|
var desc = {
|
||||||
|
"widgettype": "urlwidget",
|
||||||
|
"id": "global_menu_widget",
|
||||||
|
"options": { "url": menuUrl }
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
var w = await bricks.widgetBuild(desc, sidebar);
|
||||||
|
if (w) {
|
||||||
|
sidebar.addSubWidget(w);
|
||||||
|
console.log('[Shell] Menu reloaded');
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log('[Shell] Menu reload error:', e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Run on DOM ready
|
// Run on DOM ready
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user