Files
raven-client/ayanova/src/api/gzmenu.js
2019-05-02 20:20:11 +00:00

233 lines
6.6 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(vm, ctx) {
vm.appBar.isMain = ctx.isMain;
vm.appBar.icon = ctx.icon;
vm.appBar.title = ctx.title;
//set the help url if presented or default to the top of the index
vm.appBar.helpUrl = ctx.helpUrl ? ctx.helpUrl : "index.html";
vm.appBar.menuItems = [];
//CONTEXT TOP PORTION
//populate the context portion of the menu so handle accordingly
if (ctx.menuItems) {
vm.appBar.menuItems = ctx.menuItems;
//DIVIDER
//Insert the devider between context and global items
vm.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
vm.appBar.menuItems.push({
title: vm.$gzlocale.get("Logout"),
icon: "sign-out-alt",
key: "app:logout"
});
//divider
vm.appBar.menuItems.push({ divider: true, inset: false });
//HELP
vm.appBar.menuItems.push({
title: vm.$gzlocale.get("MenuHelp"),
icon: "question-circle",
key: "app:help",
data: vm.appBar.helpUrl
});
//ABOUT
vm.appBar.menuItems.push({
title: vm.$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(vm, newItem) {
if (!vm.appBar.menuItems || !newItem) {
return;
}
//Find the key that is in the collection and replace it
for (var i = 0; i < vm.appBar.menuItems.length; i++) {
if (vm.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
vm.$set(vm.appBar.menuItems, i, newItem);
return;
}
}
},
///////////////////////////////
// ENABLE / DISABLE HANDLER
//
// Deal with a menu item enable / disable
// called from App.vue
handleDisableMenuItem(vm, key, disabled) {
if (!vm.appBar.menuItems || !key) {
return;
}
//Find the key that is in the collection and replace it
for (var i = 0; i < vm.appBar.menuItems.length; i++) {
var menuItem = vm.appBar.menuItems[i];
if (menuItem.key == key) {
vm.$set(vm.appBar.menuItems[i], "disabled", disabled);
//menuItem.disabled = disabled;
}
vm.$set(vm.appBar.menuItems[i], "color", disabled ? "disabled" : "");
return;
}
},
///////////////////////////////
// APP (GLOBAL) CLICK HANDLER
//
// Deal with a menu change request
// called from App.vue
handleAppClick(vm, 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
var item = this.parseMenuItem(menuItem);
if (!item.disabled && item.owner == "app") {
switch (item.key) {
case "help":
var helpurl = vm.$store.state.helpUrl + item.data;
window.open(helpurl, "_blank");
break;
case "logout":
processLogout();
vm.$router.push({ name: "login" });
break;
case "nav":
vm.$router.push({ name: item.data });
break;
default:
vm.$gzevent.$emit(
"notify-warning",
"gzmenu:handleAppClick - unrecognized command [" +
menuItem.key +
"]"
);
}
}
},
///////////////////////////////
// PARSE MENU ITEM CLICK
//
// parse out the parts of a
// menu item from a click event
//
parseMenuItem(menuItem) {
//format is "AREA:KEY:UNIQUEID"
//and data is in data portion
var keyparts = menuItem.key.split(":");
return {
owner: keyparts[0],
key: keyparts[1],
data: menuItem.data,
disabled: menuItem.disabled,
vm: menuItem.vm ? menuItem.vm : null
};
},
///////////////////////////////
// WIRE UP MAIN APP EVENTS
//
// called only by app.vue
//
wireUpAppEventHandlers(vm) {
var self = this;
vm.$gzevent.$on("menu-change", function handleMenuChange(ctx) {
self.handleMenuChange(vm, ctx);
});
vm.$gzevent.$on("menu-replace-item", function handleReplaceMenuItem(
newItem
) {
self.handleReplaceMenuItem(vm, newItem);
});
vm.$gzevent.$on("menu-disable-item", function handleDisableMenuItem(key) {
self.handleDisableMenuItem(vm, key, true);
});
vm.$gzevent.$on("menu-enable-item", function handleDisableMenuItem(key) {
self.handleDisableMenuItem(vm, key, false);
});
vm.$gzevent.$on("menu-click", function handleMenuClick(menuitem) {
self.handleAppClick(vm, menuitem);
});
//Notifications: pops up and slowly disappears
///////////
//ERROR
vm.$gzevent.$on("notify-error", function handleNotifyWarn(msg) {
vm.$dialog.notify.info(msg, {
position: "top-right",
icon: "fa-exclamation-triangle",
timeout: 8000
});
});
///////////
//WARNING
vm.$gzevent.$on("notify-warning", function handleNotifyWarn(msg) {
vm.$dialog.notify.warning(msg, {
position: "top-right",
icon: "fa-exclamation",
timeout: 7000
});
});
///////////
//INFO
vm.$gzevent.$on("notify-info", function handleNotifyWarn(msg) {
vm.$dialog.notify.info(msg, {
position: "top-right",
icon: "fa-info-circle",
timeout: 6000
});
});
///////////
//SUCCESS
vm.$gzevent.$on("notify-success", function handleNotifyWarn(msg) {
vm.$dialog.notify.success(msg, {
position: "top-right",
icon: "fa-check-circle ",
timeout: 5000
});
});
}
//new functions above here
};