/* IBM Confidential OCO Source Materials IBM Cognos Products: rs (C) Copyright IBM Corp. 2003, 2020 The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office. */ define([ 'jquery', 'q', 'doT', 'bi/commons/utils/Utils', 'bi/authoring/utils/pat/rsPromptParameters' ], function($, Q, dot, Utils, rsPromptParameters){ 'use strict'; //search for simple prompt parameters : p_Product function findPromptParameters(options) { var v_oPromptParameters; for(var v_sKey in options) { if (options.hasOwnProperty(v_sKey) && v_sKey.length > 2 && v_sKey.indexOf('p_') == 0 && options[v_sKey]) { var v_sName = v_sKey.substring(2); if (!v_oPromptParameters) { v_oPromptParameters = {}; } if (!v_oPromptParameters[v_sName]) { v_oPromptParameters[v_sName] = []; } var v_aOptions = Array.isArray(options[v_sKey]) ? options[v_sKey] : [options[v_sKey]]; for(var i=0; i // & for & // ' for ' (required for attribute values delimited by the same character) // " for " (required for attribute values delimited by the same character) return v_sString.replace( /&/g, "&" ).replace( //g, ">" ).replace( /'/g, "'" ).replace( /"/g, """ ); }, /** * The content view getContent method adds cmProperties to the response. However, when the resulting URL is submitted after pressing F5, * the cmProeprties is passed to the content view init() method not as the original object but rather a series of properties whose name is * "cmProperties[prop name]". * To avoid this unexpected flatening of the object, getContent puts the JSON string representation of cmProperties instead. * In the case of saved output, reportProperties is also stringified. * This method turns these string back into the original object form. */ decodeAndMoveCMProperties: function(options) { if (options && options.cmPropStr && !options.cmProperties) { var v_oCmProperties; try { v_oCmProperties = JSON.parse(options.cmPropStr); } catch (e) { v_oCmProperties = null; } if (v_oCmProperties) { options.cmProperties = v_oCmProperties; } } delete options.cmPropStr; if (options && options.reportPropStr && !options.reportProperties) { var v_oReportProperties; try { v_oReportProperties = JSON.parse(options.reportPropStr); } catch (e) { v_oReportProperties = null; } if (v_oReportProperties) { options.reportProperties = v_oReportProperties; } } delete options.reportPropStr; }, /** * rsEncodedOptions are used to pass rs options in such a way as to avoid any possible conflict with other * parameters that exist or may exist in the future that originate from some other component. */ decodeAndMoveRSOptions: function(options) { if (options && options.rsEncodedOptions) { // options.rsEncodedOptions exists, decode it and copy it into options var v_oRsOptions = JSON.parse(options.rsEncodedOptions); Object.keys(v_oRsOptions).forEach( function(v_sKey) { options[v_sKey] = v_oRsOptions[v_sKey]; }); delete options.rsEncodedOptions; } }, M_aConvertList : [ 'isViewer', 'isNew', 'isApplication', 'a11y', 'bidi', 'runInAdvancedViewer', 'prompt', 'rsFinalRunOptions', 'promptParameters', 'ui_appbar', 'ui_navbar' ], convertStringQSToValues: function(options, glassContext, trimURLParameterValues) { var v_bStringOnlyQS = glassContext.getCoreSvc('.FeatureChecker').checkValue('ba-glass', 'stringOnlyQS', 'enabled'); if (!v_bStringOnlyQS) { return; } for(var propertyName in options) { if (options[propertyName]) { if (this.M_aConvertList.indexOf(propertyName) != -1) { if (typeof options[propertyName] === 'object') { this.convertStringQSToValues(options[propertyName], glassContext); } else if (typeof options[propertyName] === 'string') { if (options[propertyName] === 'true') { options[propertyName] = true; } else if (options[propertyName] === 'false') { options[propertyName] = false; } else { var v_numberValue = Number(options[propertyName]); options[propertyName] = isNaN(v_numberValue) ? options[propertyName] : v_numberValue; } } } else if (propertyName.indexOf('p_') == 0 && trimURLParameterValues === true) { options[propertyName] = options[propertyName].trim(); } } } }, getAvailableOutputs: function(glassContext, v_oOutputProperties) { return glassContext.getSvc('.Content') .then(function(v_oContentSvc) { var v_sCMQueryUrl = v_oContentSvc.getBaseObjectsURL() + '/' + v_oOutputProperties.parent[0].id + '/outputs?fields=dataDescriptor,parent,locale,format,permissions,ancestors,lastPage'; return v_oContentSvc.get(v_sCMQueryUrl, {}); }); }, /** * Generic implementation of glass getContent method. * @param options The options parameter passed from glass * @param v_oContentView The actual content view instance (rv or cv) being called * @param rsShareHelper Pass share helper module to avoid having to declare it and introduce circular dependency */ getContent: function( options, v_oContentView, rsShareHelper ) { var v_bOnlyBookmarkContent = options && options.mode == "bookmark"; var v_oReturn = {}; var v_oCmProperties; if (v_oContentView.cmProperties) { // Start with the basic share link v_oReturn = rsShareHelper.buildShareUrlMap(v_oContentView); // The glass adds the perspective to the URL created from the getContent response. // As a result, when the URL is processed by the browser (via F5 or copy/paste) // it is not handled as a share link due to the presence of the perspective. // Therefore the authoring code that expands the share link information to the full set of data needed by authoring is not called. // As a result, we are forced to add additional information to ensure the URL created from the getContent response // actually works. // Need minimal cm property information v_oCmProperties = { id: v_oContentView.cmProperties.id, type: v_oContentView.cmProperties.type, defaultName: v_oContentView.cmProperties.defaultName, permissions: v_oContentView.cmProperties.permissions }; if (v_oContentView.cmProperties.type == 'output') { // Saved output requires more info if (v_oContentView.cmProperties.ancestors) { var v_sReportName = v_oContentView.cmProperties.ancestors[v_oContentView.cmProperties.ancestors.length-2].defaultName; v_oCmProperties.defaultName = v_sReportName + " - " + v_oContentView.cmProperties.modificationTime.substring(0, 10)+ " - " + v_oContentView.cmProperties.format; } v_oCmProperties.modificationTime = v_oContentView.cmProperties.modificationTime; v_oCmProperties.format = v_oContentView.cmProperties.format; if (v_oContentView.cmProperties.parent && v_oContentView.cmProperties.parent.length > 0) { v_oCmProperties.parent = [ { id: v_oContentView.cmProperties.parent[0].id, type: v_oContentView.cmProperties.parent[0].type } ]; } if (v_oContentView.reportProperties) { v_oReturn.reportPropStr = JSON.stringify( { id: v_oContentView.reportProperties.id, type: v_oContentView.reportProperties.type, defaultName: v_oContentView.reportProperties.defaultName } ); } v_oReturn.type = 'output'; delete v_oReturn.objRef; } v_oReturn.cmPropStr = JSON.stringify( v_oCmProperties ); } if (v_oContentView.id) { v_oReturn.id = v_oContentView.id; } if (!v_bOnlyBookmarkContent) { v_oReturn.application = v_oContentView.getApplicationContent( v_oReturn, v_oCmProperties ); } else { // APAR 120836 REPORT FAILS TO RUN IN IE11 IF THE DRILL-THROUGH PROMPTPARAMETER VALUES ARE LARGER THAN 2,083 CHAR LIMIT // On bookmark, remove the prompt params as that can make the URL too long leading to a long REFERER header delete v_oReturn.promptParameters; } return v_oReturn; } }; });