136 lines
4.1 KiB
JavaScript
136 lines
4.1 KiB
JavaScript
/* Xeslint-disable */
|
|
import { processLogout } from "./authutil";
|
|
|
|
/////////////////////////////////
|
|
// Menu utils and handlers
|
|
//
|
|
export default {
|
|
///////////////////////////////
|
|
// CHANGE HANDLER
|
|
//
|
|
// Deal with a menu change request
|
|
// called from App.vue
|
|
handleMenuChange(that, ctx) {
|
|
that.appBar.isMain = ctx.isMain;
|
|
that.appBar.icon = ctx.icon;
|
|
that.appBar.title = ctx.title;
|
|
//set the help url if presented or default to the top of the index
|
|
that.appBar.helpUrl = ctx.helpUrl ? ctx.helpUrl : "index.html";
|
|
that.appBar.menuItems = [];
|
|
|
|
//CONTEXT TOP PORTION
|
|
//populate the context portion of the menu so handle accordingly
|
|
if (ctx.menuItems) {
|
|
that.appBar.menuItems = ctx.menuItems;
|
|
//DIVIDER
|
|
//Insert the devider between context and global items
|
|
that.appBar.menuItems.push({ divider: true, inset: false });
|
|
}
|
|
|
|
//GLOBAL BOTTOM PORTION
|
|
|
|
//Global sub-heading
|
|
//Likely won't want this but here anyway to see
|
|
//that.appBar.menuItems.push({ header: "GLOBAL" });
|
|
|
|
//global menu items
|
|
|
|
//LOGOUT
|
|
that.appBar.menuItems.push({
|
|
title: that.$gzlocale.get("Logout"),
|
|
icon: "sign-out-alt",
|
|
color: "pink",
|
|
key: "app:logout"
|
|
});
|
|
|
|
//divider
|
|
that.appBar.menuItems.push({ divider: true, inset: false });
|
|
|
|
//HELP
|
|
that.appBar.menuItems.push({
|
|
title: that.$gzlocale.get("MenuHelp"),
|
|
icon: "question-circle",
|
|
key: "app:help",
|
|
data: that.appBar.helpUrl
|
|
});
|
|
|
|
//ABOUT
|
|
that.appBar.menuItems.push({
|
|
title: that.$gzlocale.get("HelpAboutAyaNova"),
|
|
icon: "info-circle",
|
|
key: "app:nav:abt",
|
|
data: "about"
|
|
});
|
|
},
|
|
///////////////////////////////
|
|
// CHANGE HANDLER
|
|
//
|
|
// Deal with a menu item update request
|
|
// called from App.vue
|
|
handleReplaceMenuItem(that, newItem) {
|
|
if (!that.appBar.menuItems || !newItem) {
|
|
return;
|
|
}
|
|
//Find the key that is in the collection and replace it
|
|
for (var i = 0; i < that.appBar.menuItems.length; i++) {
|
|
if (that.appBar.menuItems[i].key == newItem.key) {
|
|
//NOTE: since we are adding a new object, it has no reactivity in it so we need to use the Vue.Set to set it which
|
|
//automatically adds the setters and getters that trigger reactivity
|
|
//If it was set directly on the array it wouldn't update the UI
|
|
that.$set(that.appBar.menuItems, i, newItem);
|
|
return;
|
|
}
|
|
}
|
|
},
|
|
///////////////////////////////
|
|
// APP (GLOBAL) CLICK HANDLER
|
|
//
|
|
// Deal with a menu change request
|
|
// called from App.vue
|
|
handleAppClick(that, menuitem) {
|
|
//Key will start with the string "app:" if it's a global application command that should be handled here,
|
|
//otherwise it's a local command for a local form only
|
|
//If there is any extended information required for the command it will be in the data property of the menu item
|
|
//split a key into component parts, part one is the responsible party, part two is the command, part three only exists to make it unique if necessary
|
|
//each part is separated by a colon
|
|
|
|
//Handle different items
|
|
if (!menuitem.disabled && menuitem.key.startsWith("app:")) {
|
|
var keyparts = menuitem.key.split(":");
|
|
var cmd = keyparts[1];
|
|
switch (cmd) {
|
|
case "help":
|
|
var helpurl = that.$store.state.helpUrl + menuitem.data;
|
|
window.open(helpurl, "_blank");
|
|
break;
|
|
case "logout":
|
|
processLogout();
|
|
that.$router.replace({ name: "login" });
|
|
break;
|
|
case "nav":
|
|
that.$router.replace({ name: menuitem.data });
|
|
break;
|
|
default:
|
|
alert(
|
|
"gzmenu:handleAppClick - unrecognized command [" +
|
|
menuitem.key +
|
|
"]"
|
|
);
|
|
}
|
|
}
|
|
},
|
|
///////////////////////////////
|
|
// CONFIRM RELEVANT CLICK
|
|
//
|
|
// confirm the click is relevant
|
|
// to a contextual caller
|
|
// called by all forms except app.vue
|
|
isRelevantClick(menuitem) {
|
|
if (!menuitem.disabled && !menuitem.key.startsWith("app:")) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
//new functions above here
|
|
};
|