123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605 |
- /*
- 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<v_aOptions.length; i++)
- {
- v_oPromptParameters[v_sName].push({use: v_aOptions[i], display: v_aOptions[i]});
- }
- }
- }
- return v_oPromptParameters;
- }
- //search for complex prompt parameters
- function findPromptParametersComplex(options) {
- return options["promptParameters"];
- }
-
- function isOutputForDownload(v_sOutputFormat) {
- return ['spreadsheetML', 'xlsxData', 'CSV', 'XML'].indexOf(v_sOutputFormat) !== -1;
- }
- /**
- * Takes an object representing global parameter values where the name of the parameter is used
- * as the the object property name and converts to an array of parameter values.
- * e.g.
- * { 'product': {'name': 'product', 'values': [...]}, 'date': {'name':'date', 'values':[...]} }
- * becomes
- * [ {'name': 'product', 'values': [...]}, {'name':'date', 'values':[...]} ]
- */
- function convertToArrayImpl( v_oParameterValues ) {
- var v_aParameterValues = [];
- if (v_oParameterValues != null)
- {
- for (var v_sKey in v_oParameterValues)
- {
- if (v_oParameterValues.hasOwnProperty(v_sKey) && v_oParameterValues[v_sKey])
- {
- v_aParameterValues.push( v_oParameterValues[v_sKey] );
- }
- }
- }
- return v_aParameterValues;
- }
- function useViewer( options )
- {
- var v_bIsViewer = false;
- if (options.type === 'dataSet2') {
- // Datasets can only be edited
- v_bIsViewer = false;
- }
- else
- {
- switch (options.action)
- {
- case 'edit':
- v_bIsViewer = false;
- break;
- case 'run':
- case 'viewOutput':
- v_bIsViewer = true;
- break;
- default:
- if (options.isViewer || (options.cmProperties && options.cmProperties.type == "output"))
- {
- v_bIsViewer = true;
- }
- }
- }
-
- return v_bIsViewer;
- }
- return {
- reject : function( deferred, msg, tag ) {
- console.log( (tag ? (tag + ': ') : '' ) + msg );
- deferred.reject( new Error(msg) );
- },
- isObjectOfType : function( cmProperties, v_oType ) {
- if (cmProperties) {
- if (Array.isArray(v_oType)) {
- for (var idx = 0; idx < v_oType.length; ++idx) {
- if (this.isObjectOfType(cmProperties, v_oType[idx])) {
- return true;
- }
- }
- return false;
- }
- if (cmProperties.base && cmProperties.base[0].type === v_oType)
- {
- return true;
- }
- switch (cmProperties.type)
- {
- case v_oType:
- return true;
- case 'reportVersion':
- return cmProperties.parent &&
- (cmProperties.parent[0].type == v_oType || (cmProperties.parent[0].type == 'reportView' && cmProperties.parent[0].base[0].type == v_oType));
- case 'output':
- return cmProperties.parent &&
- (cmProperties.parent[0].parent[0].type == v_oType || (cmProperties.parent[0].parent[0].type == 'reportView' && cmProperties.parent[0].parent[0].base[0].type == v_oType));
- }
- }
- return false;
- },
-
- createTemplateParameters : function(v_oRSParameters) {
- var v_oTemplateParameters = {};
-
- v_oTemplateParameters.rsUrl = "pat/rsapp.htm";
- v_oTemplateParameters.rsParameters = JSON.stringify(v_oRSParameters);
-
- return v_oTemplateParameters;
- },
-
- /**
- * Takes an object representing global parameter values where the name of the parameter is used
- * as the the object property name and converts to an array of parameter values.
- * e.g.
- * { 'product': {'name': 'product', 'values': [...]}, 'date': {'name':'date', 'values':[...]} }
- * becomes
- * [ {'name': 'product', 'values': [...]}, {'name':'date', 'values':[...]} ]
- */
- convertToArray : function ( v_oParameterValues )
- {
- return convertToArrayImpl( v_oParameterValues );
- },
- extractGlassSettings : function( options )
- {
- var glassSettings;
- if (typeof options.ui_appbar !== 'undefined' || typeof options.ui_navbar !== 'undefined') {
- glassSettings = {};
- // Anything other than true is considered false by glass
- if (typeof options.ui_appbar !== 'undefined' && options.ui_appbar !== true) {
- glassSettings.ui_appbar = false;
- }
- if (typeof options.ui_navbar !== 'undefined' && options.ui_navbar !== true) {
- glassSettings.ui_navbar = false;
- }
- }
- return glassSettings;
- },
- isOutputFormatAllowed: function(v_sOutputFormat, glassContext)
- {
- switch(v_sOutputFormat)
- {
- case "CSV":
- return glassContext.hasCapability("canGenerateCSVOutput");
- case "XML":
- return glassContext.hasCapability("canGenerateXMLOutput");
- case "PDF":
- return glassContext.hasCapability("canGeneratePDFOutput");
- case "spreadsheetML":
- case "xlsxData":
- return glassContext.hasCapability("canGenerateXLSOutput");
- default:
- //"HTML"
- }
- return true;
- },
- createRSParameters : function( options, glassContext )
- {
- var v_sGatewayUrl= "../v1/disp";
- var v_sCafContextId = (glassContext && glassContext.cafContextId) || "";
-
- var v_sStoreId = options.cmProperties && options.cmProperties.id;
- var v_sReportStoreId = "";
- var v_sModuleStoreId = options.moduleId;
- var v_sModuleSearchPath = options.moduleSearchPath;
- var v_sPackageSearchPath = "";
- var v_sType = options.type || "";
-
- if (options.isNew) {
- if (this.isObjectOfType(options.cmProperties, 'package')) {
- v_sPackageSearchPath = options.cmProperties.searchPath + "/model[last()]";
- }
- else if (v_sStoreId) {
- // We have a CM object but it's not a package - assume module
- v_sModuleStoreId = v_sStoreId;
- v_sModuleSearchPath = options.cmProperties.searchPath;
- }
- }
- else {
- // Loading a report from the glass should only ever be done using a store id, never with a CM search path
- // failure to use a store id will result in the interactive viewer not working correctly.
- v_sReportStoreId = v_sStoreId;
- }
- var v_bIsViewer = useViewer( options );
- var v_sFormat = options.format;
- var v_bRunInAdvancedViewer = options.cmProperties && typeof options.cmProperties.runInAdvancedViewer !== 'undefined' ? !!options.cmProperties.runInAdvancedViewer : true;
- options.rsFinalRunOptions = options.rsFinalRunOptions || {};
-
- if (options.rsFinalRunOptions.prompt === undefined && options.prompt !== undefined)
- {
- options.rsFinalRunOptions.prompt = options.prompt;
- }
- if (!options.rsFinalRunOptions.globalParameters)
- {
- var v_oParameterValues = null;
- if (glassContext &&
- glassContext.services &&
- glassContext.services.userProfile &&
- glassContext.services.userProfile.userProfileSettings)
- {
- v_oParameterValues = glassContext.services.userProfile.userProfileSettings.parameter_values;
- }
- // Always calculate globalParameters. This ensures that RSVP can tell the difference between
- // the fact there are no global parameters and that that presence of global parameters is unknown.
- // In the latter case, RSVP will call CM to try to get them. If it knows there are none, we avoid the CM call.
- var v_aParameterValues = convertToArrayImpl( v_oParameterValues );
- options.rsFinalRunOptions.globalParameters = JSON.stringify( v_aParameterValues );
- }
-
- if (v_sFormat && !options.rsFinalRunOptions.format )
- {
- options.rsFinalRunOptions.format = v_sFormat;
- }
-
- if (options.rsFinalRunOptions.format && ! options.rsFinalRunOptions.Download)
- {
- options.rsFinalRunOptions.Download = isOutputForDownload(options.rsFinalRunOptions.format).toString();
- }
- if (options.editSpecification)
- {
- options.rsFinalRunOptions.editSpecification = options.editSpecification;
- }
- else if ( options.m_oLaunchParameters && options.m_oLaunchParameters.editSpecification )
- {
- options.rsFinalRunOptions.editSpecification = options.m_oLaunchParameters.editSpecification;
- }
- options.rsFinalRunOptions.isApplication = options.isApplication;
- var v_oRSParameters = {
- parentType: "RSFrame",
- rs_UIProfile : options.UIProfile,
- reportStoreID: v_sReportStoreId,
- gateway : v_sGatewayUrl,
- isViewer : v_bIsViewer,
- model : v_sPackageSearchPath,
- module : v_sModuleStoreId,
- moduleSearchPath : v_sModuleSearchPath,
- htmlContainerPath : document.location.pathname,
- productLocale : glassContext.services.userProfile.preferences.productLocale || "en",
- contentLocale : glassContext.services.userProfile.preferences.contentLocale || "en-us",
- runInAdvancedViewer : v_bRunInAdvancedViewer,
- cafcontextid : v_sCafContextId,
- type : v_sType,
- rsFinalRunOptions: options.objRef ? {
- //Supported viewer API parameters only
- format: v_sFormat || 'HTML',
- Download: isOutputForDownload(v_sFormat).toString(),
- bidi: options.bidi != undefined ? !!(options.bidi) : undefined,
- a11y: options.a11y != undefined ? !!(options.a11y) : undefined,
- prompt: options.prompt != undefined ? !!(options.prompt) : undefined,
- globalParameters: options.rsFinalRunOptions.globalParameters,
- editSpecification: options.rsFinalRunOptions.editSpecification,
- isApplication: !!options.rsFinalRunOptions.isApplication
- } : options.rsFinalRunOptions,
- parameterValuesXML: options.parameterValuesXML,
- cmProperties : options.cmProperties,
- outputSpec: options.outputSpec,
- glassSettings: this.extractGlassSettings(options)
- };
- if (options.contentLocale)
- {
- v_oRSParameters.rsFinalRunOptions.contentLocale = options.contentLocale;
- }
- if (options.action == 'run' && !this.isOutputFormatAllowed( options.rsFinalRunOptions.format, glassContext ))
- {
- // The selected format is invalid, arrange to close the perspective
- v_oRSParameters.closePerspective = true;
- }
-
- v_oRSParameters.startingTemplate = options.startingTemplate;
-
- v_oRSParameters.isSlideout = options.isSlideout;
-
- // need promptResponse parameter to pass through. in this case, viewer will show prompt pages of response retrieved from parent RS
- v_oRSParameters.promptResponse = options.promptResponse;
-
- var v_oPromptParameters = findPromptParameters(options);
- var v_oPromptParametersComplex = findPromptParametersComplex(options);
- var v_sParameterValues = rsPromptParameters.rsBuildPromptParameters(v_oPromptParameters, v_oPromptParametersComplex);
- if (v_sParameterValues)
- {
- v_oRSParameters.parameterValuesXML = v_sParameterValues;
- }
- return v_oRSParameters;
- },
- _hackFindPlugin: function(appView, id) {
- // If we used glassContext.findPlugin() it will find
- // plugins from the current perspective -- which MAY NOT be us!
- //
- // instead use the registeredPlugins on our app view
- // HACK - glass does not provide away to go from content-view to app-view
- // so have to use our cached value
- var plugin;
- if (id && appView ) {
- plugin = appView.registeredPlugins[id];
- }
- return plugin;
- },
- hackLockGlass: function(appView) {
- // glassContext.lockGlass() locks the glass for the current perspective
- // we only want to lock the glass for our perspective
- // when lockglass is called we may not be the current perspective
- // HACK until glass provides
- //console.log('rsCommon.hackLockGlass');
- if (appView) {
- appView.$('.navbar').addClass('disabled');
- appView.$('.appbar').addClass('disabled');
- }
- },
-
- hackUnlockGlass: function(appView) {
- // glassContext.lockGlass() locks the glass for the current perspective
- // we only want to lock the glass for our perspective
- // when lockglass is called we may not be the current perspective
- // HACK until glass provides
- //console.log('rsCommon.hackUnlockGlass');
- if (appView) {
- appView.$('.navbar').removeClass('disabled');
- appView.$('.appbar').removeClass('disabled');
- }
- },
- getAuthoringApplicationFromIFrame: function(iFrame) {
- return iFrame && iFrame.contentWindow && iFrame.contentWindow.Application;
- },
- F_XMLEncode: function(v_sString) {
- // < for <
- // > for >
- // & 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, "'" ).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;
- }
- };
- });
|