(function () { 'use strict'; var app = angular.module('branding'); var templatePath = modulesSharedResourcesUrl + 'Modules/BrandingV2/Views/'; app.directive('branding', ['config', 'brandingDataContext', 'brandingService', 'virusScanModalService', 'common', '$rootScope', 'OrganisationAdminService', '$window', 'user', function (config, brandingDataContext, brandingService, virusScanModalService, common, $rootScope, OrganisationAdminService, $window, user) { return { restrict: 'E', templateUrl: templatePath + 'branding.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('branding'); var logSuccess = getLogFn('branding', "success"); var logError = getLogFn('branding', "error"); $scope.branding = {}; $scope.individualRegisterUrl = config.individualRegisterUrl; activate(); function activate() { NProgress.done(); log('Activated Branding View'); } $scope.isSaving = false; OrganisationAdminService.getTopLevelOrg().then(function (org) { $scope.topLevelOrg = org; $scope.branding.organisationId = org.id; getProfile(); }); function getProfile() { user.getProfile().then(function (theUser) { $scope.user = theUser; getBranding(); }); } function getBranding() { if (config.appCode == "CUPPA") { var org = $rootScope.currentRole.organisationId; console.log("rootscopeorg:" + org) return brandingDataContext.getBranding(org).then(function (data) { if (data.length > 0) { $scope.branding = data[0]; $scope.brandingLoaded = true; } else { return brandingDataContext.getBranding($scope.topLevelOrg.id).then(function (data) { if (data.length > 0) { $scope.branding = data[0]; $scope.brandingLoaded = true; } else { $scope.branding = brandingService.createBlankBranding(); } }); } }); } else { return brandingDataContext.getBranding($scope.topLevelOrg.id).then(function (data) { if (data.length > 0) { $scope.branding = data.reduce(function (obj, item) { obj[item['Key'] ? item['Key'] : item['key']] = item.Value ? item.Value : item.value return obj }, {}); } else { $scope.branding = brandingService.createBlankBranding(); } }); } }; $scope.saveBranding = function (integration) { $scope.isSaving = true; if (config.appCode === "CUPPA") { $scope.branding.organisationId = $rootScope.currentRole.organisationId; } else { $scope.branding.organisationId = $scope.topLevelOrg.id; } save(); } $scope.resetBranding = function () { $scope.branding = brandingService.createBlankBranding(); } $scope.resetLogo = function () { $scope.branding.logoUrl = null; $scope.fileName = ""; }; $scope.resetIcon = function () { $scope.branding.iconUrl = null; $scope.fileName = ""; }; function save() { brandingDataContext.createBranding($scope.branding).then(function (data) { logSuccess("Branding updated."); logSuccess("Please note, if you have updated colours the email templates will need to be updated to reflect this change."); $scope.isSaving = false; $window.location.reload(); }).catch(function (errorData) { if (errorData === "Virus scan positive.") { virusScanModalService.virusModal(); } else { logError("An error occured saving the item."); } $scope.isSaving = false; }); }; $scope.onOrgLogoFileSelect = function (files) { $scope.branding.logoUrl = null; $scope.logoErrorMessage == ''; $scope.logoPreview = null; $scope.logofile = files[0]; // we're not interested in multiple file uploads here if ($scope.logofile.type !== 'image/jpeg' && $scope.logofile.type !== 'image/png' && $scope.logofile.type !== 'image/gif' && $scope.logofile.type !== 'image/svg+xml') { $scope.logoErrorMessage = "Please upload a valid image file. jpeg, png, svg or gif."; $scope.branding.logoUrl = null; return; } // check if the user has selected an image below our maximum file size of 20MB if ($scope.logofile.size > 20000000) { $scope.branding.logoUrl = null; $scope.logoErrorMessage == 'Image is too large. Please ensure size is less than 20MB.'; return; } var reader = new FileReader(); reader.onload = function (e) { $scope.$apply(function () { // get loaded data and render preview. $scope.logoPreview = e.target.result; $scope.branding.logoFileAsBase64 = reader.result; }); }; // Generate base 64 image for preview reader.readAsDataURL($scope.logofile); $scope.fileName = $scope.topLevelOrg.id + '-logo'; $scope.logofile.fileName = $scope.topLevelOrg.id + '-logo'; $scope.logofile.originalImageFileName = $scope.topLevelOrg.id + '-logo'; $scope.logofile.imageFileSize = $scope.logofile.size; $scope.logofile.imageFileType = $scope.logofile.type; } $scope.onOrgIconFileSelect = function (files) { $scope.branding.iconUrl = null; $scope.iconPreview = null; $scope.iconErrorMessage == ''; $scope.iconfile = files[0]; // we're not interested in multiple file uploads here if ($scope.iconfile.type !== 'image/jpeg' && $scope.iconfile.type !== 'image/png' && $scope.iconfile.type !== 'image/gif' && $scope.iconfile.type !== 'image/svg+xml') { $scope.iconErrorMessage = "Please upload a valid image file. jpeg, png, svg or gif."; $scope.branding.iconUrl = null; return; } // check if the user has selected an image below our maximum file size of 20MB if ($scope.iconfile.size > 20000000) { $scope.branding.iconUrl = null; $scope.iconErrorMessage == 'Image is too large. Please ensure size is less than 20MB.'; return; } var reader = new FileReader(); reader.onload = function (e) { $scope.$apply(function () { // get loaded data and render preview. $scope.iconPreview = e.target.result; $scope.branding.iconFileAsBase64 = reader.result; }); }; // Generate base 64 image for preview reader.readAsDataURL($scope.iconfile); $scope.fileName = $scope.topLevelOrg.id + '-icon'; $scope.iconfile.fileName = $scope.topLevelOrg.id + '-icon'; $scope.iconfile.originalImageFileName = $scope.topLevelOrg.id + '-icon'; $scope.iconfile.imageFileSize = $scope.iconfile.size; $scope.iconfile.imageFileType = $scope.iconfile.type; } } }]); app.directive('landingPage', ['config', 'brandingDataContext', 'brandingService', 'virusScanModalService', 'common', '$location', '$modal', '$rootScope', '$q', '$upload', 'OrganisationAdminService', 'fileUpload', '$timeout', '$window', function (config, brandingDataContext, brandingService, virusScanModalService, common, $location, $modal, $rootScope, $q, $upload, OrganisationAdminService, fileUpload, $timeout, $window) { return { restrict: 'E', templateUrl: templatePath + 'landingpage.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('branding'); var logSuccess = getLogFn('branding', "success"); $scope.branding = {}; $scope.domain = config.sysDomain; activate(); function activate() { NProgress.done(); log('Activated Badges View'); } $scope.isSaving = false; OrganisationAdminService.getTopLevelOrg().then(function (org) { $scope.topLevelOrg = org; console.log(org); $scope.subDomain = org.subDomain; $scope.originalSubDomain = angular.copy($scope.subDomain); $scope.branding.organisationId = org.id; getBranding(); }); function getBranding() { return brandingDataContext.getBranding($scope.topLevelOrg.id).then(function (data) { if (data.length > 0) { $scope.branding = data.reduce(function (obj, item) { obj[item['Key'] ? item['Key'] : item['key']] = item.Value ? item.Value : item.value return obj }, {}); } else { $scope.branding = brandingService.createBlankBranding(); } $scope.brandingLoaded = true; }); }; $scope.getCurrentBackground = function () { if ($scope.branding.backgroundUrl) { return { 'background-image': 'url(\'' + $scope.branding.backgroundUrl + '\')' }; } if ($scope.backgroundPreview) { return { 'background-image': 'url(' + $scope.backgroundPreview + ')' }; } if (!$scope.branding.backgroundColour) { return { 'background-image': 'url(\'img/bg-img/bg-img-3.jpg\')' }; } if ($scope.branding.backgroundColour) { return { 'background-color': $scope.branding.backgroundColour }; } } $scope.saveBranding = function (integration) { $scope.isSaving = true; $scope.branding.organisationId = $scope.topLevelOrg.id; save($scope.branding); } $scope.resetLanding = function () { $scope.subDomain = null; $scope.branding.systemEmailAddress = ''; $scope.branding.systemName = ''; $scope.branding.backgroundUrl = null; $scope.branding.backgroundColour = null; } $scope.resetBackground = function () { $scope.branding.backgroundUrl = null; $scope.backgroundPreview = null; $scope.fileName = ""; }; function save(branding) { $scope.topLevelOrg.subDomain = $scope.subDomain; var sub = config.sysDomain; $scope.topLevelOrg.brandingUrl = "https://" + $scope.subDomain + "." + sub; OrganisationAdminService.updateOrganisation($scope.topLevelOrg).then(function (org) { logSuccess("Organisation updated."); $scope.originalSubDomain = angular.copy($scope.subDomain); }); brandingDataContext.createBranding($scope.branding).then(function (data) { logSuccess("Landing page updated."); $scope.isSaving = false; }).catch(function (errorData) { if (errorData === "Virus scan positive.") { virusScanModalService.virusModal(); } else { logError("An error occured saving the item."); } $scope.isSaving = false; }); }; $scope.onOrgBackgroundFileSelect = function (files) { $scope.branding.backgroundUrl = null; $scope.backgroundPreview = null; $scope.backgroundErrorMessage == ''; if (!files[0]) { $scope.$apply(); return; } $scope.file = files[0]; // we're not interested in multiple file uploads here if ($scope.file.type !== 'image/jpeg' && $scope.file.type !== 'image/png' && $scope.file.type !== 'image/gif') { $scope.backgroundErrorMessage = "Please upload a valid image file. jpeg, png or gif."; $scope.branding.backgroundUrl = null; return; } // check if the user has selected an image below our maximum file size of 20MB if ($scope.file.size > 20000000) { $scope.branding.backgroundUrl = null; $scope.backgroundErrorMessage == 'Image is too large. Please ensure size is less than 20MB.'; return; } var filename = $scope.file.name.replace(/ /g, ''); $scope.fileName = filename; $scope.file.fileName = filename; $scope.file.originalImageFileName = filename; $scope.file.imageFileSize = $scope.file.size; $scope.file.imageFileType = $scope.file.type; var reader = new FileReader(); reader.onload = function (e) { // Assign loaded data to preview and DTO. $scope.backgroundPreview = e.target.result; $scope.branding.backgroundFileAsBase64 = reader.result; $scope.$apply(); }; // Generate base 64 image for preview reader.readAsDataURL($scope.file); } $scope.doesSubDomainExist = function (subDomain) { if ($scope.originalSubDomain !== $scope.subDomain) { OrganisationAdminService.doesSubDomainExist(subDomain).then(function (data) { if (data == "Exists" && subDomain != $scope.originalSubDomain || $scope.subDomain == 'app') { $scope.showSubDomainExists = true; return; } else { $scope.showSubDomainExists = false; return; } }); } if ($scope.subDomain == 'app') { $scope.showSubDomainExists = true; return; } $scope.showSubDomainExists = false; return; } } }]); app.directive('terminology', ['config', 'brandingDataContext', 'brandingService', 'common', '$location', '$modal', '$rootScope', '$q', '$upload', 'OrganisationAdminService', 'fileUpload', '$timeout', '$window', function (config, brandingDataContext, brandingService, common, $location, $modal, $rootScope, $q, $upload, OrganisationAdminService, fileUpload, $timeout, $window) { return { restrict: 'E', templateUrl: templatePath + 'terminology.html', link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('branding'); var logSuccess = getLogFn('branding', "success"); $scope.defaultTerminology = brandingService.createBlankTerminology(); $scope.terminology = {}; $scope.isSaving = false; OrganisationAdminService.getTopLevelOrg().then(function (org) { $scope.topLevelOrg = org; getTerminology(); }); function getTerminology() { brandingDataContext.getTerminology($scope.topLevelOrg.id).then(function (data) { if (data.length > 0) { $scope.terminology = data.reduce(function (obj, item) { obj[item['Key'] ? item['Key'] : item['key']] = item.Value ? item.Value : item.value return obj }, {}); } else { $scope.terminology = brandingService.createBlankTerminology(); } }); }; $scope.saveTerminology = function () { $scope.isSaving = true; save($scope.terminology); } $scope.resetTerminology= function () { $scope.terminology = brandingService.createBlankTerminology(); } function save(branding) { brandingDataContext.createTerminology($scope.terminology, $scope.topLevelOrg.id).then(function (data) { logSuccess("Terminolgy updated."); $scope.isSaving = false; $window.location.reload(); }); }; } }]); })();