PdfOptionsView.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * (C) Copyright IBM Corp. 2015, 2016
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  9. * IBM Corp.
  10. */
  11. define([
  12. 'jquery',
  13. 'q',
  14. 'bi/sharecommon/utils/translator',
  15. 'bi/commons/ui/View'
  16. ], function($, Q, t, View) {
  17. 'use strict';
  18. var pdfOptionsView = View.extend({
  19. init: function(options) {
  20. pdfOptionsView.inherited('init', this, arguments);
  21. this._initVariables();
  22. $.extend(this, options);
  23. },
  24. render: function() {
  25. var deferred = Q.defer();
  26. this._setEvents();
  27. deferred.resolve();
  28. return deferred.promise;
  29. },
  30. getOptions: function() {
  31. return this.pdfOptions;
  32. },
  33. /* Private functions */
  34. _setEvents: function() {
  35. var _self = this;
  36. this.$toggler.on('clicktap', function() {
  37. _self._closeOpenSiblings().then(function() {
  38. var content = {
  39. 'module': 'bi/content_apps/PdfOptionsView',
  40. 'glassContext': _self.glassContext,
  41. 'closeCallback': _self._setPdfOptions.bind(_self),
  42. // content_apps/PdfOptionsView wants the "pdfOptions" as an array of objects that have name/value properties.
  43. 'pdfOptions': $.map(_self.pdfOptions, function(value, key) {
  44. return [{
  45. name: key,
  46. value: value
  47. }];
  48. })
  49. };
  50. _self.slideout = _self.glassContext.appController.showSlideOut({
  51. 'parent': _self.parentSlideout,
  52. 'position': _self.parentSlideout.position,
  53. 'width': '350',
  54. 'label': t.translate('schedule_pdf_options_name'),
  55. 'content': content
  56. });
  57. }).done();
  58. });
  59. },
  60. _setPdfOptions: function(options) {
  61. if (!options) {
  62. return;
  63. }
  64. var updatedPdfOptions = {};
  65. options.forEach(function(option) {
  66. var value = option.value;
  67. if ((option.name).indexOf('Password') !== -1 && option.value.length) {
  68. var xmlDoc = $.parseXML(option.value);
  69. var $pwd = $(xmlDoc).find('password');
  70. if ($pwd.text().length) {
  71. value = $pwd.text();
  72. }
  73. }
  74. if (value !== undefined || value !== null) {
  75. updatedPdfOptions[option.name] = value;
  76. }
  77. }.bind(this));
  78. this.pdfOptions = updatedPdfOptions;
  79. },
  80. _initVariables: function() {
  81. this.glassContext = {};
  82. this.$toggler = {};
  83. this.parentSlideout = {};
  84. this.slideout = null;
  85. this.pdfOptions = {};
  86. this.updatedPdfOptions = {};
  87. },
  88. _closeOpenSiblings: function() {
  89. var deferred = Q.defer();
  90. // Close any open open pdf slideouts
  91. if(this.slideout && this.slideout.open) {
  92. this.slideout.hide().then(function() {
  93. deferred.resolve();
  94. }).done();
  95. } else {
  96. deferred.resolve();
  97. }
  98. return deferred.promise;
  99. }
  100. });
  101. return pdfOptionsView;
  102. });