(function () { 'use strict'; var app = angular.module('emailTemplates'); var templatePath = modulesSharedResourcesUrl + 'Modules/EmailTemplates/Views/'; app.directive('templatesList', ['config', 'emailTemplatesDataContext', 'emailTemplatesService', 'common', '$location', '$modal', '$q', '$upload', 'OrganisationAdminService', function (config, emailTemplatesDataContext, emailTemplatesService, common, $location, $modal, $q, $upload, OrganisationAdminService) { return { restrict: 'E', templateUrl: templatePath + 'templates.html', scope: { hideTitle: '=', }, link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('emailTemplates'); var logSuccess = getLogFn('emailTemplates', "success"); $scope.orderByPredicate = 'name'; activate(); $scope.templatesLoaded = false; function activate() { NProgress.done(); log('Activated Badges View'); } OrganisationAdminService.getTopLevelOrg().then(function (org) { $scope.topLevelOrg = org; getEmailTemplates(); }); function getEmailTemplates() { return emailTemplatesDataContext.getEmailTemplates($scope.topLevelOrg.id, config.appCode).then(function (data) { if (data.length == 0) { createTemplates(); $scope.templatesLoaded = false; } else { $scope.emailTemplates = data; $scope.templatesLoaded = true; } }); }; function createTemplates() { return createDefaultTemplates().then(function () { console.log("done"); getEmailTemplates(); }); }; $scope.manageTemplate = function (template) { if (template) { emailTemplatesService.setTemplate(template); } else { template = emailTemplatesService.createTemplate(); emailTemplatesService.setTemplate(template); } $location.path('/templates/manage'); } $scope.deleteEmailTemplate = function (id) { $scope.isSaving = true; deleteTemplate(id); } function deleteTemplate(id) { return emailTemplatesDataContext.deleteEmailTemplate(id).then(function (data) { logSuccess("Email Template removed."); $scope.isSaving = false; getEmailTemplates(); }); }; function createDefaultTemplates() { //get a bearer token from the myusers endpoint if (config.appCode === 'CUPPA') { var welc = getDefaultCuppaWelcome(); welc.systemShortCode = config.appCode; welc.organisationId = $scope.topLevelOrg.id; return emailTemplatesDataContext.createEmailTemplate(welc); } else { var wel = getDefaultWelcome(); wel.systemShortCode = config.appCode; wel.organisationId = $scope.topLevelOrg.id; var iss = getDefaultIssuing(); iss.systemShortCode = config.appCode; iss.organisationId = $scope.topLevelOrg.id; return emailTemplatesDataContext.createEmailTemplate(wel).then(emailTemplatesDataContext.createEmailTemplate(iss)); } } function getDefaultIssuing() { if (config.appCode == 'OB') { return { name: 'Badge Issued', description: 'Email template for all badge being issued emails.', emailType: 'BadgeIssued', subject: "You've been issued a badge - {badgeName}", title: 'Congratulations!', content: "

You have been issued with a Badge by {issuer}. 


If you have any questions about this email then please contact the badge issuer.{badgeImage}

", signature: "

Regards,

The OpenBadges.me team. 


{shareLink}

{badgeDownloadLink}

{register}

", fromEmail: 'badges@openbadges.me', new: false, htmlContent: ' You\'ve been issued a badge -{ badgeName }


Logo


Congratulations!

You have been issued with a Badge by {issuer}. 


If you have any questions about this email then please contact the badge issuer.{badgeImage}

Regards,

The OpenBadges.me team. 


{shareLink}

{badgeDownloadLink}

{register}


' }; } if (config.appCode == 'MSA') { return { name: 'Badge Issued', description: 'Email template for all badge being issued emails.', emailType: 'BadgeIssued', subject: "You've been issued a badge - {badgeName}", title: 'Congratulations!', content: "

You have been issued with a Badge by {issuer}. 


If you have any questions about this email then please contact the badge issuer.{badgeImage}

", signature: "

Regards,

The Myshowcase.me team. 


{badgeDownloadLink}


Notes

Your badge is an Open Badge conforming to the Open Badge standardsYour Badge can be added to your free myshowcase.me account for display purposes by clicking here.

", fromEmail: 'badges@myshowcase.me', new: false, htmlContent: 'You have been issued a badge - { badgeName }


Logo


Congratulations!

You have been issued with a Badge by {issuer}. 


If you have any questions about this email then please contact the badge issuer.{badgeImage}

Regards,

The OpenBadges.me team. 


{badgeDownloadLink}


Notes

Your badge is an Open Badge conforming to the Open Badge standards. Your Badge can be added to your free myshowcase.me account for display purposes by clicking here.

' }; } if (config.appCode == 'BDSU') { return { name: 'Badge Issued', description: 'Email template for all badge being issued emails.', emailType: 'BadgeIssued', subject: "You've been issued a badge - {badgeName}", title: 'Congratulations!', content: "

You have been issued with a Badge by {issuer}. 


If you have any questions about this email then please contact the badge issuer.{badgeImage}

", signature: "

Regards,

The Myshowcase.me team. 


{badgeDownloadLink}


", fromEmail: 'badges@myshowcase.me', new: false, htmlContent: 'You have been issued a badge - { badgeName }


Logo


Congratulations!

You have been issued with a Badge by {issuer}. 


If you have any questions about this email then please contact the badge issuer.{badgeImage}

Regards,

The OpenBadges.me team. 


{badgeDownloadLink}


' }; } } function getDefaultWelcome() { if (config.appCode == 'OB') { return { name: 'Welcome Email', description: 'Welcome template', emailType: 'Welcome', subject: "Welcome to openbadges.me", title: 'Welcome to openbadges.me.', content: '

Get started

Your username is: {userName}

You set the password when you created the account (if you have any problems there’s a link to reset it on the sign in page).

Are you collecting badges? 

Sign in and start managing your badges, awards and collections

Are you issuing badges? 

Follow these steps and you’ll be awarding badges in no time:

  1. Set up your issuer details
    Tell the system who your badges come from by adding an issuer
  2. Create your first badge graphic
    Get creative: use the design tool or upload a graphic
  3. Create a badge
    Add information to your graphic: what’s it called? how do people earn it?
  4. Award your badge to some lucky recipients
    Issue badges in bulk, to specific users, or automatically using our APIs
  5. View reports and analytics
    Powerful overviews of how people are doing

If you need more help, you can visit our help center. 

Get started

', signature: "Regards,

The OpenBadges.me team.", fromEmail: 'badges@openbadges.me', new: false, htmlContent: ' Welcome to openbadges.me


Logo


Welcome to openbadges.me.

Get started

Your username is: {userName}

You set the password when you created the account (if you have any problems there’s a link to reset it on the sign in page).

Are you collecting badges? 

Sign in and start managing your badges, awards and collections

Are you issuing badges? 

Follow these steps and you’ll be awarding badges in no time:

  1. Set up your issuer details
    Tell the system who your badges come from by adding an issuer
  2. Create your first badge graphic
    Get creative: use the design tool or upload a graphic
  3. Create a badge
    Add information to your graphic: what’s it called? how do people earn it?
  4. Award your badge to some lucky recipients
    Issue badges in bulk, to specific users, or automatically using our APIs
  5. View reports and analytics
    Powerful overviews of how people are doing

If you need more help, you can visit our help center. 

Get started

Regards,

The OpenBadges.me team.
' }; } if (config.appCode == 'MSA') { return { name: 'Welcome', description: 'Welcometemplate', emailType: 'Welcome', subject: "Welcome to Myshowcase.me", title: 'Welcome to Myshowcase.me.', content: 'Please find your login details below.

Username: {userName}', signature: "Regards,

The Myshowcase.me team.", fromEmail: 'info@myshowcase.me', new: false, htmlContent: ' Welcome to openbadges.me


Logo


Welcome!

Welcome to openbadges.me.  Please find your login details. Go to {sysUrl}.


Username:  {userName} 

Password:  {password}


Regards,

The OpenBadges.me team. 

' }; } if (config.appCode == 'BDSU') { return { name: 'Welcome', description: 'Welcometemplate', emailType: 'Welcome', subject: "Welcome to BDSU", title: 'Welcome to BDSU.', content: 'Please find your login details below.

Username: {userName}', signature: "Regards,

The BDSU team.", fromEmail: 'info@bdsu.com', new: false, htmlContent: ' Welcome to openbadges.me


Logo


Welcome!

Welcome to openbadges.me.  Please find your login details. Go to {sysUrl}.


Username:  {userName} 

Password:  {password}


Regards,

The OpenBadges.me team. 

' }; } if (config.appCode == 'CUPPA') { return { name: 'Welcome Email', description: 'Email template for welcome emails', emailType: 'Welcome', subject: "Welcome to Cuppa Care.", title: 'Message from CuppaCare, the learning service for social care', content: '

Thanks for setting up your admin account.

Your CuppaCare admin username is: {userName}

Log in any time at: https://admin.cuppacare.com

', signature: '

Happy brewing!

Team at CuppaCare

info@cuppacare.com

www.cuppacare.com

Copyright © 2019 Sara Dunn Associates Ltd. All rights reserved.

', fromEmail: 'noreply@cuppacare.com', new: false, htmlContent: ' Welcome to CuppaCare Admin


Logo


Message from CuppaCare, the learning service for social care

Thanks for setting up your admin account.

Your CuppaCare admin username is: {userName}

Log in any time at: https://admin.cuppacare.com

Happy brewing!

Team at CuppaCare

info@cuppacare.com

www.cuppacare.com

Copyright © 2019 Sara Dunn Associates Ltd. All rights reserved.

' }; } } function getDefaultCuppaWelcome() { return { name: 'Welcome Email', description: 'Email template for welcome emails', emailType: 'Welcome', subject: "Welcome to Cuppa Care.", title: 'Hi, this is a message from CuppaCare, the learning service for social care.', content: '


Thanks for seeting up your admin account.

Your CuppaCare admin username is: {userName}

Log in any time at: https://admin.cuppacare.com

', signature: '

Happy brewing!

Team at CuppaCare

info@cuppacare.com

www.cuppacare.com

Copyright © 2019 Sara Dunn Associates Ltd. All rights
reserved.

', fromEmail: 'noreply@cuppacare.com', new: false, htmlContent: ' Welcome to CuppaCare Admin


Logo


Hi, this is a message from CuppaCare, the learning service for social care.


Thanks for seeting up your admin account.

Your CuppaCare admin username is: {userName}

Log in any time at: https://admin.cuppacare.com

Happy brewing!

Team at CuppaCare

info@cuppacare.com

www.cuppacare.com

Copyright © 2019 Sara Dunn Associates Ltd. All rights
reserved.

' }; } } }]); app.directive('manageTemplate', ['config', 'emailTemplatesDataContext', 'emailTemplatesService', 'common', '$location', 'OrganisationAdminService', 'branding', '$compile', '$templateCache', '$http', '$timeout', '$modal', function (config, emailTemplatesDataContext, emailTemplatesService, common, $location, OrganisationAdminService, branding, $compile, $templateCache, $http, $timeout, $modal) { return { restrict: 'E', templateUrl: templatePath + 'managetemplate.html', scope: { hideTitle: '=', enableSource: '=', }, link: link }; function link($scope, elem, attrs) { var getLogFn = common.logger.getLogFn; var log = getLogFn('EmailTemplates'); var logSuccess = getLogFn('EmailTemplates', "success"); $scope.editorStyle = 'standard'; $scope.branding = branding; $scope.aceLoaded = function (_editor) { var beautify = ace.require("ace/ext/beautify"); // get reference to extension beautify.beautify(_editor.session); }; $scope.baseUrl = $location.$$protocol + '://' + $location.$$host; activate(); $scope.template = emailTemplatesService.getTemplate(); OrganisationAdminService.getTopLevelOrg().then(function (org) { $scope.topLevelOrg = org; }); $scope.saveTemplate = function () { $scope.isSaving = true; $scope.template.organisationId = $scope.topLevelOrg.id; $scope.template.systemShortCode = config.appCode; $scope.template.name = $scope.template.emailType; $scope.template.description = $scope.template.emailType; if ($scope.template.editorType !== 'source') { var t = angular.element($('#emailtemplateMain')).html(); var th = angular.element($('#emailHead')).html(); $scope.template.htmlContent = '' + th + '' + t + ''; } save($scope.template); } $scope.switchTemplate = function () { $http.get(templatePath + 'default.html').then(function (response) { $templateCache.put('Default', response.data); $scope.emailTemplate = $templateCache.get('Default'); $scope.content = $compile($scope.emailTemplate)($scope); $timeout(function () { var returnString = ''; for (var i = 0; i < $scope.content.length; i++) returnString += $scope.content[i].outerHTML ? $scope.content[i].outerHTML : ''; returnString = returnString.replace('ng-bind-html="template.signature | unsafe"', '') returnString = returnString.replace('ng-bind-html="template.content | unsafe"', '') returnString = returnString.replace('ng-bind-html="template.title | unsafe"', '') returnString = returnString.replace(' ng-binding', '') returnString = returnString.replace('ng-if="branding.logoUrl"', '') returnString = returnString.replace(' class="ng-scope"', '') returnString = returnString.replace(' ng-scope', '') returnString = returnString.replace('', '') returnString = returnString.replace('undefined', '') returnString = returnString.replace(/<\!--.*?-->/g, ''); $scope.template.htmlContent = returnString; $scope.template.editorType = 'source'; save($scope.template); }, 0); }) } function activate() { NProgress.done(); log('Activated template View'); } function save(template) { return emailTemplatesDataContext.createEmailTemplate(template).then(function (data) { logSuccess("Email Template saved."); $scope.isSaving = false; }); }; $scope.previewTemplate = function (html) { $modal.open({ templateUrl: templatePath + 'preview.html', controller: previewTemplateController, size: 'lg', backdrop: 'static', resolve: { html: function () { return html; }, } }); } //controller for showboards onboarding var previewTemplateController = function ($scope, $modalInstance, $sce, html) { $scope.html = html; $scope.getIframeSrc = function () { return $sce.trustAsResourceUrl('data:text/html;charset=UTF-8,' + $scope.html); }; $scope.close = function () { $modalInstance.dismiss('cancel'); } }; } }]); })();