(function () { 'use strict'; var app = angular.module('app', [ // Angular modules 'ngAnimate', // animations 'ngRoute', // routing 'ngSanitize', // sanitizes html bindings (ex: sidebar.js) // Custom modules 'common', // common functions, logger 'common.bootstrap', // bootstrap dialog wrapper functions // 3rd Party Modules // Breeze Modules 'breeze.angular', // Breeze service 'breeze.directives', // Breeze validation directive (zValidate) 'ui.bootstrap', // ui-bootstrap (ex: carousel, pagination, dialog) 'LocalStorageModule', 'textAngular', //rich text editor 'ui.bootstrap.modal', //bootstrap modal 'angularFileUpload', //helps with file upload 'SignalR', //push notifications 'angular-data.DSCacheFactory', //better caching functionality 'ngTagsInput', 'organisations', //organisation module 'usefulstuff', //general stuff 'user-group', //group module 'angulartics', //web analytics 'angulartics.google.analytics', //web analytics google 'myusers', 'reportingModule', 'ngTouch', 'rolesAdmin', 'mybadgesAdmin', 'angular.chosen', 'ui.bootstrap-slider', 'infinite-scroll', 'colorpicker.module', 'chart.js', 'countrySelect', 'MKM.HelpCentre', 'OrganisationAdmin', 'branding', 'issuers', 'emailTemplates', 'payments', 'fullScreenLoader', 'ngClickCopy', 'badgesDashboard', 'userSettings', 'usersAdmin', 'angularMoment', 'organisationManager', 'licencing', 'licencingAdmin', 'rulesAdmin', 'developerKey', 'subscriptions', 'addthis', 'daterangepicker', 'ui.ace', 'claims', 'switcher' ]); app.filter('positive', function() { return function(input) { if (!input) return 0; return Math.abs(input); }; }); // Handle routing errors and success events app.run(['Hub', '$route', 'userAuth', 'config', '$location', '$templateCache', 'auth', 'datacontext', '$rootScope', 'notifier', '$window', function (Hub, $route, userAuth, config, $location, $templateCache, authService, datacontext, $rootScope, notifier, $window) { // Include $route to kick start the router. var pairs = $location.url().slice(1).split('&'); var result = {}; pairs.forEach(function (pair) { pair = pair.split('='); result[pair[0]] = decodeURIComponent(pair[1] || ''); }); authService.setAccessToken(JSON.parse(JSON.stringify(result))); var auth = authService.fillAuthData(); //start signalr notifications //notifier.start(); var connection = $.hubConnection(config.mybadgesRootUrl); var UserConnection = $.hubConnection(config.myusersUrl); if (userAuth) { var tokenData = userAuth.getAuthToken(); if (tokenData != null) { //Add bearer token to request connection.qs = { bearer: tokenData.access_token }; UserConnection.qs = { bearer: tokenData.access_token }; var mybadgesProxy = connection.createHubProxy('mybadgesnotifier'); var userConnectionsProxy = UserConnection.createHubProxy('connectionsnotifier'); UserConnection.client = function () { }; mybadgesProxy.on('badgeIssuingFinished', function (createdBy, issuedBadgeId, badgeTemplateId, status) { $rootScope.$broadcast('BadgeIssuingFinished', { issuedBadgeId: issuedBadgeId }); $rootScope.$broadcast('createClientOnlyNotification', { description: "Badge", notificationType: "badgeIssued", id: badgeTemplateId, progress: true, status: status } ); }); userConnectionsProxy.on('emailVerified', function (userId) { $window.location.reload(); }); userConnectionsProxy.on('canvasFetchStarted', function (userId) { $rootScope.$broadcast('createClientOnlyNotification', { description: "Fetching data from canvas", notificationType: "syncStarted", progress: true } ); }); connection.start().done(function () { console.debug('connected a user to mybadges'); }); UserConnection.start().done(function () { console.debug('connected a user to myusers'); }); } } }]).run(function ($rootScope, $location, $templateCache, config, features) { //Insert in the function definition the dependencies you need. //Do your $on in here, like this: $rootScope.$on("$routeChangeStart", function (event, next, current) { if (next.$$route && next.$$route.settings && next.$$route.settings.content) { $('html head title').text(config.docTitle + next.$$route.settings.content); $('#ogtitle').attr('content', config.docTitle + next.$$route.settings.content); $('#ogurl').attr('content', window.location.href.toString()); window.scrollTo(0, 0); } if ($rootScope.lockRouter && next.$$route !== '/backpack' && next.$$route !== '/dashboard' && next.$$route !== '/') { event.preventDefault(); } if (next.$$route && next.$$route.settings && next.$$route.settings.auth === 1 && !config.authenticated) { event.preventDefault(); $location.path(config.loginRoute); } features.getCurrentFeatures().then(function (currentFeatures) { if (next.$$route) { var hasAccess = true; var route = next.$$route.originalPath; if (route) { // Check features if (route.includes('/organisations') && currentFeatures.indexOf('OA') == -1) hasAccess = false; if (route.includes('/rules') && currentFeatures.indexOf('ARA') == -1) hasAccess = false; if (route.includes('/roles') && currentFeatures.indexOf('CR') == -1) hasAccess = false; if (route.includes('/landing') && currentFeatures.indexOf('BD') == -1) hasAccess = false; if (route.includes('/branding') && currentFeatures.indexOf('BRA') == -1) hasAccess = false; if (route.includes('/reporting/summary') && currentFeatures.indexOf('BR') == -1) hasAccess = false; if (route.includes('/reporting/detail') && currentFeatures.indexOf('ABR') == -1) hasAccess = false; if (route.includes('/reporting/recipients') && currentFeatures.indexOf('ABR') == -1) hasAccess = false; if (route.includes('/reporting/social') && currentFeatures.indexOf('SMCT') == -1) hasAccess = false; if (route.includes('/templates') && currentFeatures.indexOf('ET') == -1) hasAccess = false; if (route.includes('/issue') && currentFeatures.indexOf('BI') == -1) hasAccess = false; if (route.includes('/key') && currentFeatures.indexOf('DA') == -1) hasAccess = false; if (route.includes('/users') && currentFeatures.indexOf('MA') == -1) hasAccess = false; // Check roles if ($rootScope.currentRole) { if (route.includes('/issuers') && $rootScope.currentRole.functions.indexOf('badges_issuer_access') == -1) hasAccess = false; if (route.includes('/graphics') && $rootScope.currentRole.functions.indexOf('badges_graphics_access') == -1) hasAccess = false; if (route.includes('/badges') && $rootScope.currentRole.functions.indexOf('badges_badges_access') == -1) hasAccess = false; if (route.includes('/issue') && $rootScope.currentRole.functions.indexOf('badges_issue_access') == -1) hasAccess = false; if (route.includes('/rules') && $rootScope.currentRole.functions.indexOf('badges_issue_access') == -1) hasAccess = false; if (route.includes('/key') && $rootScope.currentRole.functions.indexOf('badges_issue_access') == -1) hasAccess = false; if ((route.includes('/claims') && !route.includes('/claims/review')) && $rootScope.currentRole.functions.indexOf('badges_claimscreate_access') == -1) hasAccess = false; if (route.includes('/claims/review') && $rootScope.currentRole.functions.indexOf('badges_claimsreview_access') == -1) hasAccess = false; if (route.includes('/organisations') && $rootScope.currentRole.functions.indexOf('manage_organisations') == -1) hasAccess = false; if (route.includes('/reporting') && $rootScope.currentRole.functions.indexOf('access_badge_reporting') == -1) hasAccess = false; if (route.includes('/users') && $rootScope.currentRole.functions.indexOf('manage_users') == -1) hasAccess = false; if (route.includes('/branding') && $rootScope.currentRole.name != 'SystemAdministrator') hasAccess = false; if (route.includes('/landing') && $rootScope.currentRole.name != 'SystemAdministrator') hasAccess = false; if (route.includes('/templates') && $rootScope.currentRole.name != 'SystemAdministrator') hasAccess = false; if (route.includes('/roles') && $rootScope.currentRole.name != 'SystemAdministrator') hasAccess = false; if (route.includes('/subscription') && $rootScope.currentRole.name != 'SystemAdministrator') hasAccess = false; } if (!hasAccess) { event.preventDefault(); if (current) { if ($rootScope.currentRole.name === 'SystemAdministrator') { $location.path('/premiumfeature'); } else { $location.path(current.$$route.originalPath); } } } } } }); }); $rootScope.$on('$routeChangeStart', function (event, next, current) { if (typeof (current) !== 'undefined') { $templateCache.remove(current.templateUrl); } }); }); })();