Files
raven-client/ayanova/src/api/gzmenu.js
2019-12-30 23:46:06 +00:00

304 lines
8.8 KiB
JavaScript

/* xxxeslint-disable */
/////////////////////////////////
// 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;
if (ctx.icon && !ctx.icon.startsWith("fa-")) {
ctx.icon = "fa-" + ctx.icon;
}
vm.appBar.icon = ctx.icon;
vm.appBar.title = ctx.title;
//Parse the formdata if present
var formAyaType = 0;
var formRecordId = 0;
if (ctx.formData) {
if (ctx.formData.ayaType != undefined) {
formAyaType = ctx.formData.ayaType;
}
if (ctx.formData.ayaType != undefined) {
formRecordId = ctx.formData.recordId;
}
}
//set the help url if presented or default to the User section intro
vm.appBar.helpUrl = ctx.helpUrl ? ctx.helpUrl : "user-intro";
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 });
}
//WIKI, ATTACHMENTS, RECORD HISTORY
if (formAyaType != 0 && formRecordId != 0) {
vm.appBar.menuItems.push({
title: window.$gz.locale.get("Attachments"),
icon: "paperclip",
key: "app:attachments",
data: { ayaType: formAyaType, recordId: formRecordId }
});
vm.appBar.menuItems.push({
title: window.$gz.locale.get("WikiPage"),
icon: "feather",
key: "app:wiki",
data: { ayaType: formAyaType, recordId: formRecordId }
});
vm.appBar.menuItems.push({
title: window.$gz.locale.get("Review"),
icon: "calendar-check",
key: "app:review",
data: { ayaType: formAyaType, recordId: formRecordId }
});
vm.appBar.menuItems.push({
title: window.$gz.locale.get("History"),
icon: "history",
key: "app:history",
data: { ayaType: formAyaType, recordId: formRecordId }
});
}
//CUSTOMIZE
//set custom fields and link to locale text editor
if (
ctx.formData &&
ctx.formData.formCustomTemplateKey != undefined &&
window.$gz.role.hasRole(window.$gz.role.AUTHORIZATION_ROLES.BizAdminFull)
) {
//add customize menu item
//DIVIDER
//Insert the devider between context and global items
vm.appBar.menuItems.push({ divider: true, inset: false });
//customize
vm.appBar.menuItems.push({
title: window.$gz.locale.get("Customize"),
icon: "sliders-h",
data: ctx.formData.formCustomTemplateKey,
key: "app:customize"
});
}
//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
//divider
vm.appBar.menuItems.push({ divider: true, inset: false });
//SEARCH
vm.appBar.menuItems.push({
title: window.$gz.locale.get("Search"),
icon: "search",
key: "app:search",
data: formAyaType
});
//HELP
vm.appBar.menuItems.push({
title: window.$gz.locale.get("MenuHelp"),
icon: "question-circle",
key: "app:help",
data: vm.appBar.helpUrl
});
//ABOUT
vm.appBar.menuItems.push({
title: window.$gz.locale.get("HelpAboutAyaNova"),
icon: "info-circle",
key: "app:nav:abt",
data: "ay-about"
});
//LOGOUT
vm.appBar.menuItems.push({
title: window.$gz.locale.get("Logout"),
icon: "sign-out-alt",
key: "app:logout"
});
},
///////////////////////////////
// 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 "search":
vm.$router.push({
name: "home-search",
params: { ayatype: item.data }
});
break;
case "attachments":
vm.$router.push({
name: "ay-attachments",
params: { ayatype: item.data.ayaType, recordid: item.data.recordId }
});
break;
case "wiki":
vm.$router.push({
name: "ay-wiki",
params: { ayatype: item.data.ayaType, recordid: item.data.recordId }
});
break;
case "review":
vm.$router.push({
name: "ay-review",
params: { ayatype: item.data.ayaType, recordid: item.data.recordId }
});
break;
case "history":
vm.$router.push({
name: "ay-history",
params: { ayatype: item.data.ayaType, recordid: item.data.recordId }
});
break;
case "logout":
vm.$router.push("/login");
break;
case "customize":
vm.$router.push({
name: "ay-customize",
params: { formCustomTemplateKey: item.data }
});
break;
case "nav":
vm.$router.push({ name: item.data });
break;
default:
window.$gz.eventBus.$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 MENU EVENTS
//
// called once from app.vue only
//
wireUpEventHandlers(vm) {
var self = this;
window.$gz.eventBus.$on("menu-change", function handleMenuChange(ctx) {
self.handleMenuChange(vm, ctx);
});
window.$gz.eventBus.$on("menu-replace-item", function handleReplaceMenuItem(
newItem
) {
self.handleReplaceMenuItem(vm, newItem);
});
window.$gz.eventBus.$on("menu-disable-item", function handleDisableMenuItem(
key
) {
self.handleDisableMenuItem(vm, key, true);
});
window.$gz.eventBus.$on("menu-enable-item", function handleDisableMenuItem(
key
) {
self.handleDisableMenuItem(vm, key, false);
});
window.$gz.eventBus.$on("menu-click", function handleMenuClick(menuitem) {
self.handleAppClick(vm, menuitem);
});
}
//new functions above here
};