(function () { 'use strict'; //configure the MyShowcase app var app = angular.module('app'); //the main module of the app called 'app' // Configure Toastr toastr.options.timeOut = 4000; toastr.options.positionClass = 'toast-bottom-right'; var events = { controllerStartActivate: 'controller.startActivate', controllerActivateSuccess: 'controller.activateSuccess', loginSuccess: 'auth.success', logoutSuccess: 'auth.logout' }; //mamny of these config values are set in index.html var config = { appErrorPrefix: '[Error] ', //Configure the exceptionHandler decorator docTitle: productName + ' > ', events: events, frameworkRemoteServiceName: frameworkOdataServiceName, //points to the JustFrameworks oData endpoint version: '1.0.0', //version of myshowcase userRemoteServiceUrl: userRemoteServiceUrl, //user REST service endpoint usersRemoteServiceUrl: usersRemoteServiceUrl, //users REST service endpoint myusersUrl:myusersUrl, //MyUsers REST service endpoint groupRemoteServiceUrl: groupRemoteServiceUrl,//groups REST service endpoint competencyRemoteServiceUrl: competencyRemoteServiceUrl,//competency REST service endpoint notificationsRemoteServiceUrl: notificationsRemoteServiceUrl,//notifications REST service endpoint alternativeEmailServiceUrl: alternativeEmailServiceUrl,//alternative emails REST service endpoint cloudinaryName: cloudinaryName, //the name of the Clouinary account used to store images cloudinaryUploadPreset: cloudinaryUploadPreset,//The Cloudinary account upload preset that allows the client to directly upload images to Cloudinary noAuthUrls: noAuthUrls, //a list of urls where requests should not have authentication applied cloudinaryApiBaseUrl: cloudinaryApiBaseUrl, //the base REST API url for Cloudinary cloudinaryBaseUrl: cloudinaryBaseUrl, //the base url for for cloudinary images cloudinaryUploadPath: cloudinaryUploadPath, //the path to upload images for items to on Cloudinary cloudinaryAvatarUploadPath: cloudinaryAvatarUploadPath, //the path to upload avatar images to on Cloudinary authenticated: false, //default authentication level accessLevel: 0, applicationId: applicationId, //application ID of MyShowcase within MyUsers productVersion: productVersion, realm: myusersUrl, //pointer the the MyUsers endpoint firstName: "", lastName: "", email: "", userId: "", orgAdmin: "", systemAdmin: "", uploadBucketName: brandingBucketName, brandingBucketName: brandingBucketName, azureBlobUrl: azureBlobUrl, loginRoute: loginRoute, //the angular route used to siginin organisationTypeId: organisationTypeId, groupTypeId: groupTypeId, orgRemoteServiceUrl: orgRemoteServiceUrl, orgAdminRemoteServiceUrl: orgAdminRemoteServiceUrl, modulesSharedResourcesUrl: modulesSharedResourcesUrl, mybadgesUrl: mybadgesUrl, mybadgesRootUrl: mybadgesRootUrl, instanceCode: instanceCode, registerUrl: registerUrl, individualRegisterUrl: individualRegisterUrl, roleTokenExpiry: roleTokenExpiry, appCode: appCode, stripePublicKey: stripePublicKey, paymentsRemoteServiceUrl: paymentsRemoteServiceUrl, adminRoles: adminRoles, userRoles: userRoles, adminAppCodes: adminAppCodes, userAppCodes: userAppCodes, myShowcaseSiteUrl: myShowcaseSiteUrl, sysDomain: sysDomain, noOrgId: noOrgId, userProfileServiceUrl: userProfileServiceUrl, sysUrl: sysUrl, mybadgesSecretKey: mybadgesSecretKey, tenantUrl: tenantUrl, zendeskHost: zendeskHost }; // default branding config var branding = { systemName: systemName, systemEmailAddress: systemEmailAddress, primaryColour: primaryColour, secondaryColour: secondaryColour, backgroundColour: backgroundColour, textColour: textColour, fontColour: fontColour, logoUrl: logoUrl, iconUrl: iconUrl, backgroundUrl: backgroundUrl, headerStyle: headerStyle, isDefault: true }; // default terminology var terminology = { organisation: 'organisation', organisationPlural: 'organisations', group: 'group', groupPlural: 'groups', user: 'user', userPlural: 'users', role: 'role', rolePlural: 'roles', }; function mapConfigs(values, config) { for (var i = 0; i < values.length; i++) { config[values[i].Key] = values[i].Value; if (values[i].Key === 'systemName' && values[i].Value) config.docTitle = values[i].Value + ' >'; } config.isDefault = false; return config; } app.run(['$rootScope', 'config', 'branding', '$location', 'tenantService', 'OrganisationAdminService', function ($rootScope, config, branding, $location, tenantService, OrganisationAdminService) { var host = $location.$$host; $rootScope.shellTemplate = modulesSharedResourcesUrl + 'Templates/shell.html'; tenantService.getUISettings(host).then(function (settings) { // Set the required settings app.value('config', mapConfigs(settings, config)); app.value('branding', mapConfigs(settings, branding)); $rootScope.branding = mapConfigs(settings, branding); $rootScope.appLoaded = true; }).catch(function () { OrganisationAdminService.getTopLevelOrg(true).then(function (org) { if (org) { tenantService.getOrgUISettings(org.id).then(function (settings) { // Set the required settings app.value('config', mapConfigs(settings, config)); app.value('branding', mapConfigs(settings, branding)); $rootScope.branding = mapConfigs(settings, branding); $rootScope.appLoaded = true; }).catch(function () { console.log('Loaded default config'); $rootScope.appLoaded = true; }); } else { console.log('Loaded default config'); $rootScope.appLoaded = true; } }).catch(function () { console.log('Loaded default config'); $rootScope.appLoaded = true; }) }).catch(function () { console.log('Loaded default config'); $rootScope.appLoaded = true; }); }]); app.value('config', config); app.value('branding', branding); app.value('terminology', terminology); //setup a log provider for the app app.config(['$logProvider', function ($logProvider) { // turn debugging off/on (no info or warn) if ($logProvider.debugEnabled) $logProvider.debugEnabled(true); }]); //set hashbang for the location service app.config(['$locationProvider', function ($locationProvider) { $locationProvider.html5Mode(false); $locationProvider.hashPrefix("!"); }]); //#region Configure the common services via commonConfig app.config(['commonConfigProvider', function (cfg) { cfg.config.controllerActivateSuccessEvent = config.events.controllerActivateSuccess; cfg.config.loginSuccessEvent = config.events.loginSuccess; cfg.config.logoutSuccessEvent = config.events.logoutSuccess; }]); //configure the http provider - add some bespoke interceptors app.config(function ($httpProvider) { $httpProvider.interceptors.push('authInterceptorService'); //add auth token to each request $httpProvider.interceptors.push('noCacheInterceptorService'); //add a unique query param to each request - prevents caching in IE }); app.config(function ($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist([ // Allow same origin resource loads. 'self', // Allow loading from our assets domain. Notice the difference between * and **. 'https://myshowcase.mkmapps.local/**', 'https://app.myshowcase.me/**', 'https://testing-new.myshowcase.me/**', 'https://dev.myshowcase.me/**', 'https://mybadgesresources.mkmapps.local/**', 'https://mybadgesresources-dev.mkmapps.com/**', 'https://mybadgesresources-testing.mkmapps.com/**', 'https://mybadgesresources.mkmapps.com/**', 'https://ben-openbadges.devserver.mkmapps.com/**', 'https://ben-mybadgesresources.devserver.mkmapps.com/**', 'https://ben-myshowcase.devserver.mkmapps.com/**', 'https://mymodules.mkmapps.local/**', 'https://modules.blob.core.windows.net/**', 'https://mymodules.azureedge.net/**', 'https://ben-mymodules.devserver.mkmapps.com/**', ]); }); String.prototype.toUpperCaseFirstChar = function () { return this.substr(0, 1).toUpperCase() + this.substr(1); } String.prototype.toLowerCaseFirstChar = function () { return this.substr(0, 1).toLowerCase() + this.substr(1); } String.prototype.toUpperCaseEachWord = function (delim) { delim = delim ? delim : ' '; return this.split(delim).map(function (v) { return v.toUpperCaseFirstChar() }).join(delim); } String.prototype.toLowerCaseEachWord = function (delim) { delim = delim ? delim : ' '; return this.split(delim).map(function (v) { return v.toLowerCaseFirstChar() }).join(delim); } })();