DeliveryPickerView.js 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  1. /*
  2. * Licensed Materials - Property of IBM
  3. * IBM Cognos Products: SHARE
  4. * (C) Copyright IBM Corp. 2015, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure
  6. * restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define([
  9. 'jquery',
  10. 'underscore',
  11. 'bi/sharecommon/utils/simpledoT',
  12. 'q',
  13. 'ckeditor',
  14. 'ckeditor/jquery',
  15. 'bi/commons/ui/View',
  16. 'bi/schedule/app/appControler',
  17. 'bi/sharecommon/utils/translator',
  18. 'bi/commons/utils/Utils',
  19. 'bi/commons/ui/properties/PropertyUIControl',
  20. 'bi/commons/utils/ContentFormatter',
  21. 'bi/schedule/utils/TextFormatter',
  22. 'text!bi/schedule/templates/DeliveryPickerOptions.html',
  23. 'text!bi/schedule/templates/RecipientsList.html',
  24. 'bi/commons/ui/properties/CheckBox',
  25. 'bi/commons/ui/properties/RadioButtonGroup',
  26. 'bootstrap'
  27. ], function($, _, dot, Q, ckeditor, jckeditor, View, controller, t, Utils, PropertyUIControl, stringFormatter, TextFormatter, optionsTemplate, recipientsListTemplate, CheckBox, RadioButtonGroup) { //NOSONAR
  28. 'use strict'; //NOSONAR
  29. /* deliveryOptions look like:
  30. * {
  31. * save: {
  32. * "notify": false
  33. * },
  34. * email: {
  35. * "emailAsAttachment": false,
  36. * "emailAsURL": false,
  37. * "subject": "blah",
  38. * "memoPart": "this is the body",
  39. * "to": "CAMID ()",
  40. * "cc": ,
  41. * "bcc": ,
  42. * },
  43. * mobile: {
  44. * "to":
  45. * },
  46. * print: {
  47. * printer: ""
  48. * },
  49. * archive: {
  50. * filenameStub: "filename",
  51. * location: /configuration/archiveLocation[@name='test'], //Using of "storeID('id')" is deprecated starting Helios R9
  52. * conflictResolution: "fail(keep)"|"replace(default"|"appendDateTime"|"appendSequenceNumber"
  53. * }
  54. * }
  55. */
  56. var __STANDARD_DELAY = 500;
  57. var __EMPTY_MESSAGE_BODY = "<html><body></body></html>";
  58. var deliveryPickerView = View.extend({
  59. /*
  60. * Constructor
  61. *
  62. * options: {
  63. * $el: {},
  64. * deliveryOptions: {},
  65. * reportName: string,
  66. * isEditMode: boolean
  67. */
  68. init: function(options, $outputDiv) { //NOSONAR
  69. deliveryPickerView.inherited('init', this, arguments);
  70. this.reportName = "";
  71. this.isEditMode = false;
  72. this.enableAdvancedSettings = false;
  73. this.deliveryOptions = {};
  74. this.overlay = false;
  75. this.showMobile = true;
  76. this.s3Connection = '';
  77. this.showSaveToFileSystem = true;
  78. var s3Loc = this._initS3Loc(options);
  79. this.s3SaveToCloud = (s3Loc) && (s3Loc !== '');
  80. if (this.s3SaveToCloud) {
  81. this.s3Location = s3Loc.value;
  82. var s3ReportName = this._initS3ReportName(options);
  83. if (s3ReportName) {
  84. this.s3ReportName = s3ReportName.value;
  85. }
  86. }
  87. this.canSave = true;
  88. this._icons = {
  89. email: 'email',
  90. print: 'print_icon',
  91. mobile: 'mobile_icon',
  92. save: 'save',
  93. archive: 'saveExternal',
  94. saveToCloud: 'saveExternal'
  95. };
  96. this._archiveLocations = [];
  97. if (options.reportName === undefined) {
  98. throw "Error: report name parameter must be provided.";
  99. }
  100. if (options.glassContext === undefined) {
  101. throw "Error: glassContext parameter must be provided.";
  102. }
  103. if (options.$toggler === undefined) {
  104. throw "Error: $toggler parameter must be provided.";
  105. }
  106. $.extend(this, options);
  107. this.notifyOnSave = !this.enableAdvancedSettings || false;
  108. if (options.deliveryOptions && options.deliveryOptions.save) {
  109. this.notifyOnSave = options.deliveryOptions.save.notify;
  110. }
  111. this.save = {
  112. notify: this.notifyOnSave
  113. };
  114. this.print = {
  115. name: ""
  116. };
  117. this.archive = {
  118. filenameStub: this.reportName,
  119. location: "",
  120. conflictResolution: "replace"
  121. };
  122. // if no permission passed in, assume full rights (subscribe case)
  123. if (options.hasPermission === undefined) {
  124. this.hasPermission = {
  125. write: true
  126. };
  127. }
  128. this.canSave = (this.hasPermission.write || _.contains(this.hasPermission, "write")) ? true : false;
  129. // Default the deliveryOptions to just Save, unless user does not have Write permission
  130. if ( ( !options.deliveryOptions || $.isEmptyObject(options.deliveryOptions ) && !this._hasSaveToCloudOption())) {
  131. if (this.canSave) {
  132. this.deliveryOptions = {
  133. save: {
  134. notify: this.notifyOnSave
  135. }
  136. };
  137. } else {
  138. this.deliveryOptions = {
  139. print: {
  140. name: ""
  141. }
  142. };
  143. }
  144. }
  145. if (!this.enableAdvancedSettings) {
  146. this.email = {
  147. emailAsAttachment: !this.canSave,
  148. emailAsURL: this.canSave,
  149. subject: "",
  150. memoPart: ""
  151. };
  152. this.mobile = {};
  153. }
  154. else {
  155. this.email = {
  156. emailAsAttachment: !this.canSave,
  157. emailAsURL: this.canSave,
  158. subject: "",
  159. memoPart: "",
  160. to: [],
  161. bcc: [],
  162. cc: []
  163. };
  164. this.mobile = {
  165. to: []
  166. };
  167. }
  168. if (!this.isEditMode) {
  169. this.email.subject = t.translate("subscription_email_subject", {
  170. report_name: this.reportName
  171. });
  172. if (!this.enableAdvancedSettings) {
  173. this.email.memoPart = '<html><body><p>' + t.translate("subscription_email_body") + '</p></body></html>';
  174. }
  175. } else if (this.isEditMode && !this.enableAdvancedSettings) {
  176. // Set defaults for subscription delivery
  177. this.email.subject = t.translate("subscription_email_subject", {
  178. report_name: this.reportName
  179. });
  180. this.email.memoPart = '<html><body><p>' + t.translate("subscription_email_body") + '</p></body></html>';
  181. if (this.deliveryOptions.email){
  182. this.deliveryOptions.email.subject = t.translate("subscription_email_subject", {
  183. report_name: this.reportName
  184. });
  185. this.deliveryOptions.email.memoPart = '<html><body><p>' + t.translate("subscription_email_body") + '</p></body></html>';
  186. }
  187. }
  188. },
  189. _initS3Loc: function(options) {
  190. if (options.deliveryOptions.saveToCloud) {
  191. var s3Details = {
  192. value: options.deliveryOptions.cloudLocation
  193. };
  194. return s3Details;
  195. }
  196. return _.find(options.rawOptions, function(anOpt){ return anOpt.name === 'runOptionEnum#saveToCloud'; });
  197. },
  198. _initS3ReportName: function(options) {
  199. if (options.deliveryOptions.cloudName) {
  200. var s3ReportNameDetails = {
  201. value: options.deliveryOptions.cloudName
  202. };
  203. return s3ReportNameDetails;
  204. }
  205. return _.find(options.rawOptions, function(anOpt){ return anOpt.name === 'runOptionEnum#cloudName'; });
  206. },
  207. close: function() {
  208. $(document).removeData(['setemail','setmobile']);
  209. },
  210. /**
  211. * Render is the main function of the Content View. Content Views should implement (override) the render
  212. * method to populate this.el with the appropriate HTML. Render should always return this as a promise
  213. * to allow chaining of calls.
  214. * @returns (Promise)
  215. */
  216. render: function() {
  217. return Q();
  218. },
  219. getDeliveryOptions: function() { //NOSONAR
  220. if (this.deliveryOptions.email) {
  221. 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
  222. delete this.deliveryOptions.email.memoPart;
  223. }
  224. if (this.deliveryOptions.email.to && this.deliveryOptions.email.to.length > 0) {
  225. this.deliveryOptions.email.to = this._cleanRecipientsArray(this.deliveryOptions.email.to.slice());
  226. }
  227. if (this.deliveryOptions.email.cc && this.deliveryOptions.email.cc.length > 0) {
  228. this.deliveryOptions.email.cc = this._cleanRecipientsArray(this.deliveryOptions.email.cc.slice());
  229. }
  230. if (this.deliveryOptions.email.bcc && this.deliveryOptions.email.bcc.length > 0) {
  231. this.deliveryOptions.email.bcc = this._cleanRecipientsArray(this.deliveryOptions.email.bcc.slice());
  232. }
  233. }
  234. if (this.deliveryOptions.mobile && this.deliveryOptions.mobile.to && this.deliveryOptions.mobile.to.length > 0) {
  235. this.deliveryOptions.mobile.to = this._cleanRecipientsArray(this.deliveryOptions.mobile.to.slice());
  236. }
  237. if (this._isSaveToCloudOptionsSelected()) {
  238. var cloudOptions = this.getCloudOptions();
  239. if (cloudOptions.location) {
  240. this.deliveryOptions.cloudLocation = cloudOptions.location;
  241. if (cloudOptions.cloudReportName) {
  242. this.deliveryOptions.cloudName = cloudOptions.cloudReportName;
  243. }
  244. }
  245. } else {
  246. delete this.deliveryOptions.cloudLocation;
  247. delete this.deliveryOptions.cloudName;
  248. }
  249. return this.deliveryOptions;
  250. },
  251. getDeliveryContent: function(allowRecipients) {
  252. var htmlGenerator = dot.simpleTemplate(optionsTemplate);
  253. if (typeof allowRecipients !== "boolean") {
  254. // default to true
  255. allowRecipients = true;
  256. }
  257. this.contentUniqueId = _.uniqueId('id_');
  258. var attributes = {
  259. schedule_delivery_s3ReportName_label: t.translate('schedule_delivery_s3ReportName_label'),
  260. schedule_delivery_s3ConnectionName_label: t.translate('schedule_delivery_s3ConnectionName_label'),
  261. schedule_delivery_s3LocationName_label: t.translate('schedule_delivery_s3LocationName_label'),
  262. schedule_delivery_printer_name_label: t.translate("schedule_delivery_printer_name_label"),
  263. schedule_name_label: t.translate("schedule_name_label"),
  264. schedule_delivery_location_label: t.translate("schedule_delivery_location_label"),
  265. schedule_delivery_conflict_resolution_label: t.translate("schedule_delivery_conflict_resolution_label"),
  266. showSaveToFileSystem: this.showSaveToFileSystem,
  267. advanced: this.enableAdvancedSettings,
  268. schedule_delivery_recipient_label: t.translate("schedule_delivery_recipient_label"),
  269. schedule_delivery_subject_label: t.translate("schedule_delivery_subject_label"),
  270. schedule_delivery_cc_label: t.translate("schedule_delivery_cc_label"),
  271. schedule_delivery_bcc_label: t.translate("schedule_delivery_bcc_label"),
  272. schedule_done_btn: t.translate("schedule_delivery_done_label"),
  273. uniqueid: this.contentUniqueId,
  274. showMobile: this.showMobile,
  275. allowRecipients: allowRecipients
  276. };
  277. return htmlGenerator(attributes);
  278. },
  279. setCloudEvents: function($deliveryList) {
  280. var reportNameEl = $deliveryList.find('#delivery_saveToS3_reportName_' + this.contentUniqueId);
  281. var cloudOptions = this.getCloudOptions();
  282. if (cloudOptions.cloudReportName) {
  283. reportNameEl.val(cloudOptions.cloudReportName);
  284. } else if (cloudOptions.reportName) {
  285. reportNameEl.val(cloudOptions.reportName);
  286. } else {
  287. reportNameEl.val(this.reportName);
  288. }
  289. reportNameEl.on('change', function(){ this.cloudReportName = reportNameEl.val();}.bind(this));
  290. },
  291. _renderOptions: function($selectEl, optionList) {
  292. $selectEl.empty();
  293. $selectEl.append($('<option>', {
  294. value: '',
  295. text: ''
  296. }));
  297. _.each(optionList, function(item) {
  298. $selectEl.append($('<option>', {
  299. value: item.id,
  300. text: item.defaultName
  301. }));
  302. });
  303. },
  304. _setS3ConnectionOptionsForUpdate: function($deliveryList) {
  305. var locationIDToLookup = this.s3Location;
  306. if (this.cloudLocation) {
  307. locationIDToLookup = this.cloudLocation;
  308. }
  309. controller.getS3LocationParentConnectionID(this.glassContext, locationIDToLookup).done(function(resp) {
  310. if (resp.data[0] && resp.data[0].parent[0] && resp.data[0].parent[0].id) {
  311. var preChosenConnectionID = resp.data[0].parent[0].id;
  312. controller.getS3ConnectionDetails(this.glassContext).done(function(resp) {
  313. var $connectionSelect = $deliveryList.find('.schedule_save_to_file_system_connection_selection');
  314. var $locationSelect = $deliveryList.find('.location-selction-section-select');
  315. var $locationSection = $deliveryList.find('.location-selction-section');
  316. this._renderOptions($connectionSelect, resp.data);
  317. $connectionSelect.val(preChosenConnectionID);
  318. this._handleConnectionChange($connectionSelect, $locationSelect, $locationSection, $deliveryList);
  319. controller.getS3LocationsDetails(this.glassContext, preChosenConnectionID).done(function(resp) {
  320. this._renderOptions($locationSelect, resp.data)
  321. $locationSelect.val(locationIDToLookup);
  322. this._handleLocationChange($locationSelect);
  323. }.bind(this));
  324. }.bind(this));
  325. }
  326. }.bind(this));
  327. },
  328. _handleConnectionChange: function($connectionSelect, $locationSelect, $locationSection, $deliveryList) {
  329. $connectionSelect.change(function() {
  330. $locationSection.hide();
  331. this.cloudConnection = $connectionSelect.val();
  332. $locationSelect.val('');
  333. $locationSelect.empty();
  334. controller.getS3LocationsDetails(this.glassContext, $connectionSelect.val()).done(function(resp) {
  335. this._renderOptions($locationSelect, resp.data);
  336. $locationSection.show();
  337. this._handleLocationChange($locationSelect);
  338. }.bind(this));
  339. }.bind(this));
  340. },
  341. _handleLocationChange: function($locationSelect) {
  342. $locationSelect.change(function() {
  343. this.cloudLocation = $locationSelect.val();
  344. }.bind(this));
  345. },
  346. _setS3ConnectionOptions: function($deliveryList) {
  347. var dfd = Q.defer();
  348. controller.getS3ConnectionDetails(this.glassContext).done(function(resp) {
  349. var $connectionSelect = $deliveryList.find('.schedule_save_to_file_system_connection_selection');
  350. var $locationSelect = $deliveryList.find('.location-selction-section-select');
  351. var $locationSection = $deliveryList.find('.location-selction-section');
  352. $locationSection.hide();
  353. this._handleConnectionChange($connectionSelect, $locationSelect, $locationSection, $deliveryList);
  354. this._handleLocationChange($locationSelect);
  355. this._renderOptions($connectionSelect, resp.data);
  356. dfd.resolve();
  357. }.bind(this));
  358. return dfd.promise;
  359. },
  360. setDeliveryOptions: function($deliveryList, $activeOptionsList) {
  361. var dfd = Q.defer();
  362. // Check if there are archive locations set in configuration to decide if render the savetofilesystem ui
  363. controller.getArchiveLocations(this.glassContext).done(function(result) {
  364. if (result && result.data && result.data.length > 0) {
  365. this._archiveLocations = result.data;
  366. } else {
  367. this.showSaveToFileSystem = false;
  368. }
  369. this._renderCheckBoxes($deliveryList, $activeOptionsList);
  370. this.setCloudEvents($deliveryList);
  371. if (this._isSaveToCloudOptionsSelected()) {
  372. $deliveryList.find('.delivery_s3_options').show(__STANDARD_DELAY);
  373. }
  374. if (this.showSaveToFileSystem) {
  375. this._renderRadioButtonGroup($deliveryList);
  376. }
  377. // Update the pane's ActiveOptionsList list.
  378. if ($activeOptionsList) {
  379. this.updateActiveDeliveryList($activeOptionsList);
  380. }
  381. dfd.resolve();
  382. }.bind(this));
  383. return dfd.promise;
  384. },
  385. getCloudOptions: function() {
  386. var result = {};
  387. if ((this.cloudLocation) && (this.cloudLocation !== '')) {
  388. result.location = this.cloudLocation;
  389. if ((this.cloudReportName) && (this.cloudReportName !== '')) {
  390. result.reportName = this.cloudReportName;
  391. result.cloudReportName = this.cloudReportName;
  392. }
  393. }
  394. // Need this when opening an existing schedule with save to s3 selected
  395. else if (this.s3Location && this.s3Location !== '') {
  396. result.location = this.s3Location;
  397. if (this.cloudReportName && this.cloudReportName !== '') {
  398. result.reportName = this.cloudReportName;
  399. result.cloudReportName = this.cloudReportName;
  400. } else if (this.s3ReportName && this.s3ReportName !== '') {
  401. result.reportName = this.s3ReportName;
  402. result.cloudReportName = this.cloudReportName;
  403. }
  404. }
  405. return result;
  406. },
  407. _isSaveToCloudOptionsSelected: function() {
  408. if ((this.s3SaveToCloud) || (this.cloudLocation) || (this.s3Location)) {
  409. return true;
  410. }
  411. return false;
  412. },
  413. _renderCheckBoxes: function($deliveryList, $activeOptionsList) { //NOSONAR
  414. var emailStatus = false;
  415. var attachmentStatus = false;
  416. var linkStatus = false;
  417. var printStatus = false;
  418. var mobileStatus = false;
  419. var saveStatus = false;
  420. var archiveStatus = false;
  421. // Check off options previously selected
  422. if (this.deliveryOptions.save) {
  423. saveStatus = true;
  424. }
  425. if (this.s3SaveToCloud || this.cloudLocation) {
  426. this._setS3ConnectionOptionsForUpdate($deliveryList);
  427. }
  428. if (this.deliveryOptions.email) {
  429. emailStatus = true;
  430. $deliveryList.find('.delivery_email_options').show();
  431. if (this.deliveryOptions.email.emailAsAttachment) {
  432. this.email.emailAsAttachment = true;
  433. attachmentStatus = true;
  434. } else {
  435. this.email.emailAsAttachment = false;
  436. }
  437. if (this.deliveryOptions.email.emailAsURL) {
  438. this.email.emailAsURL = true;
  439. linkStatus = true;
  440. saveStatus = true;
  441. } else {
  442. this.email.emailAsURL = false;
  443. }
  444. if (this.enableAdvancedSettings) {
  445. this.setAdvancedEmailStoredContent($deliveryList);
  446. }
  447. } else {
  448. $deliveryList.find('.delivery_email_options').hide();
  449. }
  450. if (this.deliveryOptions.mobile) {
  451. mobileStatus = true;
  452. $deliveryList.find('.delivery_mobile_options').show();
  453. if (this.enableAdvancedSettings) {
  454. this.setAdvancedMobileStoredContent($deliveryList);
  455. }
  456. } else {
  457. $deliveryList.find('.delivery_mobile_options').hide();
  458. }
  459. if (this.deliveryOptions.print) {
  460. printStatus = true;
  461. this._setPrinters($deliveryList);
  462. $deliveryList.find('.delivery_print_options').show();
  463. } else {
  464. $deliveryList.find('.delivery_print_options').hide();
  465. }
  466. if (this.deliveryOptions.archive) {
  467. archiveStatus = true;
  468. this.archive.conflictResolution = this.deliveryOptions.archive.conflictResolution;
  469. this._setSaveToFileSystemValues($deliveryList);
  470. $deliveryList.find('.delivery_save_to_file_system_options').show();
  471. } else {
  472. $deliveryList.find('.delivery_save_to_file_system_options').hide();
  473. }
  474. this.emailCheckbox = new CheckBox({
  475. 'id': 'delivery_email_checkbox_' + this.contentUniqueId,
  476. 'el': $deliveryList.find('#delivery_email_container_' + this.contentUniqueId),
  477. 'name': 'delivery_email_option',
  478. 'label': t.translate("schedule_delivery_email_label"),
  479. 'ariaLabel': t.translate("schedule_delivery_email_label"),
  480. 'svgIcon': 'email',
  481. 'checked': emailStatus,
  482. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  483. });
  484. this.attachmentCheckbox = new CheckBox({
  485. 'id': 'delivery_attachment_checkbox_' + this.contentUniqueId,
  486. 'el': $deliveryList.find('#delivery_attachment_container_' + this.contentUniqueId),
  487. 'name': 'delivery_attachment_option',
  488. 'label': t.translate("schedule_delivery_attach_label"),
  489. 'ariaLabel': t.translate("schedule_delivery_attach_label"),
  490. 'checked': attachmentStatus,
  491. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  492. });
  493. this.printCheckbox = new CheckBox({
  494. 'id': 'delivery_print_checkbox_' + this.contentUniqueId,
  495. 'el': $deliveryList.find('#delivery_print_container_' + this.contentUniqueId),
  496. 'name': 'delivery_print_option',
  497. 'label': t.translate("schedule_delivery_print_label"),
  498. 'ariaLabel': t.translate("schedule_delivery_print_label"),
  499. 'svgIcon': 'print_icon',
  500. 'checked': printStatus,
  501. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  502. });
  503. this.mobileCheckbox = new CheckBox({
  504. 'id': 'delivery_mobile_checkbox_' + this.contentUniqueId,
  505. 'el': $deliveryList.find('#delivery_mobile_container_' + this.contentUniqueId),
  506. 'name': 'delivery_mobile_option',
  507. 'label': t.translate("schedule_delivery_mobile_label"),
  508. 'ariaLabel': t.translate("schedule_delivery_mobile_label"),
  509. 'svgIcon': 'mobile_icon',
  510. 'checked': mobileStatus,
  511. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  512. });
  513. this.saveToFSCheckbox = new CheckBox({
  514. 'id': 'delivery_save_to_file_system_checkbox_container_' + this.contentUniqueId,
  515. 'el': $deliveryList.find('#delivery_save_to_file_system_checkbox_container_' + this.contentUniqueId),
  516. 'name': 'delivery_save_to_file_system_options',
  517. 'label': t.translate("schedule_delivery_save_to_file_system_label"),
  518. 'ariaLabel': t.translate("schedule_delivery_save_to_file_system_label"),
  519. 'svgIcon': 'saveExternal',
  520. 'checked': archiveStatus,
  521. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  522. });
  523. if (this.hasPermission.write || _.contains(this.hasPermission, "write")) {
  524. this.linkCheckbox = new CheckBox({
  525. 'id': 'delivery_link_checkbox_' + this.contentUniqueId,
  526. 'el': $deliveryList.find('#delivery_link_container_' + this.contentUniqueId),
  527. 'name': 'delivery_link_option',
  528. 'label': t.translate("schedule_delivery_link_label"),
  529. 'ariaLabel': t.translate("schedule_delivery_link_label"),
  530. 'checked': linkStatus,
  531. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  532. });
  533. this.saveTOS3Checkbox = new CheckBox({
  534. 'id': 'delivery_saveTOS3_checkbox_' + this.contentUniqueId,
  535. 'el': $deliveryList.find('#delivery_saveTOS3_container_' + this.contentUniqueId),
  536. 'name': 'delivery_saveTOS3_option',
  537. 'label': t.translate("saveToCloud"),
  538. 'ariaLabel': t.translate("schedule_delivery_save_label"),
  539. 'svgIcon': 'saveExternal',
  540. 'checked': this._isSaveToCloudOptionsSelected(),
  541. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  542. });
  543. this.saveCheckbox = new CheckBox({
  544. 'id': 'delivery_save_checkbox_' + this.contentUniqueId,
  545. 'el': $deliveryList.find('#delivery_save_container_' + this.contentUniqueId),
  546. 'name': 'delivery_save_option',
  547. 'label': t.translate("schedule_delivery_save_label"),
  548. 'ariaLabel': t.translate("schedule_delivery_save_label"),
  549. 'svgIcon': 'save',
  550. 'checked': saveStatus,
  551. 'onChange': function(name, value) {this._handleCheckBoxes(name, value, $deliveryList, $activeOptionsList);}.bind(this)
  552. });
  553. if (this._checkCapabilities('canIncludeLinkInEmail')) {
  554. this.linkCheckbox.doRender();
  555. }
  556. this.saveTOS3Checkbox.doRender();
  557. this.saveCheckbox.doRender();
  558. }
  559. if ( this.showSaveToFileSystem ) {
  560. this.saveToFSCheckbox.doRender();
  561. }
  562. if (this._checkCapabilities('canEmail')) {
  563. this.emailCheckbox.doRender();
  564. }
  565. if (this._checkCapabilities('canAttach')) {
  566. this.attachmentCheckbox.doRender();
  567. }
  568. this.printCheckbox.doRender();
  569. this.mobileCheckbox.doRender();
  570. },
  571. _checkCapabilities: function(capabilityName) {
  572. return _.find(this.glassContext.services.userProfile.capabilities, function(capability){
  573. return capability === capabilityName;
  574. });
  575. },
  576. _handleCheckBoxes: function(name, value, $deliveryList, $activeOptionsList) { //NOSONAR
  577. switch(name) {
  578. case 'delivery_saveTOS3_option':
  579. if (value) {
  580. this._setS3ConnectionOptions($deliveryList);
  581. this.deliveryOptions.saveToCloud = true;
  582. $deliveryList.find('.delivery_s3_options').show(__STANDARD_DELAY);
  583. } else {
  584. $deliveryList.find('.delivery_s3_options').hide(__STANDARD_DELAY);
  585. // this.deliveryOptions.saveToCloud = false;
  586. delete this.deliveryOptions.saveToCloud;
  587. delete this.deliveryOptions.cloudLocation;
  588. //Delete the raw options for runOptionEnum#saveToCloud and runOptionEnum#cloudName
  589. this.rawOptions = _.filter(this.rawOptions, function(option) {
  590. return !(option.name === "runOptionEnum#saveToCloud" || option.name === 'runOptionEnum#cloudName');
  591. });
  592. delete this.s3SaveToCloud;
  593. delete this.s3Location;
  594. delete this.cloudConnection;
  595. delete this.cloudLocation;
  596. }
  597. break;
  598. case 'delivery_attachment_option':
  599. if (this.deliveryOptions.email) {
  600. if(value) {
  601. this.email.emailAsAttachment = true;
  602. this.deliveryOptions.email = this.email;
  603. } else {
  604. this.email.emailAsAttachment = false;
  605. this.deliveryOptions.email = this.email;
  606. }
  607. }
  608. break;
  609. case 'delivery_link_option':
  610. if (this.deliveryOptions.email) {
  611. if (value) {
  612. this.email.emailAsURL = true;
  613. this.deliveryOptions.email = this.email;
  614. if (!this.deliveryOptions.save) { //NOSONAR
  615. this.saveCheckbox.check();
  616. this.glassContext.appController.showToast(t.translate('schedule_delivery_email_save_info_label'), {
  617. 'type': 'info',
  618. 'preventDuplicates' : true
  619. });
  620. }
  621. } else {
  622. this.email.emailAsURL = false;
  623. this.deliveryOptions.email = this.email;
  624. }
  625. }
  626. break;
  627. case 'delivery_email_option':
  628. if (value) {
  629. this.deliveryOptions.email = this.email;
  630. if (this.deliveryOptions.email.emailAsAttachment) {
  631. this.attachmentCheckbox.check();
  632. } else {
  633. this.attachmentCheckbox.uncheck();
  634. }
  635. // linkCheckbox is only rendered when there is write permission
  636. if (this.linkCheckbox) {
  637. if (this.deliveryOptions.email.emailAsURL) { //NOSONAR
  638. this.linkCheckbox.check();
  639. } else {
  640. this.linkCheckbox.uncheck();
  641. }
  642. }
  643. $deliveryList.find('.delivery_email_options').show(__STANDARD_DELAY);
  644. if (this.enableAdvancedSettings) {
  645. this.setAdvancedEmailStoredContent($deliveryList);
  646. }
  647. } else {
  648. delete this.deliveryOptions.email;
  649. // Reset the updated holder and the UI email recipients list to empty
  650. this.email.to = [];
  651. $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId + ' .delivery_recipient').remove();
  652. $deliveryList.find('.delivery_email_options').hide(__STANDARD_DELAY);
  653. }
  654. break;
  655. case 'delivery_save_option':
  656. if (value) {
  657. this.deliveryOptions.save = this.save;
  658. } else {
  659. if (this.deliveryOptions.email && this.deliveryOptions.email.emailAsURL) {
  660. this.saveCheckbox.check();
  661. this.glassContext.appController.showToast(t.translate('schedule_delivery_email_save_info_label'), {
  662. 'type': 'info',
  663. 'preventDuplicates' : true
  664. });
  665. } else {
  666. delete this.deliveryOptions.save;
  667. }
  668. }
  669. break;
  670. case 'delivery_mobile_option':
  671. if (value) {
  672. this.deliveryOptions.mobile = this.mobile;
  673. $deliveryList.find('.delivery_mobile_options').show(__STANDARD_DELAY);
  674. if(this.enableAdvancedSettings) {
  675. this.setAdvancedMobileStoredContent($deliveryList);
  676. }
  677. } else {
  678. delete this.deliveryOptions.mobile;
  679. $deliveryList.find('.delivery_mobile_options').hide(__STANDARD_DELAY);
  680. }
  681. break;
  682. case 'delivery_print_option':
  683. if (value) {
  684. $deliveryList.find('.delivery_print_options').show(__STANDARD_DELAY);
  685. this._setPrinters($deliveryList, $activeOptionsList);
  686. } else {
  687. delete this.deliveryOptions.print;
  688. $deliveryList.find('.delivery_print_options').hide(__STANDARD_DELAY);
  689. }
  690. break;
  691. case 'delivery_save_to_file_system_options':
  692. if(value) {
  693. $deliveryList.find('.delivery_save_to_file_system_options').show(__STANDARD_DELAY);
  694. this._setSaveToFileSystemValues($deliveryList, $activeOptionsList);
  695. } else {
  696. delete this.deliveryOptions.archive;
  697. $deliveryList.find('.delivery_save_to_file_system_options').hide(__STANDARD_DELAY);
  698. }
  699. break;
  700. default: {
  701. break;
  702. }
  703. }
  704. // Force "save" option to be used if everything has been unchecked
  705. if ($.isEmptyObject(this.deliveryOptions) && !this._isSaveToCloudOptionsSelected()) {
  706. if (this.hasPermission.write || _.contains(this.hasPermission, "write")) {
  707. this.saveCheckbox.check();
  708. } else {
  709. this.printCheckbox.check();
  710. }
  711. // Toast to explain why user is unable to unclick save (at least one delivery option must be selected)
  712. this.glassContext.appController.showToast(t.translate('schedule_delivery_min_select_label'), {
  713. 'type': 'info',
  714. 'preventDuplicates': true
  715. });
  716. }
  717. // Update the pane's ActiveOptionsList list.
  718. if ($activeOptionsList) {
  719. this.updateActiveDeliveryList($activeOptionsList);
  720. }
  721. },
  722. _hasSaveToCloudOption: function() {
  723. if (this.deliveryOptions.saveToCloud) {
  724. return true;
  725. }
  726. //Check the raw options
  727. var saveToCloudOption = _.find(this.rawOptions, function(option) {
  728. if (option.name === 'runOptionEnum#saveToCloud') {
  729. return true;
  730. }
  731. });
  732. if (saveToCloudOption) {
  733. return true;
  734. }
  735. return false;
  736. },
  737. _setPrinters: function ($deliveryList, $activeOptionsList) {
  738. var $printerDropdown = $deliveryList.find('.schedule_printer_names:not(.clickBound)');
  739. $printerDropdown.addClass('clickBound');
  740. var $printerOtherField = $deliveryList.find('#delivery_print_other_name_' + this.contentUniqueId + ':not(.clickBound)');
  741. $printerOtherField.addClass('clickBound');
  742. $printerDropdown.change(function () {
  743. var newValue = $printerDropdown.val();
  744. if (newValue === t.translate('schedule_delivery_printer_other_label')) {
  745. $deliveryList.find('.delivery_other_printer_section').show(__STANDARD_DELAY);
  746. } else {
  747. $deliveryList.find('.delivery_other_printer_section').hide(__STANDARD_DELAY);
  748. this._updatePrintDeliveryOption(newValue, $activeOptionsList);
  749. }
  750. }.bind(this));
  751. // can be changed to 'input' for every key stroke/ change including copy paste
  752. $printerOtherField.on('change', function (event) {
  753. this._updatePrintDeliveryOption(event.target.value, $activeOptionsList);
  754. }.bind(this));
  755. if ($printerDropdown.length) {
  756. controller.getPrinters(this.glassContext).done(function (result) {
  757. var systemPrinters = [];
  758. if (result && result.data) {
  759. systemPrinters = result.data;
  760. }
  761. this._setPrinterSelectionValues(systemPrinters, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList);
  762. }.bind(this));
  763. } else {
  764. // 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
  765. this.deliveryOptions.print = this.print;
  766. }
  767. },
  768. _setPrinterSelectionValues: function (systemPrinters, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList) {
  769. var presetPrinterName = '';
  770. if (this.deliveryOptions && this.deliveryOptions.print && this.deliveryOptions.print.name) {
  771. // There is a preset printer delivery option
  772. presetPrinterName = this.deliveryOptions.print.name;
  773. }
  774. // Set dropdown values and determine if the already-selected printer value is in the dropdown list
  775. for (var i = 0; i < systemPrinters.length; i++) {
  776. /* provide a displayed printer name that is truncated from the middle with an ellipsis
  777. * e.g: 'My Printer Name That Is Exceedingly Long' => 'My Pr...xceedingly Long'
  778. */
  779. var truncatedName = TextFormatter.middleShortenString(systemPrinters[i].defaultName);
  780. /* provide a meaningful option 'title' using defaultScreenTip, if provided, otherwise use the description, and
  781. * failing that, use the printerAddress attribute
  782. */
  783. var title = (systemPrinters[i].defaultScreenTip) ? systemPrinters[i].defaultScreenTip
  784. : ((systemPrinters[i].defaultDescription) ? systemPrinters[i].defaultDescription
  785. : systemPrinters[i].printerAddress);
  786. $printerDropdown.append($('<option>', {
  787. value: systemPrinters[i].printerAddress,
  788. title: title
  789. }).text(truncatedName));
  790. }
  791. // Add 'Other...' to dropdown list
  792. $printerDropdown.append($('<option>', {
  793. value: t.translate('schedule_delivery_printer_other_label')
  794. }).text(t.translate('schedule_delivery_printer_other_label')));
  795. // Do not automatically display 'Other...' input field directly if there are system printer options
  796. if (systemPrinters.length > 0) {
  797. $deliveryList.find('.delivery_other_printer_section').hide();
  798. }
  799. if (presetPrinterName) {
  800. // set dropdown value to preset
  801. this._setDropDownValueToPresetPrinter(presetPrinterName, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList);
  802. } else {
  803. this._setDefaultDeliveryPrintOption(systemPrinters, $printerOtherField, $activeOptionsList);
  804. }
  805. },
  806. _setDropDownValueToPresetPrinter: function (presetPrinterName, $printerDropdown, $printerOtherField, $deliveryList, $activeOptionsList) {
  807. var escapedPrinterName = TextFormatter.escapeSpecialCharacters(presetPrinterName);
  808. if ($printerDropdown.find("option[value='" + escapedPrinterName + "']").length > 0) {
  809. // presetPrinterName is one of the available options, make it the selected one, and hide the Other... text field if shown
  810. $printerDropdown.val(presetPrinterName);
  811. $deliveryList.find('.delivery_other_printer_section').hide();
  812. } else {
  813. // presetPrinterName is specified, but is not an available select value, so treat it as the 'Other...' value
  814. $printerDropdown.val(t.translate('schedule_delivery_printer_other_label'));
  815. $deliveryList.find('.delivery_other_printer_section').show(__STANDARD_DELAY);
  816. $printerOtherField.val(presetPrinterName);
  817. }
  818. this._updatePrintDeliveryOption(presetPrinterName, $activeOptionsList);
  819. },
  820. _setDefaultDeliveryPrintOption: function (systemPrinters, $printerOtherField, $activeOptionsList) {
  821. var printerName;
  822. if (systemPrinters && systemPrinters.length > 0) {
  823. //select the first listed printer as the default
  824. printerName = systemPrinters[0].printerAddress;
  825. } else {
  826. //set the default to "Other..." value
  827. printerName = $printerOtherField.val();
  828. }
  829. this._updatePrintDeliveryOption(printerName, $activeOptionsList);
  830. },
  831. _updatePrintDeliveryOption: function (printerName, $activeOptionsList) {
  832. this.print.name = printerName;
  833. this.deliveryOptions.print = this.print;
  834. if ($activeOptionsList){
  835. this.updateActiveDeliveryList($activeOptionsList);
  836. }
  837. },
  838. _setSaveToFileSystemValues: function($deliveryList, $activeOptionsList) { //NOSONAR
  839. var $outputNameField = $deliveryList.find('#delivery_save_to_file_system_file_name_' + this.contentUniqueId + ':not(.clickBound)');
  840. $outputNameField.addClass('clickBound');
  841. if (this.deliveryOptions && this.deliveryOptions.archive && this.deliveryOptions.archive.filenameStub) {
  842. this.archive.filenameStub = this.deliveryOptions.archive.filenameStub;
  843. } else {
  844. this.archive.filenameStub = this.reportName;
  845. }
  846. $outputNameField.val(this.archive.filenameStub);
  847. var $outputNameInputField = $deliveryList.find('.delivery_save_to_file_system_file_name_input_section');
  848. stringFormatter.middleShortenString($outputNameInputField);
  849. var $fileLocationDropdown = $deliveryList.find('.schedule_save_to_file_system_locations:not(.clickBound)');
  850. $fileLocationDropdown.addClass('clickBound');
  851. this._archiveLocations = _.sortBy(this._archiveLocations, 'defaultName');
  852. for (var i = 0; i < this._archiveLocations.length; i++) {
  853. var truncatedName = TextFormatter.middleShortenString(this._archiveLocations[i].defaultName);
  854. $fileLocationDropdown.append($('<option>', {
  855. value: this._archiveLocations[i].defaultName,
  856. title: this._archiveLocations[i].defaultName
  857. }).text(truncatedName));
  858. }
  859. if(this.deliveryOptions && this.deliveryOptions.archive && this.deliveryOptions.archive.location) {
  860. //The saved location could still be id based but going forward from R9 it will be named searchPath
  861. this.archive.location = this.deliveryOptions.archive.location;
  862. var displayName = this._getDisplayNameFromStoreIDOrSearchPath(this.archive.location);
  863. $fileLocationDropdown.val(displayName);
  864. } else {
  865. this.archive.location = this._archiveLocations[0].searchPath;
  866. }
  867. $fileLocationDropdown.change(function() {
  868. var newValue = $fileLocationDropdown.val();
  869. var namedSearchPath = this._getSearchPathForLocation(newValue);
  870. this.archive.location = namedSearchPath;
  871. this.deliveryOptions.archive.location = this.archive.location;
  872. if ($activeOptionsList) {
  873. this.updateActiveDeliveryList($activeOptionsList);
  874. }
  875. }.bind(this));
  876. $outputNameField.on('change', function(event){
  877. this.archive.filenameStub = event.target.value;
  878. this.deliveryOptions.archive.filenameStub = this.archive.filenameStub;
  879. if($activeOptionsList) {
  880. this.updateActiveDeliveryList($activeOptionsList);
  881. }
  882. }.bind(this));
  883. if ( this._archiveLocations.length > 0 && this.archive.location === "") {
  884. //Handle in case nothing is set by user
  885. this.archive.location = this._archiveLocations[0].searchPath;
  886. }
  887. // Set the latest
  888. this.deliveryOptions.archive = this.archive;
  889. if ($activeOptionsList) {
  890. this.updateActiveDeliveryList($activeOptionsList);
  891. }
  892. },
  893. _getSearchPathForLocation: function(locationName) {
  894. var idItem = _.find(this._archiveLocations, function(item){
  895. return item.defaultName === locationName;
  896. }.bind(this));
  897. return idItem? idItem.searchPath : "";
  898. },
  899. _getDisplayNameFromStoreIDOrSearchPath: function(savedLocation) {
  900. var idItem = _.find(this._archiveLocations, function(item){
  901. return savedLocation.indexOf(item.id) !== -1 || savedLocation === item.searchPath ;
  902. }.bind(this));
  903. return idItem? idItem.defaultName : "";
  904. },
  905. _renderRadioButtonGroup: function($deliveryList) {
  906. var deferred = Q.defer();
  907. var itemsSpec = [this._getConflictResolutionContainer($deliveryList)];
  908. this._conflictResolutionOptionsControl = new PropertyUIControl({
  909. 'el': $deliveryList.find('#schedule_delivery_conflict_resolution_section_' + this.contentUniqueId),
  910. 'items': itemsSpec,
  911. 'glassContext': this.glassContext
  912. });
  913. this._conflictResolutionOptionsControl.render().then(function() {
  914. this._conflictResolutionOptionsControl = this._conflictResolutionOptionsControl.getProperty('conflictResolutionOptions');
  915. deferred.resolve();
  916. }.bind(this));
  917. return deferred.promise;
  918. },
  919. _getConflictResolutionContainer: function($deliveryList) {
  920. return {
  921. 'type': 'CollapsibleSection',
  922. 'name': 'conflictResolutionOptions',
  923. 'styleAsSimpleRow': true,
  924. 'label': t.translate("schedule_delivery_conflict_resolution_label"),
  925. 'items': [this._getConflictResolutionOptions($deliveryList)]
  926. };
  927. },
  928. _getConflictResolutionOptions: function() {
  929. var buttonItems = [];
  930. buttonItems.push({
  931. 'name': 'fail',
  932. 'label': t.translate("schedule_delivery_keep_existing_label"),
  933. 'id': 'delivery_keep_' + this.contentUniqueId,
  934. 'value': 'fail'
  935. });
  936. buttonItems.push({
  937. 'name': 'replace',
  938. 'label': t.translate("schedule_delivery_replace_label"),
  939. 'id': 'delivery_replace_' + this.contentUniqueId,
  940. 'value': 'replace'
  941. });
  942. buttonItems.push({
  943. 'name': 'appendDateTime',
  944. 'label': t.translate("schedule_delivery_timestamp_label"),
  945. 'id': 'delivery_timestamp_' + this.contentUniqueId,
  946. 'value': 'appendDateTime'
  947. });
  948. buttonItems.push({
  949. 'name': 'appendSequenceNumber',
  950. 'label': t.translate("schedule_delivery_version_number_label"),
  951. 'id': 'delivery_version_number_' + this.contentUniqueId,
  952. 'value': 'appendSequenceNumber'
  953. });
  954. return {
  955. 'type': 'RadioButtonGroup',
  956. 'name': 'delivery_conflict_resolution_pick',
  957. 'ariaLabel': t.translate("schedule_delivery_conflict_resolution_label"),
  958. 'value': this.archive.conflictResolution,
  959. 'separator': false,
  960. 'onChange': this._updateConflictResolutionValue.bind(this),
  961. 'items': buttonItems
  962. };
  963. },
  964. _updateConflictResolutionValue: function(name, value) {
  965. // Update the delivery options for save to archives
  966. this.archive.conflictResolution = value;
  967. },
  968. updateActiveDeliveryList: function($activeOptionsList) {
  969. if (this.deliveryOptions) {
  970. $activeOptionsList.html('');
  971. for (var delivery in this.deliveryOptions) { //NOSONAR
  972. if (delivery !== 'cloudLocation') {
  973. var $link = $("<div/>").addClass('delivery_link').text(t.translate("schedule_delivery_" + delivery + "_short_label"));
  974. $("<div/>").addClass('delivery_type_container').append("<span class='delivery_icon' data-icon='" + this._icons[delivery] + "'></span>").append($link).appendTo($activeOptionsList);
  975. }
  976. }
  977. //Check for cloud storage delivery option
  978. if (this._hasSaveToCloudOption() && !this.deliveryOptions.saveToCloud) {
  979. if (this.$el.find('.delivery_type_container.saveToCloud').length === 0) {
  980. var $link = $("<div/>").addClass('delivery_link').text(t.translate("schedule_delivery_saveToCloud_short_label"));
  981. $("<div/>").addClass('delivery_type_container saveToCloud').append("<span class='delivery_icon' data-icon='" + this._icons['saveToCloud'] + "'></span>").append($link).appendTo($activeOptionsList);
  982. }
  983. }
  984. this.setIcons($activeOptionsList);
  985. this.shortenLinks($activeOptionsList);
  986. }
  987. },
  988. setIcons: function(container) {
  989. var icons = container.find('.delivery_icon');
  990. var links = container.find('.delivery_link');
  991. for (var j = 0; j < icons.length; j++) {
  992. var $icon = $(icons[j]);
  993. var $link = $(links[j]);
  994. Utils.setIcon($icon, 'common-' + $icon.data('icon'), $link.html());
  995. }
  996. },
  997. shortenLinks: function(container) {
  998. var links = container.find('.delivery_link');
  999. for (var j = 0; j < links.length; j++) {
  1000. stringFormatter.middleShortenString(links[j]);
  1001. }
  1002. },
  1003. // FUNCTIONS EXCLUSIVE TO ADVANCED LEVEL
  1004. setAdvancedMobileStoredContent: function($deliveryList) {
  1005. var $mobileRecipientsList = $deliveryList.find('#delivery_mobile_recipients_' + this.contentUniqueId);
  1006. // mobile recipients
  1007. var $mobileRecipientsInput = $deliveryList.find('.delivery_mobile_to_section:not(.clickBound)');
  1008. $mobileRecipientsInput.addClass('clickBound');
  1009. $mobileRecipientsInput.on('clicktap', function() {
  1010. this.glassContext.appController.showSlideOut({
  1011. 'position': 'right',
  1012. 'overlay': true,
  1013. 'parent': this.slideout,
  1014. 'width': this.slideout.width,
  1015. 'label': t.translate('schedule_delivery_accounts_aria_label'),
  1016. 'content': {
  1017. 'module': 'bi/schedule/views/AccountPickerSlideoutView',
  1018. 'glassContext': this.glassContext,
  1019. 'addCallback': function(selectedItems) {
  1020. var values = Object.keys(selectedItems).map(function(key) {
  1021. return selectedItems[key]
  1022. });
  1023. this._addMobileRecipients(values, $deliveryList, true);
  1024. return Promise.resolve();
  1025. }.bind(this)
  1026. }
  1027. });
  1028. }.bind(this));
  1029. var $mobileRecipientsEllipsis = $deliveryList.find('#delivery_mobile_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
  1030. $mobileRecipientsEllipsis.addClass('clickBound');
  1031. $mobileRecipientsEllipsis.on('clicktap', function(event) {
  1032. event.cancelBubble = true;
  1033. if (event.stopPropagation) {
  1034. event.stopPropagation();
  1035. }
  1036. $mobileRecipientsList.addClass('expanded');
  1037. $mobileRecipientsEllipsis.hide();
  1038. }.bind(this));
  1039. //POPULATE IF MOBILE ALREADY HAS
  1040. if (this.deliveryOptions && this.deliveryOptions.mobile && this.deliveryOptions.mobile.to && $.isArray(this.deliveryOptions.mobile.to) &&this.deliveryOptions.mobile.to.length !== 0) { //NOSONAR
  1041. this._addMobileRecipients(this.deliveryOptions.mobile.to, $deliveryList, false);
  1042. }
  1043. var $mobileRecipientLabel = $deliveryList.find('label[for="delivery_mobile_recipients_' + this.contentUniqueId+ '"]');
  1044. if (!$(document).data('setmobile')) {
  1045. $(document).data('setmobile', true).on('clicktap', function(event) {
  1046. // Collapse mobile Recipients
  1047. if (!$mobileRecipientsInput.is(event.target) && $mobileRecipientsInput.has(event.target).length === 0) {
  1048. $mobileRecipientsList.removeClass('expanded');
  1049. this._checkForEllipsis($mobileRecipientsList, $mobileRecipientLabel, function(show) {
  1050. if (show) {
  1051. $mobileRecipientsEllipsis.show(__STANDARD_DELAY);
  1052. } else {
  1053. $mobileRecipientsEllipsis.hide(__STANDARD_DELAY);
  1054. }
  1055. }.bind(this));
  1056. }
  1057. }.bind(this));
  1058. }
  1059. },
  1060. setAdvancedEmailStoredContent: function($deliveryList) { //NOSONAR
  1061. // subject
  1062. var $emailSubjectInput = $deliveryList.find('#schedule_email_subject_' + this.contentUniqueId);
  1063. if (this.deliveryOptions.email.subject) {
  1064. $emailSubjectInput.val(this.deliveryOptions.email.subject);
  1065. this.email.subject = $emailSubjectInput.val();
  1066. } else if(this.email.subject) {
  1067. $emailSubjectInput.val(this.email.subject);
  1068. }
  1069. // can be changed to 'input' for every key stroke/ change including copy paste
  1070. $emailSubjectInput.on('change', function(event){
  1071. this.deliveryOptions.email.subject = event.target.value;
  1072. this.email.subject = event.target.value;
  1073. }.bind(this));
  1074. // email message
  1075. var $emailBodyEditor = $deliveryList.find('#delivery_email_message_' + this.contentUniqueId);
  1076. var customConfig2 = "../../../js/schedule/utils/cke_editor_delivery_config.js";
  1077. var messageEditor = $emailBodyEditor.ckeditor({
  1078. customConfig: "../../../js/schedule/utils/cke_editor_delivery_config.js"
  1079. }).editor;
  1080. if (messageEditor.config && messageEditor.config.language){
  1081. messageEditor.config.language = this.glassContext.services.userProfile.preferences.productLocale;
  1082. }
  1083. // set editor dialog handler
  1084. this._setEditorDialogHideHandler();
  1085. if (this.deliveryOptions.email.memoPart) {
  1086. messageEditor.setData(this.deliveryOptions.email.memoPart);
  1087. this.email.memoPart = messageEditor.getData();
  1088. } else if (this.email.memoPart) {
  1089. messageEditor.setData(this.email.memoPart);
  1090. } else {
  1091. // SET empty deliveryOptions memoPart
  1092. this.deliveryOptions.email.memoPart = __EMPTY_MESSAGE_BODY;
  1093. this.email.memoPart = __EMPTY_MESSAGE_BODY;
  1094. }
  1095. messageEditor.on('change', function(event) {
  1096. this.deliveryOptions.email.memoPart = "<html><body>" + event.editor.getData() + "</body></html>";
  1097. this.email.memoPart = "<html><body>" + event.editor.getData() + "</body></html>";
  1098. }.bind(this));
  1099. // RECIPIENTS
  1100. var $emailRecipientsList = $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId);
  1101. var $ccRecipientsList = $deliveryList.find('#delivery_cc_recipients_' + this.contentUniqueId);
  1102. var $bccRecipientsList = $deliveryList.find('#delivery_bcc_recipients_' + this.contentUniqueId);
  1103. // TO Recipients
  1104. var $emailRecipientsInput = $deliveryList.find('.delivery_email_to_section');
  1105. var $emailRecipientsLabel = $emailRecipientsInput.find('.schedule_delivery_header:not(.clickBound)');
  1106. $emailRecipientsLabel.addClass('clickBound');
  1107. $emailRecipientsLabel.on('clicktap', function() {
  1108. this.glassContext.appController.showSlideOut({
  1109. 'position': 'right',
  1110. 'overlay': true,
  1111. 'parent': this.slideout,
  1112. 'width': this.slideout.width,
  1113. 'label': t.translate('schedule_delivery_accounts_aria_label'),
  1114. 'content': {
  1115. 'module': 'bi/schedule/views/AccountPickerSlideoutView',
  1116. 'glassContext': this.glassContext,
  1117. 'addCallback': function(selectedItems) {
  1118. var values = Object.keys(selectedItems).map(function(key) {
  1119. return selectedItems[key]
  1120. });
  1121. this._addEmailRecipients(values, $deliveryList, true);
  1122. return Promise.resolve();
  1123. }.bind(this)
  1124. }
  1125. });
  1126. }.bind(this));
  1127. // Setup the handlers for recipient edit boxes
  1128. this._handleRecipientEdit($deliveryList, $emailRecipientsList, this._addEmailAddress.bind(this));
  1129. this._handleRecipientEdit($deliveryList, $ccRecipientsList, this._addCCEmailAddress.bind(this));
  1130. this._handleRecipientEdit($deliveryList, $bccRecipientsList, this._addBCCEmailAddress.bind(this));
  1131. var $emailRecipientsEllipsis = $deliveryList.find('#delivery_email_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
  1132. $emailRecipientsEllipsis.addClass('clickBound');
  1133. $emailRecipientsEllipsis.on('clicktap', function(event) {
  1134. event.cancelBubble = true;
  1135. if (event.stopPropagation) {
  1136. event.stopPropagation();
  1137. }
  1138. $emailRecipientsList.addClass('expanded');
  1139. $emailRecipientsEllipsis.hide();
  1140. }.bind(this));
  1141. // Populate
  1142. if (this.deliveryOptions && this.deliveryOptions.email && this.deliveryOptions.email.to && $.isArray(this.deliveryOptions.email.to)) {
  1143. if (this.deliveryOptions.email.to.length !== 0) {
  1144. this._addEmailRecipients(this.deliveryOptions.email.to, $deliveryList, false);
  1145. } else {
  1146. //Populate the to field with the default logged in user name if user has an email adrress set in the authentication name space
  1147. if ( this.glassContext.profile.account && this.glassContext.profile.account.defaultName && this.glassContext.profile.account.email ) {
  1148. var defaultRecipientData = [{
  1149. 'defaultName': this.glassContext.profile.account.defaultName,
  1150. 'address': this.glassContext.profile.account.email,
  1151. 'type': t.translate('currentUser'),
  1152. 'id': _.uniqueId('recipientId_')
  1153. }];
  1154. this._addEmailRecipients(defaultRecipientData, $deliveryList);
  1155. }
  1156. }
  1157. }
  1158. // CC Recipients
  1159. var $ccRecipientsInput = $deliveryList.find('.delivery_cc_section');
  1160. var $ccRecipientsLabel = $ccRecipientsInput.find('.schedule_delivery_header:not(.clickBound)');
  1161. $ccRecipientsLabel.addClass('clickBound');
  1162. $ccRecipientsLabel.on('clicktap', function() {
  1163. this.glassContext.appController.showSlideOut({
  1164. 'position': 'right',
  1165. 'overlay': true,
  1166. 'parent': this.slideout,
  1167. 'width': this.slideout.width,
  1168. 'label': t.translate('schedule_delivery_accounts_aria_label'),
  1169. 'content': {
  1170. 'module': 'bi/schedule/views/AccountPickerSlideoutView',
  1171. 'glassContext': this.glassContext,
  1172. 'addCallback': function(selectedItems) {
  1173. var values = Object.keys(selectedItems).map(function(key) {
  1174. return selectedItems[key]
  1175. });
  1176. this._addCCRecipients(values, $deliveryList, true);
  1177. return Promise.resolve();
  1178. }.bind(this)
  1179. }
  1180. });
  1181. }.bind(this));
  1182. var $ccRecipientsEllipsis = $deliveryList.find('#delivery_cc_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
  1183. $ccRecipientsEllipsis.addClass('clickBound');
  1184. $ccRecipientsEllipsis.on('clicktap', function(event) {
  1185. event.cancelBubble = true;
  1186. if (event.stopPropagation) {
  1187. event.stopPropagation();
  1188. }
  1189. $ccRecipientsList.addClass('expanded');
  1190. $ccRecipientsEllipsis.hide();
  1191. }.bind(this));
  1192. //Toggler
  1193. var $ccToggler = $deliveryList.find('.delivery_cc_toggler:not(.clickBound)');
  1194. $ccToggler.addClass('clickBound');
  1195. $ccToggler.on('clicktap', function(){
  1196. $ccToggler.hide();
  1197. $deliveryList.find('.delivery_cc_section').show(__STANDARD_DELAY);
  1198. }.bind(this));
  1199. //POPULATE
  1200. if (this.deliveryOptions && this.deliveryOptions.email && this.deliveryOptions.email.cc && $.isArray(this.deliveryOptions.email.cc)) {
  1201. if (this.deliveryOptions.email.cc.length === 0) {
  1202. $ccRecipientsInput.hide();
  1203. } else {
  1204. $ccToggler.hide();
  1205. //Add them
  1206. this._addCCRecipients(this.deliveryOptions.email.cc, $deliveryList, false);
  1207. }
  1208. } else {
  1209. $ccRecipientsInput.hide();
  1210. }
  1211. // BCC Recipients
  1212. var $bccRecipientsInput = $deliveryList.find('.delivery_bcc_section');
  1213. var $bccRecipientsLabel = $bccRecipientsInput.find('.schedule_delivery_header:not(.clickBound)');
  1214. $bccRecipientsLabel.addClass('clickBound');
  1215. $bccRecipientsLabel.on('clicktap', function() {
  1216. this.glassContext.appController.showSlideOut({
  1217. 'position': 'right',
  1218. 'overlay': true,
  1219. 'parent': this.slideout,
  1220. 'width': this.slideout.width,
  1221. 'label': t.translate('schedule_delivery_accounts_aria_label'),
  1222. 'content': {
  1223. 'module': 'bi/schedule/views/AccountPickerSlideoutView',
  1224. 'glassContext': this.glassContext,
  1225. 'addCallback': function(selectedItems) {
  1226. var values = Object.keys(selectedItems).map(function(key) {
  1227. return selectedItems[key]
  1228. });
  1229. this._addBCCRecipients(values, $deliveryList, true);
  1230. return Promise.resolve();
  1231. }.bind(this)
  1232. }
  1233. });
  1234. }.bind(this));
  1235. var $bccRecipientsEllipsis = $deliveryList.find('#delivery_bcc_ellipsis_' + this.contentUniqueId + ':not(.clickBound)');
  1236. $bccRecipientsEllipsis.addClass('clickBound');
  1237. $bccRecipientsEllipsis.on('clicktap', function(event) {
  1238. event.cancelBubble = true;
  1239. if (event.stopPropagation) {
  1240. event.stopPropagation();
  1241. }
  1242. $bccRecipientsList.addClass('expanded');
  1243. $bccRecipientsEllipsis.hide();
  1244. }.bind(this));
  1245. //Toggler
  1246. var $bccToggler = $deliveryList.find('.delivery_bcc_toggler:not(.clickBound)');
  1247. $bccToggler.addClass('clickBound');
  1248. $bccToggler.on('clicktap', function(){
  1249. $bccToggler.hide();
  1250. $deliveryList.find('.delivery_bcc_section').show(__STANDARD_DELAY);
  1251. }.bind(this));
  1252. //POPULATE
  1253. if (this.deliveryOptions && this.deliveryOptions.email && this.deliveryOptions.email.bcc && $.isArray(this.deliveryOptions.email.bcc)) {
  1254. if (this.deliveryOptions.email.bcc.length === 0) {
  1255. $bccRecipientsInput.hide();
  1256. } else {
  1257. $bccToggler.hide();
  1258. //Add them
  1259. this._addBCCRecipients(this.deliveryOptions.email.bcc, $deliveryList, false);
  1260. }
  1261. } else {
  1262. $bccRecipientsInput.hide();
  1263. }
  1264. var $emailRecipientLabel = $deliveryList.find('label[for="delivery_email_recipients_edit_field_' + this.contentUniqueId+ '"]');
  1265. var $ccRecipientLabel = $deliveryList.find('label[for="delivery_cc_recipients_edit_field_' + this.contentUniqueId+ '"]');
  1266. var $bccRecipientLabel = $deliveryList.find('label[for="delivery_bcc_recipients_edit_field_' + this.contentUniqueId+ '"]');
  1267. // Closing each list if not clicked on them
  1268. if (!$(document).data('setemail')) {
  1269. $(document).data('setemail', true).on('clicktap', function(event) {
  1270. // Collapse email Recipients
  1271. if (!$emailRecipientsInput.is(event.target) && $emailRecipientsInput.has(event.target).length === 0) {
  1272. $emailRecipientsList.removeClass('expanded');
  1273. this._checkForEllipsis($emailRecipientsList, $emailRecipientLabel, function(show) {
  1274. if (show) {
  1275. $emailRecipientsEllipsis.show(__STANDARD_DELAY);
  1276. } else {
  1277. $emailRecipientsEllipsis.hide(__STANDARD_DELAY);
  1278. }
  1279. }.bind(this));
  1280. }
  1281. // Collapse cc Recipients
  1282. if (!$ccRecipientsInput.is(event.target) && $ccRecipientsInput.has(event.target).length === 0) {
  1283. $ccRecipientsList.removeClass('expanded');
  1284. this._checkForEllipsis($ccRecipientsList, $ccRecipientLabel, function(show) {
  1285. if (show) {
  1286. $ccRecipientsEllipsis.show(__STANDARD_DELAY);
  1287. } else {
  1288. $ccRecipientsEllipsis.hide(__STANDARD_DELAY);
  1289. }
  1290. }.bind(this));
  1291. }
  1292. // Collapse bcc Recipients
  1293. if (!$bccRecipientsInput.is(event.target) && $bccRecipientsInput.has(event.target).length === 0) {
  1294. $bccRecipientsList.removeClass('expanded');
  1295. this._checkForEllipsis($bccRecipientsList, $bccRecipientLabel, function(show) {
  1296. if (show) {
  1297. $bccRecipientsEllipsis.show(__STANDARD_DELAY);
  1298. } else {
  1299. $bccRecipientsEllipsis.hide(__STANDARD_DELAY);
  1300. }
  1301. }.bind(this));
  1302. }
  1303. }.bind(this));
  1304. }
  1305. },
  1306. _validateEmail: function(address) {
  1307. 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])*)+$/;
  1308. return address.match(emailRegEx);
  1309. },
  1310. _handleRecipientEdit: function($deliveryList, $recipientsList, addCallback) {
  1311. var $recipientsEdit = $recipientsList.find('.delivery_recipients_edit_box');
  1312. $recipientsEdit.on('keydown', function(event) {
  1313. var keyCode = event.keyCode || event.which;
  1314. if (event.target.value.length > 0) {
  1315. // tab, enter, comma or semi-colon
  1316. if ( keyCode == 9 || keyCode == 13 || keyCode == 188 || keyCode == 186) {
  1317. addCallback(event.target.value, $deliveryList, $recipientsList);
  1318. $recipientsEdit.val('');
  1319. event.preventDefault();
  1320. }
  1321. } else {
  1322. // handle backspace to delete
  1323. if ( keyCode == 8) {
  1324. var $prev = $recipientsList.find('.delivery_recipient:last');
  1325. if ($prev.length !== 0) {
  1326. this._removeRecipient($deliveryList, $prev);
  1327. }
  1328. event.preventDefault();
  1329. }
  1330. }
  1331. }.bind(this));
  1332. $recipientsEdit.on('paste', function(event) {
  1333. setTimeout(function() {
  1334. var emailList = this._checkForMultipleEmails(event.target.value);
  1335. _.each(emailList,function(email) {
  1336. addCallback(email, $deliveryList, $recipientsList);
  1337. });
  1338. $recipientsEdit.val('');
  1339. }.bind(this), 0);
  1340. }.bind(this));
  1341. // Automatically add the current recipient when focus is lost
  1342. $recipientsEdit.on('focusout', function(event) {
  1343. if (event.target.value.length > 0) {
  1344. addCallback(event.target.value, $deliveryList, $recipientsList);
  1345. $recipientsEdit.val('');
  1346. }
  1347. }.bind(this));
  1348. // prevent expanded input from collapsing when input box is selected
  1349. $recipientsEdit.on('clicktap', function(event) {
  1350. event.preventDefault();
  1351. return false;
  1352. }.bind(this));
  1353. },
  1354. _checkForMultipleEmails: function(input) {
  1355. var emailList = input.split(/,|;/);
  1356. return emailList;
  1357. },
  1358. _addAddress: function(address, $deliveryList, $emailRecipientsList) {
  1359. var recipientData = [{
  1360. defaultName: address,
  1361. address: address,
  1362. type: address,
  1363. id: _.uniqueId('recipientId_')
  1364. }];
  1365. var listAttrs = {
  1366. recipients: recipientData,
  1367. removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
  1368. invalidLabel : t.translate("schedule_delivery_invalid_address")
  1369. };
  1370. var list = dot.simpleTemplate(recipientsListTemplate);
  1371. var $recipientList = $(list(listAttrs));
  1372. if (this._validateEmail(address)) {
  1373. $recipientList.find('.delivery_recipient_underline').hide();
  1374. } else {
  1375. $recipientList.find('.delivery_recipient_underline').show();
  1376. }
  1377. $emailRecipientsList.find('.delivery_recipients_edit_field').before($recipientList);
  1378. if (!$emailRecipientsList.hasClass('expanded')) {
  1379. var $recipientsLabel = $deliveryList.find('label[for="' + $emailRecipientsList.id + '"]');
  1380. if ($emailRecipientsList.prop('scrollHeight') > $recipientsLabel.height()*1.25) {
  1381. $emailRecipientsList.addClass('expanded');
  1382. }
  1383. }
  1384. this.setIcons($recipientList);
  1385. return recipientData;
  1386. },
  1387. _addEmailAddress: function(address, $deliveryList, $emailRecipientsList) {
  1388. var recipientData = this._addAddress(address, $deliveryList, $emailRecipientsList);
  1389. // update lists
  1390. this.email.to = this.email.to.slice().concat(recipientData);
  1391. this._updateEmailRecipients($deliveryList);
  1392. this._setRecipientsListEvents($deliveryList);
  1393. },
  1394. _addCCEmailAddress: function(address, $deliveryList, $ccRecipientsList) {
  1395. var recipientData = this._addAddress(address, $deliveryList, $ccRecipientsList);
  1396. // update lists
  1397. this.email.cc = this.email.cc.slice().concat(recipientData);
  1398. this._updateCCRecipients($deliveryList);
  1399. this._setRecipientsListEvents($deliveryList);
  1400. },
  1401. _addBCCEmailAddress: function(address, $deliveryList, $bccRecipientsList) {
  1402. var recipientData = this._addAddress(address, $deliveryList, $bccRecipientsList);
  1403. // update lists
  1404. this.email.bcc = this.email.bcc.slice().concat(recipientData);
  1405. this._updateBCCRecipients($deliveryList);
  1406. this._setRecipientsListEvents($deliveryList);
  1407. },
  1408. _addEmailRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
  1409. var recipientData = [];
  1410. var data;
  1411. if (manuallyAdded) {
  1412. data = this._verifyNewRecipients(recipients, this.email.to.slice()) || [];
  1413. } else {
  1414. this.email.to = [];
  1415. data = recipients || [];
  1416. }
  1417. for (var i=0; i<data.length;i++) {
  1418. recipientData.push({
  1419. defaultName: data[i].defaultName || "",
  1420. address: data[i].searchPath || data[i].address || "",
  1421. type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
  1422. id: _.uniqueId('recipientId_')
  1423. });
  1424. }
  1425. var listAttrs = {
  1426. recipients: recipientData,
  1427. removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
  1428. invalidLabel : t.translate("schedule_delivery_invalid_address")
  1429. };
  1430. var list = dot.simpleTemplate(recipientsListTemplate);
  1431. var recipientList = $(list(listAttrs));
  1432. $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId + ' .delivery_recipients_edit_field').before(recipientList);
  1433. // update lists
  1434. this.email.to = this.email.to.slice().concat(recipientData);
  1435. this._updateEmailRecipients($deliveryList);
  1436. if (manuallyAdded) {
  1437. if (recipientData.length === 1) {
  1438. this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
  1439. } else if ( recipientData.length > 1) {
  1440. this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
  1441. }
  1442. }
  1443. this.setIcons(recipientList);
  1444. this._setRecipientsListEvents($deliveryList);
  1445. },
  1446. _addCCRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
  1447. var recipientData = [];
  1448. var data ;
  1449. if (manuallyAdded) {
  1450. data = this._verifyNewRecipients(recipients, this.email.cc.slice()) || [];
  1451. } else {
  1452. this.email.cc = [];
  1453. data = recipients || [];
  1454. }
  1455. for (var i=0; i<data.length;i++) {
  1456. recipientData.push({
  1457. defaultName: data[i].defaultName || "",
  1458. address: data[i].searchPath || data[i].address || "",
  1459. type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
  1460. id: _.uniqueId('recipientId_')
  1461. });
  1462. }
  1463. var listAttrs = {
  1464. recipients: recipientData,
  1465. removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
  1466. invalidLabel : t.translate("schedule_delivery_invalid_address")
  1467. };
  1468. var list = dot.simpleTemplate(recipientsListTemplate);
  1469. var recipientList = $(list(listAttrs));
  1470. $deliveryList.find('#delivery_cc_recipients_' + this.contentUniqueId + ' .delivery_recipients_edit_field').before(recipientList);
  1471. // update lists
  1472. this.email.cc = this.email.cc.slice().concat(recipientData);
  1473. this._updateCCRecipients($deliveryList);
  1474. if (manuallyAdded) {
  1475. if (recipientData.length === 1) {
  1476. this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
  1477. } else if ( recipientData.length > 1) {
  1478. this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
  1479. }
  1480. }
  1481. this.setIcons(recipientList);
  1482. this._setRecipientsListEvents($deliveryList);
  1483. },
  1484. _addBCCRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
  1485. var recipientData = [];
  1486. var data;
  1487. if (manuallyAdded) {
  1488. data = this._verifyNewRecipients(recipients, this.email.bcc.slice()) || [];
  1489. } else {
  1490. this.email.bcc = [];
  1491. data = recipients || [];
  1492. }
  1493. for (var i=0; i<data.length;i++) {
  1494. recipientData.push({
  1495. defaultName: data[i].defaultName || "",
  1496. address: data[i].searchPath || data[i].address || "",
  1497. type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
  1498. id: _.uniqueId('recipientId_')
  1499. });
  1500. }
  1501. var listAttrs = {
  1502. recipients: recipientData,
  1503. removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
  1504. invalidLabel : t.translate("schedule_delivery_invalid_address")
  1505. };
  1506. var list = dot.simpleTemplate(recipientsListTemplate);
  1507. var recipientList = $(list(listAttrs));
  1508. $deliveryList.find('#delivery_bcc_recipients_' + this.contentUniqueId + ' .delivery_recipients_edit_field').before(recipientList);
  1509. // update lists
  1510. this.email.bcc = this.email.bcc.slice().concat(recipientData);
  1511. this._updateBCCRecipients($deliveryList);
  1512. if (manuallyAdded) {
  1513. if (recipientData.length === 1) {
  1514. this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
  1515. } else if ( recipientData.length > 1) {
  1516. this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
  1517. }
  1518. }
  1519. this.setIcons(recipientList);
  1520. this._setRecipientsListEvents($deliveryList);
  1521. },
  1522. _addMobileRecipients: function(recipients, $deliveryList, manuallyAdded) { //NOSONAR
  1523. var recipientData = [];
  1524. var data;
  1525. if (manuallyAdded) {
  1526. data = this._verifyNewRecipients(recipients, this.mobile.to.slice()) || [];
  1527. } else {
  1528. this.mobile.to = [];
  1529. data = recipients || [];
  1530. }
  1531. for (var i=0; i<data.length;i++) {
  1532. recipientData.push({
  1533. defaultName: data[i].defaultName || "",
  1534. address: data[i].searchPath || data[i].address || "",
  1535. type: (data[i].type)? t.translate(data[i].type) : ((data[i].address)? data[i].address : ""),
  1536. id: _.uniqueId('recipientId_')
  1537. });
  1538. }
  1539. var listAttrs = {
  1540. recipients: recipientData,
  1541. removeLabel: t.translate("schdeule_delivery_remove_recipient_label"),
  1542. invalidLabel : t.translate("schedule_delivery_invalid_address")
  1543. };
  1544. var list = dot.simpleTemplate(recipientsListTemplate);
  1545. var recipientList = $(list(listAttrs));
  1546. $deliveryList.find('#delivery_mobile_recipients_' + this.contentUniqueId).append(recipientList);
  1547. // update lists
  1548. this.mobile.to = this.mobile.to.slice().concat(recipientData);
  1549. this._updateMobileRecipients($deliveryList);
  1550. if (manuallyAdded) {
  1551. if (recipientData.length === 1) {
  1552. this.glassContext.appController.showToast(t.translate('schedule_delivery_single_recipient_added'));
  1553. } else if ( recipientData.length > 1) {
  1554. this.glassContext.appController.showToast(t.translate('schedule_delivery_multiple_recipient_added', {recipient_count: recipientData.length}));
  1555. }
  1556. }
  1557. this.setIcons(recipientList);
  1558. this._setRecipientsListEvents($deliveryList);
  1559. },
  1560. _verifyNewRecipients: function(incomingRecipients, recipientsList) {
  1561. var newRecipients = [];
  1562. for (var i = 0; i < incomingRecipients.length; i++) {
  1563. var newId = true;
  1564. for (var j = 0; j < recipientsList.length; j++) {
  1565. if (incomingRecipients[i].searchPath === recipientsList[j].address ||
  1566. incomingRecipients[i].address === recipientsList[j].address ) {
  1567. newId = false;
  1568. break;
  1569. }
  1570. }
  1571. if (newId) {
  1572. newRecipients.push(incomingRecipients[i]);
  1573. }
  1574. }
  1575. return newRecipients;
  1576. },
  1577. _setRecipientsListEvents: function($deliveryList) {
  1578. var recipients = $deliveryList.find('.delivery_recipient:not(.clickBound)');
  1579. recipients.addClass('clickBound');
  1580. recipients.on('clicktap', function(event) {
  1581. event.cancelBubble = true;
  1582. if (event.stopPropagation) {
  1583. event.stopPropagation();
  1584. }
  1585. });
  1586. var recipientsDeleteButton = $deliveryList.find('.delivery_delete_recipient_icon:not(.clickBound)');
  1587. recipientsDeleteButton.addClass('clickBound');
  1588. recipientsDeleteButton.on('clicktap', function(event) {
  1589. event.cancelBubble = true;
  1590. if (event.stopPropagation) {
  1591. event.stopPropagation();
  1592. }
  1593. var $recipient = $(event.target).closest('.delivery_recipient');
  1594. this._removeRecipient($deliveryList, $recipient);
  1595. }.bind(this));
  1596. },
  1597. _removeRecipient: function ($deliveryList, $recipient) {
  1598. var recipientId = $recipient.attr('id');
  1599. var recipientType = $recipient.closest('.delivery_recipients_field').data('recipienttype');
  1600. $recipient.hide(__STANDARD_DELAY);
  1601. $recipient.remove();
  1602. switch(recipientType) {
  1603. case "email":
  1604. this.email.to = this._removeRecipientFromList(recipientId, this.email.to.slice());
  1605. // update deliveryoptions
  1606. this._updateEmailRecipients($deliveryList);
  1607. break;
  1608. case "cc":
  1609. this.email.cc = this._removeRecipientFromList(recipientId, this.email.cc.slice());
  1610. // update deliveryoptions
  1611. this._updateCCRecipients($deliveryList);
  1612. break;
  1613. case "bcc":
  1614. this.email.bcc = this._removeRecipientFromList(recipientId, this.email.bcc.slice());
  1615. // update deliveryoptions
  1616. this._updateBCCRecipients($deliveryList);
  1617. break;
  1618. case "mobile":
  1619. this.mobile.to = this._removeRecipientFromList(recipientId, this.mobile.to.slice());
  1620. // update deliveryoptions
  1621. this._updateMobileRecipients($deliveryList);
  1622. break;
  1623. default:
  1624. break;
  1625. }
  1626. },
  1627. _removeRecipientFromList: function(id, list) {
  1628. var index = -1;
  1629. for (var i = 0; i < list.length; i++) {
  1630. if (id === list[i].id) {
  1631. index = i;
  1632. break;
  1633. }
  1634. }
  1635. if (index >= 0) {
  1636. list.splice(index, 1);
  1637. }
  1638. var newList = list;
  1639. return newList;
  1640. },
  1641. _updateEmailRecipients: function($deliveryList) {
  1642. var $emailRecipientsEllipsis = $deliveryList.find('#delivery_email_ellipsis_' + this.contentUniqueId);
  1643. var $emailRecipientsList = $deliveryList.find('#delivery_email_recipients_' + this.contentUniqueId);
  1644. var $emailRecipientLabel = $deliveryList.find('label[for="delivery_email_recipients_edit_field_' + this.contentUniqueId+ '"]');
  1645. //update deliveryoptions
  1646. this.deliveryOptions.email.to = this.email.to.slice();
  1647. //Show ellipsis
  1648. this._checkForEllipsis($emailRecipientsList, $emailRecipientLabel, function(show) {
  1649. if (show) {
  1650. if (!$emailRecipientsList.hasClass('expanded')) {
  1651. $emailRecipientsEllipsis.show(__STANDARD_DELAY);
  1652. }
  1653. } else {
  1654. $emailRecipientsEllipsis.hide(__STANDARD_DELAY);
  1655. $emailRecipientsList.removeClass('expanded');
  1656. }
  1657. }.bind(this));
  1658. },
  1659. _updateCCRecipients: function($deliveryList) {
  1660. var $ccRecipientsEllipsis = $deliveryList.find('#delivery_cc_ellipsis_' + this.contentUniqueId);
  1661. var $ccRecipientsList = $deliveryList.find('#delivery_cc_recipients_' + this.contentUniqueId);
  1662. var $ccRecipientLabel = $deliveryList.find('label[for="delivery_cc_recipients_edit_field_' + this.contentUniqueId+ '"]');
  1663. //update deliveryoptions
  1664. this.deliveryOptions.email.cc = this.email.cc.slice();
  1665. //Show ellipsis
  1666. this._checkForEllipsis($ccRecipientsList, $ccRecipientLabel, function(show) {
  1667. if (show) {
  1668. if (!$ccRecipientsList.hasClass('expanded')) {
  1669. $ccRecipientsEllipsis.show(__STANDARD_DELAY);
  1670. }
  1671. } else {
  1672. $ccRecipientsEllipsis.hide(__STANDARD_DELAY);
  1673. $ccRecipientsList.removeClass('expanded');
  1674. }
  1675. }.bind(this));
  1676. },
  1677. _updateBCCRecipients: function($deliveryList) {
  1678. var $bccRecipientsEllipsis = $deliveryList.find('#delivery_bcc_ellipsis_' + this.contentUniqueId);
  1679. var $bccRecipientsList = $deliveryList.find('#delivery_bcc_recipients_' + this.contentUniqueId);
  1680. var $bccRecipientLabel = $deliveryList.find('label[for="delivery_bcc_recipients_edit_field_' + this.contentUniqueId+ '"]');
  1681. //update deliveryoptions
  1682. this.deliveryOptions.email.bcc = this.email.bcc.slice();
  1683. //Show ellipsis
  1684. this._checkForEllipsis($bccRecipientsList, $bccRecipientLabel, function(show) {
  1685. if (show) {
  1686. if (!$bccRecipientsList.hasClass('expanded')) {
  1687. $bccRecipientsEllipsis.show(__STANDARD_DELAY);
  1688. }
  1689. } else {
  1690. $bccRecipientsEllipsis.hide(__STANDARD_DELAY);
  1691. $bccRecipientsList.removeClass('expanded');
  1692. }
  1693. }.bind(this));
  1694. },
  1695. _updateMobileRecipients: function($deliveryList) {
  1696. var $mobileRecipientsEllipsis = $deliveryList.find('#delivery_mobile_ellipsis_' + this.contentUniqueId);
  1697. var $mobileRecipientsList = $deliveryList.find('#delivery_mobile_recipients_' + this.contentUniqueId);
  1698. var $mobileRecipientLabel = $deliveryList.find('label[for="delivery_mobile_recipients_' + this.contentUniqueId+ '"]');
  1699. //update deliveryoptions
  1700. this.deliveryOptions.mobile.to = this.mobile.to.slice();
  1701. //Show ellipsis
  1702. this._checkForEllipsis($mobileRecipientsList, $mobileRecipientLabel, function(show) {
  1703. if (show) {
  1704. if (!$mobileRecipientsList.hasClass('expanded')) {
  1705. $mobileRecipientsEllipsis.show(__STANDARD_DELAY);
  1706. }
  1707. } else {
  1708. $mobileRecipientsEllipsis.hide(__STANDARD_DELAY);
  1709. $mobileRecipientsList.removeClass('expanded');
  1710. }
  1711. }.bind(this));
  1712. },
  1713. _checkForEllipsis: function($list, $reference, callback, counter) { //NOSONAR
  1714. var rightXPositionOfRecipientField = $list.offset().left + $list.width();
  1715. //Not typein and not adding via the CA_AccountPickerView, the initial list is empty so no ellipes
  1716. if ($list.width() === 1) {
  1717. return;
  1718. }
  1719. if (!counter) {
  1720. counter = 0;
  1721. }
  1722. //Removes the invisible span. This is required so that there are no "invisible gaps" when list content gets moved around
  1723. $list.find("#invisibleSpan").remove();
  1724. var insertedInvisibleSpan = false;
  1725. if (($list.prop('scrollHeight') !== 0 && $reference.height() !== 0) || counter > 10) {
  1726. if ($list.prop('scrollHeight') > $reference.height()*1.25) {
  1727. if (typeof callback === 'function') {
  1728. callback(true);
  1729. }
  1730. //if the ellipse is showing
  1731. if (!$list.hasClass("expanded")){
  1732. $list.find(".delivery_recipient").each(function() {
  1733. //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
  1734. //the number 30 is an approximation of the width of the ellipse span
  1735. //only do this if it has not been completed already (because ellipse only appears on first line)
  1736. if ((($(this).offset().left + $(this).width()) > (rightXPositionOfRecipientField - 30) ) && ($(this).position().top === 0) && !insertedInvisibleSpan ){ //NOSONAR
  1737. $(this).before("<span id='invisibleSpan' style='width:30px; height:30px; visability:hidden'> </span>");
  1738. insertedInvisibleSpan = true;
  1739. }
  1740. });
  1741. }
  1742. } else {
  1743. if (typeof callback === 'function') {
  1744. callback(false);
  1745. }
  1746. }
  1747. } else {
  1748. var delay = __STANDARD_DELAY;
  1749. setTimeout(function() {
  1750. this._checkForEllipsis($list, $reference, callback, counter+1);
  1751. }.bind(this), delay);
  1752. }
  1753. },
  1754. _cleanRecipientsArray: function(list) {
  1755. var cleanArray = [];
  1756. for (var i = 0; i < list.length; i++) {
  1757. cleanArray.push({
  1758. address: list[i].address,
  1759. defaultName: list[i].defaultName,
  1760. type: (list[i].type)? t.translate(list[i].type) : ((list[i].address)? list[i].address : ""),
  1761. });
  1762. }
  1763. return cleanArray;
  1764. },
  1765. _setEditorDialogHideHandler: function() {
  1766. if (!$('body').hasClass('editorHideHandlerSet')) {
  1767. $('body').addClass('editorHideHandlerSet').on('clicktap.ckeditorDialog', function(event) {
  1768. var editorDialogs = $('body').find('.cke_dialog');
  1769. var editorDialogBg = $('body').find('.cke_dialog_background_cover');
  1770. if ((editorDialogs.is(event.target) || editorDialogs.has(event.target).length > 0) || (editorDialogBg.is(event.target) || editorDialogBg.has(event.target).length > 0)) {
  1771. event.stopPropagation();
  1772. }
  1773. });
  1774. }
  1775. }
  1776. });
  1777. return deliveryPickerView;
  1778. });