/* * Licensed Materials - Property of IBM * * IBM Cognos Products: SHARE * * (C) Copyright IBM Corp. 2015, 2016 * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with * IBM Corp. */ define([ 'jquery', 'q', 'bi/sharecommon/utils/translator', 'bi/commons/ui/View' ], function($, Q, t, View) { 'use strict'; var pdfOptionsView = View.extend({ init: function(options) { pdfOptionsView.inherited('init', this, arguments); this._initVariables(); $.extend(this, options); }, render: function() { var deferred = Q.defer(); this._setEvents(); deferred.resolve(); return deferred.promise; }, getOptions: function() { return this.pdfOptions; }, /* Private functions */ _setEvents: function() { var _self = this; this.$toggler.on('clicktap', function() { _self._closeOpenSiblings().then(function() { var content = { 'module': 'bi/content_apps/PdfOptionsView', 'glassContext': _self.glassContext, 'closeCallback': _self._setPdfOptions.bind(_self), // content_apps/PdfOptionsView wants the "pdfOptions" as an array of objects that have name/value properties. 'pdfOptions': $.map(_self.pdfOptions, function(value, key) { return [{ name: key, value: value }]; }) }; _self.slideout = _self.glassContext.appController.showSlideOut({ 'parent': _self.parentSlideout, 'position': _self.parentSlideout.position, 'width': '350', 'label': t.translate('schedule_pdf_options_name'), 'content': content }); }).done(); }); }, _setPdfOptions: function(options) { if (!options) { return; } var updatedPdfOptions = {}; options.forEach(function(option) { var value = option.value; if ((option.name).indexOf('Password') !== -1 && option.value.length) { var xmlDoc = $.parseXML(option.value); var $pwd = $(xmlDoc).find('password'); if ($pwd.text().length) { value = $pwd.text(); } } if (value !== undefined || value !== null) { updatedPdfOptions[option.name] = value; } }.bind(this)); this.pdfOptions = updatedPdfOptions; }, _initVariables: function() { this.glassContext = {}; this.$toggler = {}; this.parentSlideout = {}; this.slideout = null; this.pdfOptions = {}; this.updatedPdfOptions = {}; }, _closeOpenSiblings: function() { var deferred = Q.defer(); // Close any open open pdf slideouts if(this.slideout && this.slideout.open) { this.slideout.hide().then(function() { deferred.resolve(); }).done(); } else { deferred.resolve(); } return deferred.promise; } }); return pdfOptionsView; });