(function () { 'use strict'; var app = angular.module('app'); var shortcut = { // (A) SET SHORTCUT KEYS TO LISTEN TO listen: null, set: (listen) => { // (A1) KEY SEQUENCE + FUNCTION TO RUN shortcut.listen = listen; // (A2) KEY PRESS LISTENERS window.addEventListener("keydown", (evt) => { shortcut.track(evt.key.toLowerCase(), true); }); window.addEventListener("keyup", (evt) => { shortcut.track(evt.key.toLowerCase(), false); }); }, // (B) KEY PRESS SEQUENCE TRACKER sequence: [], track: (key, direction) => { // (B1) PREVENT AUTO CLEANING if (shortcut.junk != null) { clearTimeout(shortcut.junk); } // (B2) KEY DOWN if (direction) { if (!shortcut.sequence.includes(key)) { shortcut.sequence.push(key); } } // (B3) KEY UP else { let idx = shortcut.sequence.indexOf(key); if (idx != -1) { shortcut.sequence.splice(idx, 1); } } // (B4) HIT SHORTCUT? if (shortcut.sequence.length != 0) { let seq = shortcut.sequence.join("-"); if (shortcut.listen[seq]) { shortcut.sequence = []; shortcut.listen[seq](); } // (B5) PREVENT "STUCK SEQUENCE" WHEN USER LEAVES PAGE // E.G. OPEN NEW TAB WHILE IN MIDDLE OF KEY PRESS SEQUENCE else { shortcut.junk = setTimeout(shortcut.clean, 600) } } }, // (C) AUTO CLEANUP junk: null, clean: () => { shortcut.junk = null; shortcut.sequence = []; } }; document.onkeydown = function (e) {//remove this function if you dont want to block default action // normalize event e = e || window.event; // detecting multiple keys, e.g: Ctrl + shift + k and block default action (in edge it duplicates tab) if (e.ctrlKey && !e.altKey && e.shiftKey && e.keyCode === 75) {//75 means k [*] // prevent default action if (e.preventDefault) { e.preventDefault(); } // IE e.returnValue = false; } }; // The controller for the shell app.controller('shell', ['$rootScope', '$location', '$interval', 'layoutService', 'config', 'branding', 'zendeskService', '$window', 'fullScreenLoaderContext', 'userModals', function ($rootScope, $location, $interval, layoutService, config, branding, zendeskService, $window, fsl, userModals) { var $ctrl = this; $ctrl.sharedShellTemplate = modulesSharedResourcesUrl + 'Layout/Views/shell.html'; shortcut.set({ "shift-l": () => { $rootScope.siteOverride = true; $rootScope.$apply() } }); // The currently authenticated user $ctrl.user = null; // Data for the current user $ctrl.userData = { notifications: [], currentRole: null, availableRoles: [], isApprenticeshipUser: false, enableTrainingRecords: config.enableTrainingRecords, enableCalendar: config.enableCalendar }; $ctrl.branding = branding; $ctrl.config = config; $ctrl.appLoaded = false; $ctrl.noAuthUrls = config.noAuthUrls; $ctrl.currentPath = $location.$$path; $rootScope.$on('$routeChangeStart', function (event, next, current) { if (next.$$route) { $ctrl.currentPath = $location.$$path; } }); // Sidebar visibility $ctrl.sidebar = { left: $window.innerWidth > 1240 && !isTouchDevice(), mobile: false } $ctrl.toggleLeftSideBar = function () { $ctrl.sidebar.left = !$ctrl.sidebar.left; $ctrl.sidebar.mobile = layoutService.isMobile() ? !$ctrl.sidebar.mobile : false; }; // Display the scrolltop button when the user scrolls down $ctrl.checkScrollHeight = function () { return (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) ? "block" : "none"; }; // Scroll to the top of the page $ctrl.scrollToTop = function () { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; $ctrl.focusFirstElement(); }; // Set the app to loaded, hiding the full screen loader $ctrl.loaded = function () { fsl.hide(); $rootScope.appLoaded = true; } // Activate the full screen loader $ctrl.activate = function () { if ($ctrl.showNavigation) { $rootScope.fsl = true; fsl.show('Loading application'); } $interval(function () { $rootScope.$broadcast('refreshRoleToken'); }, 3600000); } // Checks that the current user is verified, and that the reset password flags // are not set, opening modals if either of these conditions fail $ctrl.checkUserIsVerified = function (user) { $rootScope.verifiedEmails = user.emailAddresses.reduce(function (verifiedEmails, email) { if (email.verified) { verifiedEmails.push(email.email); } return verifiedEmails; }, []); if ($rootScope.verifiedEmails.length == 0) { userModals.verifyEmail(user); } if (isForgottenPassword || isSetPassword) { userModals.resetPassword(); } } // Check if a sidebar route link should be highlighted based on // the path, and any additional links $ctrl.highlightRoute = function (path, additionalLinks) { return $location.path() === path || ( additionalLinks && additionalLinks.indexOf($location.path()) > -1 ); } // Check if a sidebar route link should be highlighted based on // its sub routes $ctrl.highlightSubRoute = function (nestedLinks) { return nestedLinks.some(function (nestedLink) { return $ctrl.highlightRoute(nestedLink.route); }) } // Find and focus the first main element $ctrl.focusFirstElement = function () { $("#main-content").focus(); } // Check if this device supports touch function isTouchDevice() { var el = document.createElement('div'); el.setAttribute('ongesturestart', 'return;'); // or try "ontouchstart" return typeof el.ongesturestart === "function"; } zendeskService.loadWidget(); } ]); // The controller for the navigation shell app.controller('appNavController', ['$scope', '$modal', 'tenantService', function ($scope, $modal, tenantService) { var $ctrl = this; var shell = $scope.shell; // The currently open sub menu $ctrl.openSubMenu = ''; // Toggle the currently open sidebar menu $ctrl.toggleSubMenu = function (menu) { $ctrl.openSubMenu = $ctrl.openSubMenu != menu ? menu : ''; } // Toggle the currently open sidebar menu $ctrl.showHelpText = function (helpData) { $modal.open({ templateUrl: modulesSharedResourcesUrl + 'Layout/Views/help-text.html', controller: getHelpTextController, size: 'lg', backdrop: 'static', resolve: { helpData: function () { return helpData; } } }); } var getHelpTextController = function ($scope, $modalInstance, helpData) { $scope.helpLoaded = false; $scope.functionName = helpData.functionName; if (helpData.functionId != null) tenantService.getSpecificRoleFunctionHelpText( helpData.roleId, helpData.functionId, helpData.topLevelOrgId) .then(function (data) { if (data != null && data[0] != null) $scope.helpText = data[0].value; $scope.helpLoaded = true; }); //close the modal $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; } // Toggle the left sidebar $ctrl.toggleSidebar = function () { shell.toggleLeftSideBar(); $ctrl.toggleUserSettings(true); } // Toggle the user settings menu $ctrl.toggleUserSettings = function (hide) { if (!hide) { shell.sidebar.mobile = false; } $ctrl.showMenu = hide ? false : !$ctrl.showMenu; $("body").css({ overflowY: $ctrl.showMenu ? "hidden" : "visible" }); } // Jump to content by finding the first focusable element with a visible child $ctrl.jumpToContent = function () { $ctrl.toggleUserSettings(true); shell.focusFirstElement(); } }]); })();