12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847 |
- /*
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: SHARE
- * (C) Copyright IBM Corp. 2015, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([
- 'jquery',
- 'underscore',
- 'bi/sharecommon/utils/simpledoT',
- 'q',
- 'ckeditor',
- 'ckeditor/jquery',
- 'bi/commons/ui/View',
- 'bi/schedule/app/appControler',
- 'bi/sharecommon/utils/translator',
- 'bi/commons/utils/Utils',
- 'bi/commons/ui/properties/PropertyUIControl',
- 'bi/commons/utils/ContentFormatter',
- 'bi/schedule/utils/TextFormatter',
- 'text!bi/schedule/templates/DeliveryPickerOptions.html',
- 'text!bi/schedule/templates/RecipientsList.html',
- 'bi/commons/ui/properties/CheckBox',
- 'bi/commons/ui/properties/RadioButtonGroup',
- 'bootstrap'
- ], function($, _, dot, Q, ckeditor, jckeditor, View, controller, t, Utils, PropertyUIControl, stringFormatter, TextFormatter, optionsTemplate, recipientsListTemplate, CheckBox, RadioButtonGroup) { //NOSONAR
- 'use strict'; //NOSONAR
- /* deliveryOptions look like:
- * {
- * save: {
- * "notify": false
- * },
- * email: {
- * "emailAsAttachment": false,
- * "emailAsURL": false,
- * "subject": "blah",
- * "memoPart": "this is the body",
- * "to": "CAMID ()",
- * "cc": ,
- * "bcc": ,
- * },
- * mobile: {
- * "to":
- * },
- * print: {
- * printer: ""
- * },
- * archive: {
- * filenameStub: "filename",
- * location: /configuration/archiveLocation[@name='test'], //Using of "storeID('id')" is deprecated starting Helios R9
- * conflictResolution: "fail(keep)"|"replace(default"|"appendDateTime"|"appendSequenceNumber"
- * }
- * }
- */
- var __STANDARD_DELAY = 500;
- var __EMPTY_MESSAGE_BODY = "<html><body></body></html>";
- var deliveryPickerView = View.extend({
- /*
- * Constructor
- *
- * options: {
- * $el: {},
- * deliveryOptions: {},
- * reportName: string,
- * isEditMode: boolean
- */
-
- init: function(options, $outputDiv) { //NOSONAR
- deliveryPickerView.inherited('init', this, arguments);
- this.reportName = "";
- this.isEditMode = false;
- this.enableAdvancedSettings = false;
- this.deliveryOptions = {};
- this.overlay = false;
- this.showMobile = true;
- this.s3Connection = '';
- this.showSaveToFileSystem = true;
- var s3Loc = this._initS3Loc(options);
- this.s3SaveToCloud = (s3Loc) && (s3Loc !== '');
- if (this.s3SaveToCloud) {
- this.s3Location = s3Loc.value;
- var s3ReportName = this._initS3ReportName(options);
- if (s3ReportName) {
- this.s3ReportName = s3ReportName.value;
- }
- }
-
- this.canSave = true;
- this._icons = {
- email: 'email',
- print: 'print_icon',
- mobile: 'mobile_icon',
- save: 'save',
- archive: 'saveExternal',
- saveToCloud: 'saveExternal'
- };
- this._archiveLocations = [];
- if (options.reportName === undefined) {
- throw "Error: report name parameter must be provided.";
- }
- if (options.glassContext === undefined) {
- throw "Error: glassContext parameter must be provided.";
- }
- if (options.$toggler === undefined) {
- throw "Error: $toggler parameter must be provided.";
- }
- $.extend(this, options);
- this.notifyOnSave = !this.enableAdvancedSettings || false;
- if (options.deliveryOptions && options.deliveryOptions.save) {
- this.notifyOnSave = options.deliveryOptions.save.notify;
- }
- this.save = {
- notify: this.notifyOnSave
- };
- this.print = {
- name: ""
- };
- this.archive = {
- filenameStub: this.reportName,
- location: "",
- conflictResolution: "replace"
- };
- // if no permission passed in, assume full rights (subscribe case)
- if (options.hasPermission === undefined) {
- this.hasPermission = {
- write: true
- };
- }
- this.canSave = (this.hasPermission.write || _.contains(this.hasPermission, "write")) ? true : false;
- // Default the deliveryOptions to just Save, unless user does not have Write permission
- if ( ( !options.deliveryOptions || $.isEmptyObject(options.deliveryOptions ) && !this._hasSaveToCloudOption())) {
- if (this.canSave) {
- this.deliveryOptions = {
- save: {
- notify: this.notifyOnSave
- }
- };
- } else {
- this.deliveryOptions = {
- print: {
- name: ""
- }
- };
- }
- }
- if (!this.enableAdvancedSettings) {
- this.email = {
- emailAsAttachment: !this.canSave,
- emailAsURL: this.canSave,
- subject: "",
- memoPart: ""
- };
- this.mobile = {};
- }
- else {
- this.email = {
- emailAsAttachment: !this.canSave,
- emailAsURL: this.canSave,
- subject: "",
- memoPart: "",
- to: [],
- bcc: [],
- cc: []
- };
- this.mobile = {
- to: []
- };
- }
- if (!this.isEditMode) {
- this.email.subject = t.translate("subscription_email_subject", {
- report_name: this.reportName
- });
- if (!this.enableAdvancedSettings) {
- this.email.memoPart = '<html><body><p>' + t.translate("subscription_email_body") + '</p></body></html>';
- }
- } else if (this.isEditMode && !this.enableAdvancedSettings) {
- // Set defaults for subscription delivery
- this.email.subject = t.translate("subscription_email_subject", {
- report_name: this.reportName
- });
- this.email.memoPart = '<html><body><p>' + t.translate("subscription_email_body") + '</p></body></html>';
- if (this.deliveryOptions.email){
- this.deliveryOptions.email.subject = t.translate("subscription_email_subject", {
- report_name: this.reportName
- });
- this.deliveryOptions.email.memoPart = '<html><body><p>' + t.translate("subscription_email_body") + '</p></body></html>';
- }
- }
- },
- _initS3Loc: function(options) {
- if (options.deliveryOptions.saveToCloud) {
- var s3Details = {
- value: options.deliveryOptions.cloudLocation
- };
- return s3Details;
- }
- return _.find(options.rawOptions, function(anOpt){ return anOpt.name === 'runOptionEnum#saveToCloud'; });
- },
- _initS3ReportName: function(options) {
- if (options.deliveryOptions.cloudName) {
- var s3ReportNameDetails = {
- value: options.deliveryOptions.cloudName
- };
- return s3ReportNameDetails;
- }
- return _.find(options.rawOptions, function(anOpt){ return anOpt.name === 'runOptionEnum#cloudName'; });
- },
- close: function() {
- $(document).removeData(['setemail','setmobile']);
- },
- /**
- * Render is the main function of the Content View. Content Views should implement (override) the render
- * method to populate this.el with the appropriate HTML. Render should always return this as a promise
- * to allow chaining of calls.
- * @returns (Promise)
- */
- render: function() {
- return Q();
- },
- getDeliveryOptions: function() { //NOSONAR
- if (this.deliveryOptions.email) {
- if (this.emailCheckbox && this.emailCheckbox.isChecked() && this.attachmentCheckbox && this.attachmentCheckbox.isChecked() && typeof this.deliveryOptions.email.memoPart !== 'undefined' && this.deliveryOptions.email.memoPart === __EMPTY_MESSAGE_BODY) { //NOSONAR
- delete this.deliveryOptions.email.memoPart;
- }
- if (this.deliveryOptions.email.to && this.deliveryOptions.email.to.length > 0) {
- this.deliveryOptions.email.to = this._cleanRecipientsArray(this.deliveryOptions.email.to.slice());
- }
- if (this.deliveryOptions.email.cc && this.deliveryOptions.email.cc.length > 0) {
- this.deliveryOptions.email.cc = this._cleanRecipientsArray(this.deliveryOptions.email.cc.slice());
- }
- if (this.deliveryOptions.email.bcc && this.deliveryOptions.email.bcc.length > 0) {
- this.deliveryOptions.email.bcc = this._cleanRecipientsArray(this.deliveryOptions.email.bcc.slice());
- }
- }
- if (this.deliveryOptions.mobile && this.deliveryOptions.mobile.to && this.deliveryOptions.mobile.to.length > 0) {
- this.deliveryOptions.mobile.to = this._cleanRecipientsArray(this.deliveryOptions.mobile.to.slice());
- }
- if (this._isSaveToCloudOptionsSelected()) {
- var cloudOptions = this.getCloudOptions();
- if (cloudOptions.location) {
- this.deliveryOptions.cloudLocation = cloudOptions.location;
- if (cloudOptions.cloudReportName) {
- this.deliveryOptions.cloudName = cloudOptions.cloudReportName;
- }
- }
- } else {
- delete this.deliveryOptions.cloudLocation;
- delete this.deliveryOptions.cloudName;
- }
- return this.deliveryOptions;
- },
- getDeliveryContent: function(allowRecipients) {
- var htmlGenerator = dot.simpleTemplate(optionsTemplate);
- if (typeof allowRecipients !== "boolean") {
- // default to true
- allowRecipients = true;
- }
- this.contentUniqueId = _.uniqueId('id_');
- var attributes = {
- schedule_delivery_s3ReportName_label: t.translate('schedule_delivery_s3ReportName_label'),
- schedule_delivery_s3ConnectionName_label: t.translate('schedule_delivery_s3ConnectionName_label'),
- schedule_delivery_s3LocationName_label: t.translate('schedule_delivery_s3LocationName_label'),
- schedule_delivery_printer_name_label: t.translate("schedule_delivery_printer_name_label"),
- schedule_name_label: t.translate("schedule_name_label"),
- schedule_delivery_location_label: t.translate("schedule_delivery_location_label"),
- schedule_delivery_conflict_resolution_label: t.translate("schedule_delivery_conflict_resolution_label"),
- showSaveToFileSystem: this.showSaveToFileSystem,
- advanced: this.enableAdvancedSettings,
- schedule_delivery_recipient_label: t.translate("schedule_delivery_recipient_label"),
- schedule_delivery_subject_label: t.translate("schedule_delivery_subject_label"),
- schedule_delivery_cc_label: t.translate("schedule_delivery_cc_label"),
- schedule_delivery_bcc_label: t.translate("schedule_delivery_bcc_label"),
- schedule_done_btn: t.translate("schedule_delivery_done_label"),
- uniqueid: this.contentUniqueId,
- showMobile: this.showMobile,
- allowRecipients: allowRecipients
- };
- return htmlGenerator(attributes);
- },
- setCloudEvents: function($deliveryList) {
- var reportNameEl = $deliveryList.find('#delivery_saveToS3_reportName_' + this.contentUniqueId);
-
- var cloudOptions = this.getCloudOptions();
- if (cloudOptions.cloudReportName) {
- reportNameEl.val(cloudOptions.cloudReportName);
- } else if (cloudOptions.reportName) {
- reportNameEl.val(cloudOptions.reportName);
- } else {
- reportNameEl.val(this.reportName);
- }
-
- reportNameEl.on('change', function(){ this.cloudReportName = reportNameEl.val();}.bind(this));
- },
- _renderOptions: function($selectEl, optionList) {
- $selectEl.empty();
- $selectEl.append($('<option>', {
- value: '',
- text: ''
- }));
- _.each(optionList, function(item) {
- $selectEl.append($('<option>', {
- value: item.id,
- text: item.defaultName
- }));
- });
- },
- _setS3ConnectionOptionsForUpdate: function($deliveryList) {
- var locationIDToLookup = this.s3Location;
- if (this.cloudLocation) {
- locationIDToLookup = this.cloudLocation;
- }
- controller.getS3LocationParentConnectionID(this.glassContext, locationIDToLookup).done(function(resp) {
- if (resp.data[0] && resp.data[0].parent[0] && resp.data[0].parent[0].id) {
- var preChosenConnectionID = resp.data[0].parent[0].id;
- controller.getS3ConnectionDetails(this.glassContext).done(function(resp) {
- var $connectionSelect = $deliveryList.find('.schedule_save_to_file_system_connection_selection');
- var $locationSelect = $deliveryList.find('.location-selction-section-select');
- var $locationSection = $deliveryList.find('.location-selction-section');
-
- this._renderOptions($connectionSelect, resp.data);
- $connectionSelect.val(preChosenConnectionID);
- this._handleConnectionChange($connectionSelect, $locationSelect, $locationSection, $deliveryList);
- controller.getS3LocationsDetails(this.glassContext, preChosenConnectionID).done(function(resp) {
- this._renderOptions($locationSelect, resp.data)
- $locationSelect.val(locationIDToLookup);
- this._handleLocationChange($locationSelect);
- }.bind(this));
- }.bind(this));
- }
- }.bind(this));
-
- },
- _handleConnectionChange: function($connectionSelect, $locationSelect, $locationSection, $deliveryList) {
- $connectionSelect.change(function() {
- $locationSection.hide();
- this.cloudConnection = $connectionSelect.val();
- $locationSelect.val('');
- $locationSelect.empty();
- controller.getS3LocationsDetails(this.glassContext, $connectionSelect.val()).done(function(resp) {
- this._renderOptions($locationSelect, resp.data);
- $locationSection.show();
- this._handleLocationChange($locationSelect);
- }.bind(this));
-
-
- }.bind(this));
- },
- _handleLocationChange: function($locationSelect) {
- $locationSelect.change(function() {
- this.cloudLocation = $locationSelect.val();
- }.bind(this));
- },
- _setS3ConnectionOptions: function($deliveryList) {
- var dfd = Q.defer();
- controller.getS3ConnectionDetails(this.glassContext).done(function(resp) {
- var $connectionSelect = $deliveryList.find('.schedule_save_to_file_system_connection_selection');
- var $locationSelect = $deliveryList.find('.location-selction-section-select');
- var $locationSection = $deliveryList.find('.location-selction-section');
- $locationSection.hide();
- this._handleConnectionChange($connectionSelect, $locationSelect, $locationSection, $deliveryList);
- this._handleLocationChange($locationSelect);
- this._renderOptions($connectionSelect, resp.data);
-
- dfd.resolve();
- }.bind(this));
- return dfd.promise;
- },
- setDeliveryOptions: function($deliveryList, $activeOptionsList) {
- var dfd = Q.defer();
- // Check if there are archive locations set in configuration to decide if render the savetofilesystem ui
- controller.getArchiveLocations(this.glassContext).done(function(result) {
- if (result && result.data && result.data.length > 0) {
- this._archiveLocations = result.data;
- } else {
- this.showSaveToFileSystem = false;
- }
- this._renderCheckBoxes($deliveryList, $activeOptionsList);
- this.setCloudEvents($deliveryList);
- if (this._isSaveToCloudOptionsSelected()) {
- $deliveryList.find('.delivery_s3_options').show(__STANDARD_DELAY);
- }
-
- if (this.showSaveToFileSystem) {
- this._renderRadioButtonGroup($deliveryList);
- }
- // Update the pane's ActiveOptionsList list.
- if ($activeOptionsList) {
- this.updateActiveDeliveryList($activeOptionsList);
- }
- dfd.resolve();
- }.bind(this));
- return dfd.promise;
- },
- getCloudOptions: function() {
- var result = {};
- if ((this.cloudLocation) && (this.cloudLocation !== '')) {
- result.location = this.cloudLocation;
- if ((this.cloudReportName) && (this.cloudReportName !== '')) {
- result.reportName = this.cloudReportName;
- result.cloudReportName = this.cloudReportName;
- }
- }
- // Need this when opening an existing schedule with save to s3 selected
- else if (this.s3Location && this.s3Location !== '') {
- result.location = this.s3Location;
- if (this.cloudReportName && this.cloudReportName !== '') {
- result.reportName = this.cloudReportName;
- result.cloudReportName = this.cloudReportName;
- } else if (this.s3ReportName && this.s3ReportName !== '') {
- result.reportName = this.s3ReportName;
- result.cloudReportName = this.cloudReportName;
- }
- }
- return result;
- },
- _isSaveToCloudOptionsSelected: function() {
- if ((this.s3SaveToCloud) || (this.cloudLocation) || (this.s3Location)) {
- return true;
- }
- return false;
- },
- _renderCheckBoxes: function($deliveryList, $activeOptionsList) { //NOSONAR
- var emailStatus = false;
- var attachmentStatus = false;
- var linkStatus = false;
- var printStatus = false;
- var mobileStatus = false;
- var saveStatus = false;
- var archiveStatus = false;
- // Check off options previously selected
- if (this.deliveryOptions.save) {
- saveStatus = true;
- }
- if (this.s3SaveToCloud || this.cloudLocation) {
- this._setS3ConnectionOptionsForUpdate($deliveryList);
- }
- if (this.deliveryOptions.email) {
- emailStatus = true;
- $deliveryList.find('.delivery_email_options').show();
- if (this.deliveryOptions.email.emailAsAttachment) {
- this.email.emailAsAttachment = true;
- attachmentStatus = true;
- } else {
- this.email.emailAsAttachment = false;
- }
- if (this.deliveryOptions.email.emailAsURL) {
- this.email.emailAsURL = true;
- linkStatus = true;
- saveStatus = true;
- } else {
- this.email.emailAsURL = false;
- }
- if (this.enableAdvancedSettings) {
- this.setAdvancedEmailStoredContent($deliveryList);
- }
- } else {
- $deliveryList.find('.delivery_email_options').hide();
- }
- if (this.deliveryOptions.mobile) {
- mobileStatus = true;
- $deliveryList.find('.delivery_mobile_options').show();
- if (this.enableAdvancedSettings) {
- this.setAdvancedMobileStoredContent($deliveryList);
- }
- } else {
- $deliveryList.find('.delivery_mobile_options').hide();
- }
- if (this.deliveryOptions.print) {
- printStatus = true;
- this._setPrinters($deliveryList);
- $deliveryList.find('.delivery_print_options').show();
- } else {
- $deliveryList.find('.delivery_print_options').hide();
- }
- if (this.deliveryOptions.archive) {
- archiveStatus = true;
- this.archive.conflictResolution = this.deliveryOptions.archive.conflictResolution;
- this._setSaveToFileSystemValues($deliveryList);
- $deliveryList.find('.delivery_save_to_file_system_options').show();
- } else {
- $deliveryList.find('.delivery_save_to_file_system_options').hide();
- }
- this.emailCheckbox = new CheckBox({
- 'id': 'delivery_email_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_email_container_' + this.contentUniqueId),
- 'name': 'delivery_email_option',
- 'label': t.translate("schedule_delivery_email_label"),
- 'ariaLabel': t.translate("schedule_delivery_email_label"),
- 'svgIcon': 'email',
- 'checked': emailStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- this.attachmentCheckbox = new CheckBox({
- 'id': 'delivery_attachment_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_attachment_container_' + this.contentUniqueId),
- 'name': 'delivery_attachment_option',
- 'label': t.translate("schedule_delivery_attach_label"),
- 'ariaLabel': t.translate("schedule_delivery_attach_label"),
- 'checked': attachmentStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- this.printCheckbox = new CheckBox({
- 'id': 'delivery_print_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_print_container_' + this.contentUniqueId),
- 'name': 'delivery_print_option',
- 'label': t.translate("schedule_delivery_print_label"),
- 'ariaLabel': t.translate("schedule_delivery_print_label"),
- 'svgIcon': 'print_icon',
- 'checked': printStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- this.mobileCheckbox = new CheckBox({
- 'id': 'delivery_mobile_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_mobile_container_' + this.contentUniqueId),
- 'name': 'delivery_mobile_option',
- 'label': t.translate("schedule_delivery_mobile_label"),
- 'ariaLabel': t.translate("schedule_delivery_mobile_label"),
- 'svgIcon': 'mobile_icon',
- 'checked': mobileStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- this.saveToFSCheckbox = new CheckBox({
- 'id': 'delivery_save_to_file_system_checkbox_container_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_save_to_file_system_checkbox_container_' + this.contentUniqueId),
- 'name': 'delivery_save_to_file_system_options',
- 'label': t.translate("schedule_delivery_save_to_file_system_label"),
- 'ariaLabel': t.translate("schedule_delivery_save_to_file_system_label"),
- 'svgIcon': 'saveExternal',
- 'checked': archiveStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- if (this.hasPermission.write || _.contains(this.hasPermission, "write")) {
- this.linkCheckbox = new CheckBox({
- 'id': 'delivery_link_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_link_container_' + this.contentUniqueId),
- 'name': 'delivery_link_option',
- 'label': t.translate("schedule_delivery_link_label"),
- 'ariaLabel': t.translate("schedule_delivery_link_label"),
- 'checked': linkStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- this.saveTOS3Checkbox = new CheckBox({
- 'id': 'delivery_saveTOS3_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_saveTOS3_container_' + this.contentUniqueId),
- 'name': 'delivery_saveTOS3_option',
- 'label': t.translate("saveToCloud"),
- 'ariaLabel': t.translate("schedule_delivery_save_label"),
- 'svgIcon': 'saveExternal',
- 'checked': this._isSaveToCloudOptionsSelected(),
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- this.saveCheckbox = new CheckBox({
- 'id': 'delivery_save_checkbox_' + this.contentUniqueId,
- 'el': $deliveryList.find('#delivery_save_container_' + this.contentUniqueId),
- 'name': 'delivery_save_option',
- 'label': t.translate("schedule_delivery_save_label"),
- 'ariaLabel': t.translate("schedule_delivery_save_label"),
- 'svgIcon': 'save',
- 'checked': saveStatus,
- 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
- });
- if (this._checkCapabilities('canIncludeLinkInEmail')) {
- this.linkCheckbox.doRender();
- }
- this.saveTOS3Checkbox.doRender();
- this.saveCheckbox.doRender();
- }
- if ( this.showSaveToFileSystem ) {
- this.saveToFSCheckbox.doRender();
- }
- if (this._checkCapabilities('canEmail')) {
- this.emailCheckbox.doRender();
- }
- if (this._checkCapabilities('canAttach')) {
- this.attachmentCheckbox.doRender();
- }
- this.printCheckbox.doRender();
- this.mobileCheckbox.doRender();
- },
- _checkCapabilities: function(capabilityName) {
- return _.find(this.glassContext.services.userProfile.capabilities, function(capability){
- return capability === capabilityName;
- });
- },
- _handleCheckBoxes: function(name, value, $deliveryList, $activeOptionsList) { //NOSONAR
- switch(name) {
- case 'delivery_saveTOS3_option':
- if (value) {
- this._setS3ConnectionOptions($deliveryList);
- this.deliveryOptions.saveToCloud = true;
- $deliveryList.find('.delivery_s3_options').show(__STANDARD_DELAY);
- } else {
- $deliveryList.find('.delivery_s3_options').hide(__STANDARD_DELAY);
- // this.deliveryOptions.saveToCloud = false;
- delete this.deliveryOptions.saveToCloud;
- delete this.deliveryOptions.cloudLocation;
- //Delete the raw options for runOptionEnum#saveToCloud and runOptionEnum#cloudName
- this.rawOptions = _.filter(this.rawOptions, function(option) {
- return !(option.name === "runOptionEnum#saveToCloud" || option.name === 'runOptionEnum#cloudName');
- });
- delete this.s3SaveToCloud;
- delete this.s3Location;
- delete this.cloudConnection;
- delete this.cloudLocation;
- }
- break;
- case 'delivery_attachment_option':
- if (this.deliveryOptions.email) {
- if(value) {
- this.email.emailAsAttachment = true;
- this.deliveryOptions.email = this.email;
- } else {
- this.email.emailAsAttachment = false;
- this.deliveryOptions.email = this.email;
- }
- }
- break;
- case 'delivery_link_option':
- if (this.deliveryOptions.email) {
- if (value) {
- this.email.emailAsURL = true;
- this.deliveryOptions.email = this.email;
- if (!this.deliveryOptions.save) { //NOSONAR
- this.saveCheckbox.check();
- this.glassContext.appController.showToast(t.translate('schedule_delivery_email_save_info_label'), {
- 'type': 'info',
- 'preventDuplicates' : true
- });
- }
- } else {
- this.email.emailAsURL = false;
- this.deliveryOptions.email = this.email;
- }
- }
- break;
- case 'delivery_email_option':
- if (value) {
- this.deliveryOptions.email = this.email;
- if (this.deliveryOptions.email.emailAsAttachment) {
- this.attachmentCheckbox.check();
- } else {
- this.attachmentCheckbox.uncheck();
- }
- // linkCheckbox is only rendered when there is write permission
- if (this.linkCheckbox) {
- if (this.deliveryOptions.email.emailAsURL) { //NOSONAR
- this.linkCheckbox.check();
- } else {
- this.linkCheckbox.uncheck();
- }
- }
- $deliveryList.find('.delivery_email_options').show(__STANDARD_DELAY);
- if (this.enableAdvancedSettings) {
- this.setAdvancedEmailStoredContent($deliveryList);
- }
- } else {
- delete this.deliveryOptions.email;
- // Reset the updated holder and the UI email recipients list to empty
- this.email.to = [];
- $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId + ' .delivery_recipient').remove();
- $deliveryList.find('.delivery_email_options').hide(__STANDARD_DELAY);
- }
- break;
- case 'delivery_save_option':
- if (value) {
- this.deliveryOptions.save = this.save;
- } else {
- if (this.deliveryOptions.email && this.deliveryOptions.email.emailAsURL) {
- this.saveCheckbox.check();
- this.glassContext.appController.showToast(t.translate('schedule_delivery_email_save_info_label'), {
- 'type': 'info',
- 'preventDuplicates' : true
- });
- } else {
- delete this.deliveryOptions.save;
- }
- }
- break;
- case 'delivery_mobile_option':
- if (value) {
- this.deliveryOptions.mobile = this.mobile;
- $deliveryList.find('.delivery_mobile_options').show(__STANDARD_DELAY);
- if(this.enableAdvancedSettings) {
- this.setAdvancedMobileStoredContent($deliveryList);
- }
- } else {
- delete this.deliveryOptions.mobile;
- $deliveryList.find('.delivery_mobile_options').hide(__STANDARD_DELAY);
- }
- break;
- case 'delivery_print_option':
- if (value) {
- $deliveryList.find('.delivery_print_options').show(__STANDARD_DELAY);
- this._setPrinters($deliveryList, $activeOptionsList);
- } else {
- delete this.deliveryOptions.print;
- $deliveryList.find('.delivery_print_options').hide(__STANDARD_DELAY);
- }
- break;
- case 'delivery_save_to_file_system_options':
- if(value) {
- $deliveryList.find('.delivery_save_to_file_system_options').show(__STANDARD_DELAY);
- this._setSaveToFileSystemValues($deliveryList, $activeOptionsList);
- } else {
- delete this.deliveryOptions.archive;
- $deliveryList.find('.delivery_save_to_file_system_options').hide(__STANDARD_DELAY);
- }
- break;
- default: {
- break;
- }
- }
- // Force "save" option to be used if everything has been unchecked
- if ($.isEmptyObject(this.deliveryOptions) && !this._isSaveToCloudOptionsSelected()) {
- if (this.hasPermission.write || _.contains(this.hasPermission, "write")) {
- this.saveCheckbox.check();
- } else {
- this.printCheckbox.check();
- }
- // Toast to explain why user is unable to unclick save (at least one delivery option must be selected)
- this.glassContext.appController.showToast(t.translate('schedule_delivery_min_select_label'), {
- 'type': 'info',
- 'preventDuplicates': true
- });
- }
- // Update the pane's ActiveOptionsList list.
- if ($activeOptionsList) {
- this.updateActiveDeliveryList($activeOptionsList);
- }
- },
- _hasSaveToCloudOption: function() {
- if (this.deliveryOptions.saveToCloud) {
- return true;
- }
- //Check the raw options
- var saveToCloudOption = _.find(this.rawOptions, function(option) {
- if (option.name === 'runOptionEnum#saveToCloud') {
- return true;
- }
- });
- if (saveToCloudOption) {
- return true;
- }
- return false;
- },
- _setPrinters: function ($deliveryList, $activeOptionsList) {
- var $printerDropdown = $deliveryList.find('.schedule_printer_names:not(.clickBound)');
- $printerDropdown.addClass('clickBound');
- var $printerOtherField = $deliveryList.find('#delivery_print_other_name_' + this.contentUniqueId + ':not(.clickBound)');
- $printerOtherField.addClass('clickBound');
- $printerDropdown.change(function () {
- var newValue = $printerDropdown.val();
- if (newValue === t.translate('schedule_delivery_printer_other_label')) {
- $deliveryList.find('.delivery_other_printer_section').show(__STANDARD_DELAY);
- } else {
- $deliveryList.find('.delivery_other_printer_section').hide(__STANDARD_DELAY);
- this._updatePrintDeliveryOption(newValue, $activeOptionsList);
- }
- }.bind(this));
- // can be changed to 'input' for every key stroke/ change including copy paste
- $printerOtherField.on('change', function (event) {
- this._updatePrintDeliveryOption(event.target.value, $activeOptionsList);
- }.bind(this));
- if ($printerDropdown.length) {
- controller.getPrinters(this.glassContext).done(function (result) {
- var systemPrinters = [];
- if (result && result.data) {
- systemPrinters = result.data;
- }
- this._setPrinterSelectionValues(systemPrinters, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList);
- }.bind(this));
- } else {
- // Lets deliveryOptions know that the print option is selected. Without else clause, 'Save Report' option will be selected by default even if 'Print Report' is selected
- this.deliveryOptions.print = this.print;
- }
- },
- _setPrinterSelectionValues: function (systemPrinters, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList) {
- var presetPrinterName = '';
- if (this.deliveryOptions && this.deliveryOptions.print && this.deliveryOptions.print.name) {
- // There is a preset printer delivery option
- presetPrinterName = this.deliveryOptions.print.name;
- }
- // Set dropdown values and determine if the already-selected printer value is in the dropdown list
- for (var i = 0; i < systemPrinters.length; i++) {
- /* provide a displayed printer name that is truncated from the middle with an ellipsis
- * e.g: 'My Printer Name That Is Exceedingly Long' => 'My Pr...xceedingly Long'
- */
- var truncatedName = TextFormatter.middleShortenString(systemPrinters[i].defaultName);
- /* provide a meaningful option 'title' using defaultScreenTip, if provided, otherwise use the description, and
- * failing that, use the printerAddress attribute
- */
- var title = (systemPrinters[i].defaultScreenTip) ? systemPrinters[i].defaultScreenTip
- : ((systemPrinters[i].defaultDescription) ? systemPrinters[i].defaultDescription
- : systemPrinters[i].printerAddress);
- $printerDropdown.append($('<option>', {
- value: systemPrinters[i].printerAddress,
- title: title
- }).text(truncatedName));
- }
- // Add 'Other...' to dropdown list
- $printerDropdown.append($('<option>', {
- value: t.translate('schedule_delivery_printer_other_label')
- }).text(t.translate('schedule_delivery_printer_other_label')));
- // Do not automatically display 'Other...' input field directly if there are system printer options
- if (systemPrinters.length > 0) {
- $deliveryList.find('.delivery_other_printer_section').hide();
- }
- if (presetPrinterName) {
- // set dropdown value to preset
- this._setDropDownValueToPresetPrinter(presetPrinterName, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList);
- } else {
- this._setDefaultDeliveryPrintOption(systemPrinters, $printerOtherField, $activeOptionsList);
- }
- },
- _setDropDownValueToPresetPrinter: function (presetPrinterName, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList) {
- var escapedPrinterName = TextFormatter.escapeSpecialCharacters(presetPrinterName);
- if ($printerDropdown.find("option[value='" + escapedPrinterName + "']").length > 0) {
- // presetPrinterName is one of the available options, make it the selected one, and hide the Other... text field if shown
- $printerDropdown.val(presetPrinterName);
- $deliveryList.find('.delivery_other_printer_section').hide();
- } else {
- // presetPrinterName is specified, but is not an available select value, so treat it as the 'Other...' value
- $printerDropdown.val(t.translate('schedule_delivery_printer_other_label'));
- $deliveryList.find('.delivery_other_printer_section').show(__STANDARD_DELAY);
- $printerOtherField.val(presetPrinterName);
- }
- this._updatePrintDeliveryOption(presetPrinterName, $activeOptionsList);
- },
- _setDefaultDeliveryPrintOption: function (systemPrinters, $printerOtherField, $activeOptionsList) {
- var printerName;
- if (systemPrinters && systemPrinters.length > 0) {
- //select the first listed printer as the default
- printerName = systemPrinters[0].printerAddress;
- } else {
- //set the default to "Other..." value
- printerName = $printerOtherField.val();
- }
- this._updatePrintDeliveryOption(printerName, $activeOptionsList);
- },
- _updatePrintDeliveryOption: function (printerName, $activeOptionsList) {
- this.print.name = printerName;
- this.deliveryOptions.print = this.print;
- if ($activeOptionsList){
- this.updateActiveDeliveryList($activeOptionsList);
- }
- },
- _setSaveToFileSystemValues: function($deliveryList, $activeOptionsList) { //NOSONAR
- var $outputNameField = $deliveryList.find('#delivery_save_to_file_system_file_name_' + this.contentUniqueId + ':not(.clickBound)');
- $outputNameField.addClass('clickBound');
- if (this.deliveryOptions && this.deliveryOptions.archive && this.deliveryOptions.archive.filenameStub) {
- this.archive.filenameStub = this.deliveryOptions.archive.filenameStub;
- } else {
- this.archive.filenameStub = this.reportName;
- }
- $outputNameField.val(this.archive.filenameStub);
- var $outputNameInputField = $deliveryList.find('.delivery_save_to_file_system_file_name_input_section');
- stringFormatter.middleShortenString($outputNameInputField);
- var $fileLocationDropdown = $deliveryList.find('.schedule_save_to_file_system_locations:not(.clickBound)');
- $fileLocationDropdown.addClass('clickBound');
- this._archiveLocations = _.sortBy(this._archiveLocations, 'defaultName');
- for (var i = 0; i < this._archiveLocations.length; i++) {
- var truncatedName = TextFormatter.middleShortenString(this._archiveLocations[i].defaultName);
- $fileLocationDropdown.append($('<option>', {
- value: this._archiveLocations[i].defaultName,
- title: this._archiveLocations[i].defaultName
- }).text(truncatedName));
- }
- if(this.deliveryOptions && this.deliveryOptions.archive && this.deliveryOptions.archive.location) {
- //The saved location could still be id based but going forward from R9 it will be named searchPath
- this.archive.location = this.deliveryOptions.archive.location;
- var displayName = this._getDisplayNameFromStoreIDOrSearchPath(this.archive.location);
- $fileLocationDropdown.val(displayName);
- } else {
- this.archive.location = this._archiveLocations[0].searchPath;
- }
- $fileLocationDropdown.change(function() {
- var newValue = $fileLocationDropdown.val();
- var namedSearchPath = this._getSearchPathForLocation(newValue);
- this.archive.location = namedSearchPath;
- this.deliveryOptions.archive.location = this.archive.location;
- if ($activeOptionsList) {
- this.updateActiveDeliveryList($activeOptionsList);
- }
- }.bind(this));
- $outputNameField.on('change', function(event){
- this.archive.filenameStub = event.target.value;
- this.deliveryOptions.archive.filenameStub = this.archive.filenameStub;
- if($activeOptionsList) {
- this.updateActiveDeliveryList($activeOptionsList);
- }
- }.bind(this));
- if ( this._archiveLocations.length > 0 && this.archive.location === "") {
- //Handle in case nothing is set by user
- this.archive.location = this._archiveLocations[0].searchPath;
- }
- // Set the latest
- this.deliveryOptions.archive = this.archive;
- if ($activeOptionsList) {
- this.updateActiveDeliveryList($activeOptionsList);
- }
- },
- _getSearchPathForLocation: function(locationName) {
- var idItem = _.find(this._archiveLocations, function(item){
- return item.defaultName === locationName;
- }.bind(this));
- return idItem? idItem.searchPath : "";
- },
- _getDisplayNameFromStoreIDOrSearchPath: function(savedLocation) {
- var idItem = _.find(this._archiveLocations, function(item){
- return savedLocation.indexOf(item.id) !== -1 || savedLocation === item.searchPath ;
- }.bind(this));
- return idItem? idItem.defaultName : "";
- },
- _renderRadioButtonGroup: function($deliveryList) {
- var deferred = Q.defer();
- var itemsSpec = [this._getConflictResolutionContainer($deliveryList)];
- this._conflictResolutionOptionsControl = new PropertyUIControl({
- 'el': $deliveryList.find('#schedule_delivery_conflict_resolution_section_' + this.contentUniqueId),
- 'items': itemsSpec,
- 'glassContext': this.glassContext
- });
- this._conflictResolutionOptionsControl.render().then(function() {
- this._conflictResolutionOptionsControl = this._conflictResolutionOptionsControl.getProperty('conflictResolutionOptions');
- deferred.resolve();
- }.bind(this));
- return deferred.promise;
- },
- _getConflictResolutionContainer: function($deliveryList) {
- return {
- 'type': 'CollapsibleSection',
- 'name': 'conflictResolutionOptions',
- 'styleAsSimpleRow': true,
- 'label': t.translate("schedule_delivery_conflict_resolution_label"),
- 'items': [this._getConflictResolutionOptions($deliveryList)]
- };
- },
- _getConflictResolutionOptions: function() {
- var buttonItems = [];
- buttonItems.push({
- 'name': 'fail',
- 'label': t.translate("schedule_delivery_keep_existing_label"),
- 'id': 'delivery_keep_' + this.contentUniqueId,
- 'value': 'fail'
- });
- buttonItems.push({
- 'name': 'replace',
- 'label': t.translate("schedule_delivery_replace_label"),
- 'id': 'delivery_replace_' + this.contentUniqueId,
- 'value': 'replace'
- });
- buttonItems.push({
- 'name': 'appendDateTime',
- 'label': t.translate("schedule_delivery_timestamp_label"),
- 'id': 'delivery_timestamp_' + this.contentUniqueId,
- 'value': 'appendDateTime'
- });
- buttonItems.push({
- 'name': 'appendSequenceNumber',
- 'label': t.translate("schedule_delivery_version_number_label"),
- 'id': 'delivery_version_number_' + this.contentUniqueId,
- 'value': 'appendSequenceNumber'
- });
- return {
- 'type': 'RadioButtonGroup',
- 'name': 'delivery_conflict_resolution_pick',
- 'ariaLabel': t.translate("schedule_delivery_conflict_resolution_label"),
- 'value': this.archive.conflictResolution,
- 'separator': false,
- 'onChange': this._updateConflictResolutionValue.bind(this),
- 'items': buttonItems
- };
- },
- _updateConflictResolutionValue: function(name, value) {
- // Update the delivery options for save to archives
- this.archive.conflictResolution = value;
- },
- updateActiveDeliveryList: function($activeOptionsList) {
- if (this.deliveryOptions) {
- $activeOptionsList.html('');
- for (var delivery in this.deliveryOptions) { //NOSONAR
- if (delivery !== 'cloudLocation') {
- var $link = $("<div/>").addClass('delivery_link').text(t.translate("schedule_delivery_" + delivery + "_short_label"));
- $("<div/>").addClass('delivery_type_container').append("<span class='delivery_icon' data-icon='" + this._icons[delivery] + "'></span>").append($link).appendTo($activeOptionsList);
- }
- }
- //Check for cloud storage delivery option
- if (this._hasSaveToCloudOption() && !this.deliveryOptions.saveToCloud) {
- if (this.$el.find('.delivery_type_container.saveToCloud').length === 0) {
- var $link = $("<div/>").addClass('delivery_link').text(t.translate("schedule_delivery_saveToCloud_short_label"));
- $("<div/>").addClass('delivery_type_container saveToCloud').append("<span class='delivery_icon' data-icon='" + this._icons['saveToCloud'] + "'></span>").append($link).appendTo($activeOptionsList);
- }
- }
- this.setIcons($activeOptionsList);
- this.shortenLinks($activeOptionsList);
- }
- },
- setIcons: function(container) {
- var icons = container.find('.delivery_icon');
- var links = container.find('.delivery_link');
- for (var j = 0; j < icons.length; j++) {
- var $icon = $(icons[j]);
- var $link = $(links[j]);
- Utils.setIcon($icon, 'common-' + $icon.data('icon'), $link.html());
- }
- },
- shortenLinks: function(container) {
- var links = container.find('.delivery_link');
- for (var j = 0; j < links.length; j++) {
- stringFormatter.middleShortenString(links[j]);
- }
- },
- // FUNCTIONS EXCLUSIVE TO ADVANCED LEVEL
- setAdvancedMobileStoredContent: function($deliveryList) {
- var $mobileRecipientsList = $deliveryList.find('#delivery_mobile_recipients_' + this.contentUniqueId);
- // mobile recipients
- var $mobileRecipientsInput = $deliveryList.find('.delivery_mobile_to_section:not(.clickBound)');
- $mobileRecipientsInput.addClass('clickBound');
- $mobileRecipientsInput.on('clicktap', function() {
- this.glassContext.appController.showSlideOut({
- 'position': 'right',
- 'overlay': true,
- 'parent': this.slideout,
- 'width': this.slideout.width,
- 'label': t.translate('schedule_delivery_accounts_aria_label'),
- 'content': {
- 'module': 'bi/schedule/views/AccountPickerSlideoutView',
- 'glassContext': this.glassContext,
- 'addCallback': function(selectedItems) {
- var values = Object.keys(selectedItems).map(function(key) {
- return selectedItems[key]
- });
- this._addMobileRecipients(values, $deliveryList, true);
- return Promise.resolve();
- }.bind(this)
- }
- });
- }.bind(this));
- var $mobileRecipientsEllipsis = $deliveryList.find('#delivery_mobile_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
- $mobileRecipientsEllipsis.addClass('clickBound');
- $mobileRecipientsEllipsis.on('clicktap', function(event) {
- event.cancelBubble = true;
- if (event.stopPropagation) {
- event.stopPropagation();
- }
- $mobileRecipientsList.addClass('expanded');
- $mobileRecipientsEllipsis.hide();
- }.bind(this));
- //POPULATE IF MOBILE ALREADY HAS
- if (this.deliveryOptions && this.deliveryOptions.mobile && this.deliveryOptions.mobile.to && $.isArray(this.deliveryOptions.mobile.to) &&this.deliveryOptions.mobile.to.length !== 0) { //NOSONAR
- this._addMobileRecipients(this.deliveryOptions.mobile.to, $deliveryList, false);
- }
- var $mobileRecipientLabel = $deliveryList.find('label[for="delivery_mobile_recipients_' + this.contentUniqueId+ '"]');
- if (!$(document).data('setmobile')) {
- $(document).data('setmobile', true).on('clicktap', function(event) {
- // Collapse mobile Recipients
- if (!$mobileRecipientsInput.is(event.target) && $mobileRecipientsInput.has(event.target).length === 0) {
- $mobileRecipientsList.removeClass('expanded');
- this._checkForEllipsis($mobileRecipientsList, $mobileRecipientLabel, function(show) {
- if (show) {
- $mobileRecipientsEllipsis.show(__STANDARD_DELAY);
- } else {
- $mobileRecipientsEllipsis.hide(__STANDARD_DELAY);
- }
- }.bind(this));
- }
- }.bind(this));
- }
- },
- setAdvancedEmailStoredContent: function($deliveryList) { //NOSONAR
- // subject
- var $emailSubjectInput = $deliveryList.find('#schedule_email_subject_' + this.contentUniqueId);
- if (this.deliveryOptions.email.subject) {
- $emailSubjectInput.val(this.deliveryOptions.email.subject);
- this.email.subject = $emailSubjectInput.val();
- } else if(this.email.subject) {
- $emailSubjectInput.val(this.email.subject);
- }
- // can be changed to 'input' for every key stroke/ change including copy paste
- $emailSubjectInput.on('change', function(event){
- this.deliveryOptions.email.subject = event.target.value;
- this.email.subject = event.target.value;
- }.bind(this));
- // email message
- var $emailBodyEditor = $deliveryList.find('#delivery_email_message_' + this.contentUniqueId);
- var customConfig2 = "../../../js/schedule/utils/cke_editor_delivery_config.js";
- var messageEditor = $emailBodyEditor.ckeditor({
- customConfig: "../../../js/schedule/utils/cke_editor_delivery_config.js"
- }).editor;
- if (messageEditor.config && messageEditor.config.language){
- messageEditor.config.language = this.glassContext.services.userProfile.preferences.productLocale;
- }
- // set editor dialog handler
- this._setEditorDialogHideHandler();
- if (this.deliveryOptions.email.memoPart) {
- messageEditor.setData(this.deliveryOptions.email.memoPart);
- this.email.memoPart = messageEditor.getData();
- } else if (this.email.memoPart) {
- messageEditor.setData(this.email.memoPart);
- } else {
- // SET empty deliveryOptions memoPart
- this.deliveryOptions.email.memoPart = __EMPTY_MESSAGE_BODY;
- this.email.memoPart = __EMPTY_MESSAGE_BODY;
- }
- messageEditor.on('change', function(event) {
- this.deliveryOptions.email.memoPart = "<html><body>" + event.editor.getData() + "</body></html>";
- this.email.memoPart = "<html><body>" + event.editor.getData() + "</body></html>";
- }.bind(this));
- // RECIPIENTS
- var $emailRecipientsList = $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId);
- var $ccRecipientsList = $deliveryList.find('#delivery_cc_recipients_' + this.contentUniqueId);
- var $bccRecipientsList = $deliveryList.find('#delivery_bcc_recipients_' + this.contentUniqueId);
- // TO Recipients
- var $emailRecipientsInput = $deliveryList.find('.delivery_email_to_section');
- var $emailRecipientsLabel = $emailRecipientsInput.find('.schedule_delivery_header:not(.clickBound)');
- $emailRecipientsLabel.addClass('clickBound');
- $emailRecipientsLabel.on('clicktap', function() {
- this.glassContext.appController.showSlideOut({
- 'position': 'right',
- 'overlay': true,
- 'parent': this.slideout,
- 'width': this.slideout.width,
- 'label': t.translate('schedule_delivery_accounts_aria_label'),
- 'content': {
- 'module': 'bi/schedule/views/AccountPickerSlideoutView',
- 'glassContext': this.glassContext,
- 'addCallback': function(selectedItems) {
- var values = Object.keys(selectedItems).map(function(key) {
- return selectedItems[key]
- });
- this._addEmailRecipients(values, $deliveryList, true);
- return Promise.resolve();
- }.bind(this)
- }
- });
- }.bind(this));
- // Setup the handlers for recipient edit boxes
- this._handleRecipientEdit($deliveryList, $emailRecipientsList, this._addEmailAddress.bind(this));
- this._handleRecipientEdit($deliveryList, $ccRecipientsList, this._addCCEmailAddress.bind(this));
- this._handleRecipientEdit($deliveryList, $bccRecipientsList, this._addBCCEmailAddress.bind(this));
- var $emailRecipientsEllipsis = $deliveryList.find('#delivery_email_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
- $emailRecipientsEllipsis.addClass('clickBound');
- $emailRecipientsEllipsis.on('clicktap', function(event) {
- event.cancelBubble = true;
- if (event.stopPropagation) {
- event.stopPropagation();
- }
- $emailRecipientsList.addClass('expanded');
- $emailRecipientsEllipsis.hide();
- }.bind(this));
- // Populate
- if (this.deliveryOptions && this.deliveryOptions.email && this.deliveryOptions.email.to && $.isArray(this.deliveryOptions.email.to)) {
- if (this.deliveryOptions.email.to.length !== 0) {
- this._addEmailRecipients(this.deliveryOptions.email.to, $deliveryList, false);
- } else {
- //Populate the to field with the default logged in user name if user has an email adrress set in the authentication name space
- if ( this.glassContext.profile.account && this.glassContext.profile.account.defaultName && this.glassContext.profile.account.email ) {
- var defaultRecipientData = [{
- 'defaultName': this.glassContext.profile.account.defaultName,
- 'address': this.glassContext.profile.account.email,
- 'type': t.translate('currentUser'),
- 'id': _.uniqueId('recipientId_')
- }];
- this._addEmailRecipients(defaultRecipientData, $deliveryList);
- }
- }
- }
- // CC Recipients
- var $ccRecipientsInput = $deliveryList.find('.delivery_cc_section');
- var $ccRecipientsLabel = $ccRecipientsInput.find('.schedule_delivery_header:not(.clickBound)');
- $ccRecipientsLabel.addClass('clickBound');
- $ccRecipientsLabel.on('clicktap', function() {
- this.glassContext.appController.showSlideOut({
- 'position': 'right',
- 'overlay': true,
- 'parent': this.slideout,
- 'width': this.slideout.width,
- 'label': t.translate('schedule_delivery_accounts_aria_label'),
- 'content': {
- 'module': 'bi/schedule/views/AccountPickerSlideoutView',
- 'glassContext': this.glassContext,
- 'addCallback': function(selectedItems) {
- var values = Object.keys(selectedItems).map(function(key) {
- return selectedItems[key]
- });
- this._addCCRecipients(values, $deliveryList, true);
- return Promise.resolve();
- }.bind(this)
- }
- });
- }.bind(this));
- var $ccRecipientsEllipsis = $deliveryList.find('#delivery_cc_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
- $ccRecipientsEllipsis.addClass('clickBound');
- $ccRecipientsEllipsis.on('clicktap', function(event) {
- event.cancelBubble = true;
- if (event.stopPropagation) {
- event.stopPropagation();
- }
- $ccRecipientsList.addClass('expanded');
- $ccRecipientsEllipsis.hide();
- }.bind(this));
- //Toggler
- var $ccToggler = $deliveryList.find('.delivery_cc_toggler:not(.clickBound)');
- $ccToggler.addClass('clickBound');
- $ccToggler.on('clicktap', function(){
- $ccToggler.hide();
- $deliveryList.find('.delivery_cc_section').show(__STANDARD_DELAY);
- }.bind(this));
- //POPULATE
- if (this.deliveryOptions && this.deliveryOptions.email && this.deliveryOptions.email.cc && $.isArray(this.deliveryOptions.email.cc)) {
- if (this.deliveryOptions.email.cc.length === 0) {
- $ccRecipientsInput.hide();
- } else {
- $ccToggler.hide();
- //Add them
- this._addCCRecipients(this.deliveryOptions.email.cc, $deliveryList, false);
- }
- } else {
- $ccRecipientsInput.hide();
- }
- // BCC Recipients
- var $bccRecipientsInput = $deliveryList.find('.delivery_bcc_section');
- var $bccRecipientsLabel = $bccRecipientsInput.find('.schedule_delivery_header:not(.clickBound)');
- $bccRecipientsLabel.addClass('clickBound');
- $bccRecipientsLabel.on('clicktap', function() {
- this.glassContext.appController.showSlideOut({
- 'position': 'right',
- 'overlay': true,
- 'parent': this.slideout,
- 'width': this.slideout.width,
- 'label': t.translate('schedule_delivery_accounts_aria_label'),
- 'content': {
- 'module': 'bi/schedule/views/AccountPickerSlideoutView',
- 'glassContext': this.glassContext,
- 'addCallback': function(selectedItems) {
- var values = Object.keys(selectedItems).map(function(key) {
- return selectedItems[key]
- });
- this._addBCCRecipients(values, $deliveryList, true);
- return Promise.resolve();
- }.bind(this)
- }
- });
- }.bind(this));
- var $bccRecipientsEllipsis = $deliveryList.find('#delivery_bcc_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
- $bccRecipientsEllipsis.addClass('clickBound');
- $bccRecipientsEllipsis.on('clicktap', function(event) {
- event.cancelBubble = true;
- if (event.stopPropagation) {
- event.stopPropagation();
- }
- $bccRecipientsList.addClass('expanded');
- $bccRecipientsEllipsis.hide();
- }.bind(this));
- //Toggler
- var $bccToggler = $deliveryList.find('.delivery_bcc_toggler:not(.clickBound)');
- $bccToggler.addClass('clickBound');
- $bccToggler.on('clicktap', function(){
- $bccToggler.hide();
- $deliveryList.find('.delivery_bcc_section').show(__STANDARD_DELAY);
- }.bind(this));
- //POPULATE
- if (this.deliveryOptions && this.deliveryOptions.email && this.deliveryOptions.email.bcc && $.isArray(this.deliveryOptions.email.bcc)) {
- if (this.deliveryOptions.email.bcc.length === 0) {
- $bccRecipientsInput.hide();
- } else {
- $bccToggler.hide();
- //Add them
- this._addBCCRecipients(this.deliveryOptions.email.bcc, $deliveryList, false);
- }
- } else {
- $bccRecipientsInput.hide();
- }
- var $emailRecipientLabel = $deliveryList.find('label[for="delivery_email_recipients_edit_field_' + this.contentUniqueId+ '"]');
- var $ccRecipientLabel = $deliveryList.find('label[for="delivery_cc_recipients_edit_field_' + this.contentUniqueId+ '"]');
- var $bccRecipientLabel = $deliveryList.find('label[for="delivery_bcc_recipients_edit_field_' + this.contentUniqueId+ '"]');
- // Closing each list if not clicked on them
- if (!$(document).data('setemail')) {
- $(document).data('setemail', true).on('clicktap', function(event) {
- // Collapse email Recipients
- if (!$emailRecipientsInput.is(event.target) && $emailRecipientsInput.has(event.target).length === 0) {
- $emailRecipientsList.removeClass('expanded');
- this._checkForEllipsis($emailRecipientsList, $emailRecipientLabel, function(show) {
- if (show) {
- $emailRecipientsEllipsis.show(__STANDARD_DELAY);
- } else {
- $emailRecipientsEllipsis.hide(__STANDARD_DELAY);
- }
- }.bind(this));
- }
- // Collapse cc Recipients
- if (!$ccRecipientsInput.is(event.target) && $ccRecipientsInput.has(event.target).length === 0) {
- $ccRecipientsList.removeClass('expanded');
- this._checkForEllipsis($ccRecipientsList, $ccRecipientLabel, function(show) {
- if (show) {
- $ccRecipientsEllipsis.show(__STANDARD_DELAY);
- } else {
- $ccRecipientsEllipsis.hide(__STANDARD_DELAY);
- }
- }.bind(this));
- }
- // Collapse bcc Recipients
- if (!$bccRecipientsInput.is(event.target) && $bccRecipientsInput.has(event.target).length === 0) {
- $bccRecipientsList.removeClass('expanded');
- this._checkForEllipsis($bccRecipientsList, $bccRecipientLabel, function(show) {
- if (show) {
- $bccRecipientsEllipsis.show(__STANDARD_DELAY);
- } else {
- $bccRecipientsEllipsis.hide(__STANDARD_DELAY);
- }
- }.bind(this));
- }
- }.bind(this));
- }
- },
- _validateEmail: function(address) {
- var emailRegEx = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~])*@[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$/;
- return address.match(emailRegEx);
- },
- _handleRecipientEdit: function($deliveryList, $recipientsList, addCallback) {
- var $recipientsEdit = $recipientsList.find('.delivery_recipients_edit_box');
- $recipientsEdit.on('keydown', function(event) {
- var keyCode = event.keyCode || event.which;
- if (event.target.value.length > 0) {
- // tab, enter, comma or semi-colon
- if ( keyCode == 9 || keyCode == 13 || keyCode == 188 || keyCode == 186) {
- addCallback(event.target.value, $deliveryList, $recipientsList);
- $recipientsEdit.val('');
- event.preventDefault();
- }
- } else {
- // handle backspace to delete
- if ( keyCode == 8) {
- var $prev = $recipientsList.find('.delivery_recipient:last');
- if ($prev.length !== 0) {
- this._removeRecipient($deliveryList, $prev);
- }
- event.preventDefault();
- }
- }
- }.bind(this));
- $recipientsEdit.on('paste', function(event) {
- setTimeout(function() {
- var emailList = this._checkForMultipleEmails(event.target.value);
- _.each(emailList,function(email) {
- addCallback(email, $deliveryList, $recipientsList);
- });
- $recipientsEdit.val('');
- }.bind(this), 0);
- }.bind(this));
- // Automatically add the current recipient when focus is lost
- $recipientsEdit.on('focusout', function(event) {
- if (event.target.value.length > 0) {
- addCallback(event.target.value, $deliveryList, $recipientsList);
- $recipientsEdit.val('');
- }
- }.bind(this));
- // prevent expanded input from collapsing when input box is selected
- $recipientsEdit.on('clicktap', function(event) {
- event.preventDefault();
- return false;
- }.bind(this));
- },
- _checkForMultipleEmails: function(input) {
- var emailList = input.split(/,|;/);
- return emailList;
- },
- _addAddress: function(address, $deliveryList, $emailRecipientsList) {
- var recipientData = [{
- defaultName: address,
- address: address,
- type: address,
- id: _.uniqueId('recipientId_')
- }];
- var listAttrs = {
- recipients: recipientData,
- removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
- invalidLabel : t.translate("schedule_delivery_invalid_address")
- };
- var list = dot.simpleTemplate(recipientsListTemplate);
- var $recipientList = $(list(listAttrs));
- if (this._validateEmail(address)) {
- $recipientList.find('.delivery_recipient_underline').hide();
- } else {
- $recipientList.find('.delivery_recipient_underline').show();
- }
- $emailRecipientsList.find('.delivery_recipients_edit_field').before($recipientList);
- if (!$emailRecipientsList.hasClass('expanded')) {
- var $recipientsLabel = $deliveryList.find('label[for="' + $emailRecipientsList.id + '"]');
- if ($emailRecipientsList.prop('scrollHeight') > $recipientsLabel.height()*1.25) {
- $emailRecipientsList.addClass('expanded');
- }
- }
- this.setIcons($recipientList);
- return recipientData;
- },
- _addEmailAddress: function(address, $deliveryList, $emailRecipientsList) {
- var recipientData = this._addAddress(address, $deliveryList, $emailRecipientsList);
- // update lists
- this.email.to = this.email.to.slice().concat(recipientData);
- this._updateEmailRecipients($deliveryList);
- this._setRecipientsListEvents($deliveryList);
- },
- _addCCEmailAddress: function(address, $deliveryList, $ccRecipientsList) {
- var recipientData = this._addAddress(address, $deliveryList, $ccRecipientsList);
- // update lists
- this.email.cc = this.email.cc.slice().concat(recipientData);
- this._updateCCRecipients($deliveryList);
- this._setRecipientsListEvents($deliveryList);
- },
- _addBCCEmailAddress: function(address, $deliveryList, $bccRecipientsList) {
- var recipientData = this._addAddress(address, $deliveryList, $bccRecipientsList);
- // update lists
- this.email.bcc = this.email.bcc.slice().concat(recipientData);
- this._updateBCCRecipients($deliveryList);
- this._setRecipientsListEvents($deliveryList);
- },
- _addEmailRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
- var recipientData = [];
- var data;
- if (manuallyAdded) {
- data = this._verifyNewRecipients(recipients, this.email.to.slice()) || [];
- } else {
- this.email.to = [];
- data = recipients || [];
- }
- for (var i=0; i<data.length;i++) {
- recipientData.push({
- defaultName: data[i].defaultName || "",
- address: data[i].searchPath || data[i].address || "",
- type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
- id: _.uniqueId('recipientId_')
- });
- }
- var listAttrs = {
- recipients: recipientData,
- removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
- invalidLabel : t.translate("schedule_delivery_invalid_address")
- };
- var list = dot.simpleTemplate(recipientsListTemplate);
- var recipientList = $(list(listAttrs));
- $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId + ' .delivery_recipients_edit_field').before(recipientList);
- // update lists
- this.email.to = this.email.to.slice().concat(recipientData);
- this._updateEmailRecipients($deliveryList);
- if (manuallyAdded) {
- if (recipientData.length === 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
- } else if ( recipientData.length > 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
- }
- }
- this.setIcons(recipientList);
- this._setRecipientsListEvents($deliveryList);
- },
- _addCCRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
- var recipientData = [];
- var data ;
- if (manuallyAdded) {
- data = this._verifyNewRecipients(recipients, this.email.cc.slice()) || [];
- } else {
- this.email.cc = [];
- data = recipients || [];
- }
- for (var i=0; i<data.length;i++) {
- recipientData.push({
- defaultName: data[i].defaultName || "",
- address: data[i].searchPath || data[i].address || "",
- type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
- id: _.uniqueId('recipientId_')
- });
- }
- var listAttrs = {
- recipients: recipientData,
- removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
- invalidLabel : t.translate("schedule_delivery_invalid_address")
- };
- var list = dot.simpleTemplate(recipientsListTemplate);
- var recipientList = $(list(listAttrs));
- $deliveryList.find('#delivery_cc_recipients_' + this.contentUniqueId + ' .delivery_recipients_edit_field').before(recipientList);
- // update lists
- this.email.cc = this.email.cc.slice().concat(recipientData);
- this._updateCCRecipients($deliveryList);
- if (manuallyAdded) {
- if (recipientData.length === 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
- } else if ( recipientData.length > 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
- }
- }
- this.setIcons(recipientList);
- this._setRecipientsListEvents($deliveryList);
- },
- _addBCCRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
- var recipientData = [];
- var data;
- if (manuallyAdded) {
- data = this._verifyNewRecipients(recipients, this.email.bcc.slice()) || [];
- } else {
- this.email.bcc = [];
- data = recipients || [];
- }
- for (var i=0; i<data.length;i++) {
- recipientData.push({
- defaultName: data[i].defaultName || "",
- address: data[i].searchPath || data[i].address || "",
- type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
- id: _.uniqueId('recipientId_')
- });
- }
- var listAttrs = {
- recipients: recipientData,
- removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
- invalidLabel : t.translate("schedule_delivery_invalid_address")
- };
- var list = dot.simpleTemplate(recipientsListTemplate);
- var recipientList = $(list(listAttrs));
- $deliveryList.find('#delivery_bcc_recipients_' + this.contentUniqueId + ' .delivery_recipients_edit_field').before(recipientList);
- // update lists
- this.email.bcc = this.email.bcc.slice().concat(recipientData);
- this._updateBCCRecipients($deliveryList);
- if (manuallyAdded) {
- if (recipientData.length === 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
- } else if ( recipientData.length > 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
- }
- }
- this.setIcons(recipientList);
- this._setRecipientsListEvents($deliveryList);
- },
- _addMobileRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
- var recipientData = [];
- var data;
- if (manuallyAdded) {
- data = this._verifyNewRecipients(recipients, this.mobile.to.slice()) || [];
- } else {
- this.mobile.to = [];
- data = recipients || [];
- }
- for (var i=0; i<data.length;i++) {
- recipientData.push({
- defaultName: data[i].defaultName || "",
- address: data[i].searchPath || data[i].address || "",
- type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
- id: _.uniqueId('recipientId_')
- });
- }
- var listAttrs = {
- recipients: recipientData,
- removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
- invalidLabel : t.translate("schedule_delivery_invalid_address")
- };
- var list = dot.simpleTemplate(recipientsListTemplate);
- var recipientList = $(list(listAttrs));
- $deliveryList.find('#delivery_mobile_recipients_' + this.contentUniqueId).append(recipientList);
- // update lists
- this.mobile.to = this.mobile.to.slice().concat(recipientData);
- this._updateMobileRecipients($deliveryList);
- if (manuallyAdded) {
- if (recipientData.length === 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
- } else if ( recipientData.length > 1) {
- this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
- }
- }
- this.setIcons(recipientList);
- this._setRecipientsListEvents($deliveryList);
- },
- _verifyNewRecipients: function(incomingRecipients, recipientsList) {
- var newRecipients = [];
- for (var i = 0; i < incomingRecipients.length; i++) {
- var newId = true;
- for (var j = 0; j < recipientsList.length; j++) {
- if (incomingRecipients[i].searchPath === recipientsList[j].address ||
- incomingRecipients[i].address === recipientsList[j].address ) {
- newId = false;
- break;
- }
- }
- if (newId) {
- newRecipients.push(incomingRecipients[i]);
- }
- }
- return newRecipients;
- },
- _setRecipientsListEvents: function($deliveryList) {
- var recipients = $deliveryList.find('.delivery_recipient:not(.clickBound)');
- recipients.addClass('clickBound');
- recipients.on('clicktap', function(event) {
- event.cancelBubble = true;
- if (event.stopPropagation) {
- event.stopPropagation();
- }
- });
- var recipientsDeleteButton = $deliveryList.find('.delivery_delete_recipient_icon:not(.clickBound)');
- recipientsDeleteButton.addClass('clickBound');
- recipientsDeleteButton.on('clicktap', function(event) {
- event.cancelBubble = true;
- if (event.stopPropagation) {
- event.stopPropagation();
- }
- var $recipient = $(event.target).closest('.delivery_recipient');
- this._removeRecipient($deliveryList, $recipient);
- }.bind(this));
- },
- _removeRecipient: function ($deliveryList, $recipient) {
- var recipientId = $recipient.attr('id');
- var recipientType = $recipient.closest('.delivery_recipients_field').data('recipienttype');
- $recipient.hide(__STANDARD_DELAY);
- $recipient.remove();
- switch(recipientType) {
- case "email":
- this.email.to = this._removeRecipientFromList(recipientId, this.email.to.slice());
- // update deliveryoptions
- this._updateEmailRecipients($deliveryList);
- break;
- case "cc":
- this.email.cc = this._removeRecipientFromList(recipientId, this.email.cc.slice());
- // update deliveryoptions
- this._updateCCRecipients($deliveryList);
- break;
- case "bcc":
- this.email.bcc = this._removeRecipientFromList(recipientId, this.email.bcc.slice());
- // update deliveryoptions
- this._updateBCCRecipients($deliveryList);
- break;
- case "mobile":
- this.mobile.to = this._removeRecipientFromList(recipientId, this.mobile.to.slice());
- // update deliveryoptions
- this._updateMobileRecipients($deliveryList);
- break;
- default:
- break;
- }
- },
- _removeRecipientFromList: function(id, list) {
- var index = -1;
- for (var i = 0; i < list.length; i++) {
- if (id === list[i].id) {
- index = i;
- break;
- }
- }
- if (index >= 0) {
- list.splice(index, 1);
- }
- var newList = list;
- return newList;
- },
- _updateEmailRecipients: function($deliveryList) {
- var $emailRecipientsEllipsis = $deliveryList.find('#delivery_email_ellipsis_' + this.contentUniqueId);
- var $emailRecipientsList = $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId);
- var $emailRecipientLabel = $deliveryList.find('label[for="delivery_email_recipients_edit_field_' + this.contentUniqueId+ '"]');
- //update deliveryoptions
- this.deliveryOptions.email.to = this.email.to.slice();
- //Show ellipsis
- this._checkForEllipsis($emailRecipientsList, $emailRecipientLabel, function(show) {
- if (show) {
- if (!$emailRecipientsList.hasClass('expanded')) {
- $emailRecipientsEllipsis.show(__STANDARD_DELAY);
- }
- } else {
- $emailRecipientsEllipsis.hide(__STANDARD_DELAY);
- $emailRecipientsList.removeClass('expanded');
- }
- }.bind(this));
- },
- _updateCCRecipients: function($deliveryList) {
- var $ccRecipientsEllipsis = $deliveryList.find('#delivery_cc_ellipsis_' + this.contentUniqueId);
- var $ccRecipientsList = $deliveryList.find('#delivery_cc_recipients_' + this.contentUniqueId);
- var $ccRecipientLabel = $deliveryList.find('label[for="delivery_cc_recipients_edit_field_' + this.contentUniqueId+ '"]');
- //update deliveryoptions
- this.deliveryOptions.email.cc = this.email.cc.slice();
- //Show ellipsis
- this._checkForEllipsis($ccRecipientsList, $ccRecipientLabel, function(show) {
- if (show) {
- if (!$ccRecipientsList.hasClass('expanded')) {
- $ccRecipientsEllipsis.show(__STANDARD_DELAY);
- }
- } else {
- $ccRecipientsEllipsis.hide(__STANDARD_DELAY);
- $ccRecipientsList.removeClass('expanded');
- }
- }.bind(this));
- },
- _updateBCCRecipients: function($deliveryList) {
- var $bccRecipientsEllipsis = $deliveryList.find('#delivery_bcc_ellipsis_' + this.contentUniqueId);
- var $bccRecipientsList = $deliveryList.find('#delivery_bcc_recipients_' + this.contentUniqueId);
- var $bccRecipientLabel = $deliveryList.find('label[for="delivery_bcc_recipients_edit_field_' + this.contentUniqueId+ '"]');
- //update deliveryoptions
- this.deliveryOptions.email.bcc = this.email.bcc.slice();
- //Show ellipsis
- this._checkForEllipsis($bccRecipientsList, $bccRecipientLabel, function(show) {
- if (show) {
- if (!$bccRecipientsList.hasClass('expanded')) {
- $bccRecipientsEllipsis.show(__STANDARD_DELAY);
- }
- } else {
- $bccRecipientsEllipsis.hide(__STANDARD_DELAY);
- $bccRecipientsList.removeClass('expanded');
- }
- }.bind(this));
- },
- _updateMobileRecipients: function($deliveryList) {
- var $mobileRecipientsEllipsis = $deliveryList.find('#delivery_mobile_ellipsis_' + this.contentUniqueId);
- var $mobileRecipientsList = $deliveryList.find('#delivery_mobile_recipients_' + this.contentUniqueId);
- var $mobileRecipientLabel = $deliveryList.find('label[for="delivery_mobile_recipients_' + this.contentUniqueId+ '"]');
- //update deliveryoptions
- this.deliveryOptions.mobile.to = this.mobile.to.slice();
- //Show ellipsis
- this._checkForEllipsis($mobileRecipientsList, $mobileRecipientLabel, function(show) {
- if (show) {
- if (!$mobileRecipientsList.hasClass('expanded')) {
- $mobileRecipientsEllipsis.show(__STANDARD_DELAY);
- }
- } else {
- $mobileRecipientsEllipsis.hide(__STANDARD_DELAY);
- $mobileRecipientsList.removeClass('expanded');
- }
- }.bind(this));
- },
- _checkForEllipsis: function($list, $reference, callback, counter) { //NOSONAR
- var rightXPositionOfRecipientField = $list.offset().left + $list.width();
- //Not typein and not adding via the CA_AccountPickerView, the initial list is empty so no ellipes
- if ($list.width() === 1) {
- return;
- }
- if (!counter) {
- counter = 0;
- }
- //Removes the invisible span. This is required so that there are no "invisible gaps" when list content gets moved around
- $list.find("#invisibleSpan").remove();
- var insertedInvisibleSpan = false;
- if (($list.prop('scrollHeight') !== 0 && $reference.height() !== 0) || counter > 10) {
- if ($list.prop('scrollHeight') > $reference.height()*1.25) {
- if (typeof callback === 'function') {
- callback(true);
- }
- //if the ellipse is showing
- if (!$list.hasClass("expanded")){
- $list.find(".delivery_recipient").each(function() {
- //if a recipient div overlaps the ellipse span, insert an invisible span before the recipient div so that it gets pushed to the next line
- //the number 30 is an approximation of the width of the ellipse span
- //only do this if it has not been completed already (because ellipse only appears on first line)
- if ((($(this).offset().left + $(this).width()) > (rightXPositionOfRecipientField - 30) ) && ($(this).position().top === 0) && !insertedInvisibleSpan ){ //NOSONAR
- $(this).before("<span id='invisibleSpan' style='width:30px; height:30px; visability:hidden'> </span>");
- insertedInvisibleSpan = true;
- }
- });
- }
- } else {
- if (typeof callback === 'function') {
- callback(false);
- }
- }
- } else {
- var delay = __STANDARD_DELAY;
- setTimeout(function() {
- this._checkForEllipsis($list, $reference, callback, counter+1);
- }.bind(this), delay);
- }
- },
- _cleanRecipientsArray: function(list) {
- var cleanArray = [];
- for (var i = 0; i < list.length; i++) {
- cleanArray.push({
- address: list[i].address,
- defaultName: list[i].defaultName,
- type: (list[i].type)? t.translate(list[i].type) : ((list[i].address)? list[i].address : ""),
- });
- }
- return cleanArray;
- },
- _setEditorDialogHideHandler: function() {
- if (!$('body').hasClass('editorHideHandlerSet')) {
- $('body').addClass('editorHideHandlerSet').on('clicktap.ckeditorDialog', function(event) {
- var editorDialogs = $('body').find('.cke_dialog');
- var editorDialogBg = $('body').find('.cke_dialog_background_cover');
- if ((editorDialogs.is(event.target) || editorDialogs.has(event.target).length > 0) || (editorDialogBg.is(event.target) || editorDialogBg.has(event.target).length > 0)) {
- event.stopPropagation();
- }
- });
- }
- }
- });
- return deliveryPickerView;
- });
|