/* Xeslint-disable */ function addNavItem(title, icon, route, navItems, key) { window.$gz.store.commit("addNavItem", { title, icon, route, navItems, key: key }); } ///////////////////////////////////// // Initialize the app // on change of authentication status export default function initialize() { var promise = new Promise(function(resolve) { if (window.$gz.store.state.authenticated) { //Fetch the core localized text keys that will always be required by user window.$gz.locale .fetch(window.$gz.locale.coreKeys) .then(function putFetchedNavItemsInStore() { //put nav items into store var key = 0; var sub = []; var subSub = []; //****************** HOME //Everyone has a home //create array of sub items under the home menu item //DASHBOARD sub.push({ title: window.$gz.locale.get("DashboardDashboard"), icon: "tachometer-alt", route: "/dashboard", key: key++ }); //SCHEDULE (personal) sub.push({ title: window.$gz.locale.get("Schedule"), icon: "calendar-alt", route: "/schedule/me", key: key++ }); //MEMOS sub.push({ title: window.$gz.locale.get("Memo"), icon: "inbox", route: "/memo", key: key++ }); //3rd level items under preferences //LOCALE subSub.push({ title: window.$gz.locale.get("Locale"), icon: "language", route: "/locale", key: key++ }); //SET LOGIN subSub.push({ title: window.$gz.locale.get("SetLoginPassword"), icon: "key", route: "/changepw", key: key++ }); //NOTIFICATION SUBSCRIPTIONS subSub.push({ title: window.$gz.locale.get("NotifySubscriptionList"), icon: "bullhorn", route: "/notifysubscriptions", key: key++ }); //USER PREFERENCES (personal) sub.push({ title: window.$gz.locale.get("UserPreferences"), icon: "user-cog", route: undefined, navItems: subSub, key: key++ }); //HOME addNavItem( window.$gz.locale.get("Home"), "home", undefined, sub, key++ ); //****************** CUSTOMERS //clear sublevel arrays subSub = []; sub = []; //CUSTOMERS subitem sub.push({ title: window.$gz.locale.get("ClientList"), icon: "address-card", route: "/customers", key: key++ }); //HEAD OFFICES subitem sub.push({ title: window.$gz.locale.get("HeadOfficeList"), icon: "sitemap", route: "/headoffices", key: key++ }); // ** CUSTOMER (TOP) addNavItem( window.$gz.locale.get("ClientList"), "address-book", undefined, sub, key++ ); //****************** SERVICE //clear sublevel arrays subSub = []; sub = []; /** * * - WORKORDERS (was "service" in v7, now all "service" workorders are just workorders) - ALL LEVELS - NOTE: Either all levels still in menu at left here or somehow at right in separate boxes maybe, I like the idea of the in menu better with single right pane for simplicity - TEMPLATES - QUOTES - See "Workorders" above same layout - PREVENTIVE MAINTENANCE - See "Workorders" above same layout - UNITS - UNIT MODELS - CONTRACTS - CUSTOMER SERVICE REQUESTS - LOANERS (not 100% certain about this location for this item) - SCHEDULE (all users not just current one) */ //WORKORDERS GROUP SUBITEMS //WORKORDERS LIST (was service workorders) subSub.push({ title: window.$gz.locale.get("WorkorderServiceList"), icon: "tools", route: "/workorders", key: key++ }); //WORKORDER TEMPLATES LIST subSub.push({ title: window.$gz.locale.get("WorkorderServiceTemplate"), icon: "stamp", route: "/workordertemplates", key: key++ }); //WORKORDERS GROUP sub.push({ title: window.$gz.locale.get("WorkorderServiceList"), icon: "tools", route: undefined, navItems: subSub, key: key++ }); //QUOTE GROUP SUBITEMS subSub = []; //QUOTE LIST subSub.push({ title: window.$gz.locale.get("WorkorderQuoteList"), icon: "edit", route: "/quotes", key: key++ }); //QUOTE TEMPLATES LIST subSub.push({ title: window.$gz.locale.get("WorkorderQuoteTemplate"), icon: "stamp", route: "/quotetemplates", key: key++ }); //QUOTE GROUP sub.push({ title: window.$gz.locale.get("WorkorderQuoteList"), icon: "edit", route: undefined, navItems: subSub, key: key++ }); //PM GROUP SUBITEMS subSub = []; //PM LIST subSub.push({ title: window.$gz.locale.get("WorkorderPreventiveMaintenanceList"), icon: "business-time", route: "/pmlist", key: key++ }); //PM TEMPLATES LIST subSub.push({ title: window.$gz.locale.get( "WorkorderPreventiveMaintenanceTemplate" ), icon: "stamp", route: "/pmtemplates", key: key++ }); //PM GROUP sub.push({ title: window.$gz.locale.get("WorkorderPreventiveMaintenanceList"), icon: "business-time", route: undefined, navItems: subSub, key: key++ }); //UNITS subitem sub.push({ title: window.$gz.locale.get("UnitList"), icon: "fan", route: "/units", key: key++ }); //UNIT MODELS subitem sub.push({ title: window.$gz.locale.get("UnitModels"), icon: undefined, route: "/unitmodels", key: key++ }); //**** Service (TOP GROUP) addNavItem( window.$gz.locale.get("Service"), "toolbox", undefined, sub, key++ ); //NOTE: If a user has read full record or better then they should have access to that area // if ( // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.TechLimited // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.TechFull // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.SubContractorLimited // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.SubContractorFull // ) // ) { // addNavItem( // window.$gz.locale.get("Service"), // "toolbox", // "/service", // undefined, // key++ // ); // } // if ( // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.DispatchLimited // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.DispatchFull // ) // ) { // addNavItem( // window.$gz.locale.get("Dispatch"), // "shipping-fast", // "/dispatch", // undefined, // key++ // ); // } // if ( // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.InventoryLimited // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.InventoryFull // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.BizAdminLimited // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.BizAdminFull // ) // ) { // addNavItem( // window.$gz.locale.get("Inventory"), // "dolly", // "/inventory", // undefined, // key++ // ); // } // if ( // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.AccountingFull // ) // ) { // addNavItem( // window.$gz.locale.get("Accounting"), // "file-invoice-dollar", // "/accounting", // undefined, // key++ // ); // } // if ( // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.BizAdminLimited // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.BizAdminFull // ) // ) { // addNavItem( // window.$gz.locale.get("Administration"), // "user-tie", // "/admin", // undefined, // key++ // ); // } // if ( // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.OpsAdminFull // ) || // window.$gz.role.hasRole( // window.$gz.role.AUTHORIZATION_ROLES.OpsAdminLimited // ) // ) { // addNavItem( // window.$gz.locale.get("Operations"), // "cogs", // "ops", // undefined, // key++ // ); // } // console.log(window.$gz.store.state.navItems); }) .then(() => { //CACHE LOCALE SETTINGS window.$gz.api .get("UserOptions/" + window.$gz.store.state.userId) .then(res => { if (res.error != undefined) { //In a form this would trigger a bunch of validation or error display code but for here and now: //convert error to human readable string for display and popup a notification to user var msg = window.$gz.api.apiErrorToHumanString(res.error); window.$gz.store.commit( "logItem", "Initialize::() fetch useroptions -> error" + msg ); window.$gz.eventBus.$emit("notify-error", msg); } else { //TODO: also need the other locale settings such as number and date formats etc var localOffset = new Date().getTimezoneOffset(); if (localOffset != 0) { localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect } if (res.data.timeZoneOffset != localOffset) { //TODO: localize message and also actually have a fix for it here //so this should be a confirm prompt but for now will just show it //for now just show the message window.$gz.eventBus.$emit( "notify-info", "Time zone offset for your account is set to " + res.data.timeZoneOffset + " which doesn't match the local timezone offset of " + localOffset, window.$gz.store.state.helpUrl + "intro/#searching" ); } // window.$gz.eventBus.$emit("notify-success", "Success"); // window.$gz.eventBus.$emit( // "notify-warning", // "This is a very long warning, it has a lot of text and goes on and on and on. Hard to understand why anyone would do it this way but whatever right?@!" // ); // window.$gz.eventBus.$emit( // "notify-error", // "This is a medium error" // ); //Store offset in locale data //TODO: also need the other locale settings such as number and date formats etc to be added at server window.$gz.store.commit("setLocale", { decimalSeparator: ".", currencySymbol: "$", shortDate: "YYYY-MM-DD", shortTime: "hh:mm:ss A", shortDateAndTime: "YYYY-MM-DD hh:mm:ss A", timeZoneOffset: res.data.timeZoneOffset }); resolve(); } }) .catch(function handleFetchUserOptionsError(error) { window.$gz.store.commit( "logItem", "Initialize::() fetch useroptions -> error" + error ); throw error; }); }) .catch(function handleIntializeError(error) { window.$gz.store.commit( "logItem", "Initialize::() ltfetch -> error" + error ); throw error; }); } }); return promise; }