(function () { 'use strict'; var app = angular.module('app'); // 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'; // 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") .find('button, a, input, select, textarea, [tabindex]:not([tabindex="-1"])') .find(' > :visible') .eq(0).parent().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(); } }]); })();