123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- /*
- IBM Confidential
- OCO Source Materials
- IBM Cognos Products: rs
- (C) Copyright IBM Corp. 2017, 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(['bi/authoring/utils/pat/rsPromptParameters', 'bi/authoring/utils/rsOpenHelper','bi/authoring/utils/rsCommon', 'jquery', 'q'], function(rsPromptParameters, OpenHelper, rsCommon, $, Q){
- 'use strict';
- // CM properties needed to generate share URL
- var M_aShareProperties = [
- { property: 'id', type: null },
- { property: 'type', type: null },
- { property: 'burstKey', type: ['output'] },
- { property: 'parent', type: null }
- ];
-
- function createShareUrl(v_oOpenSpec, v_oCmProperties) {
- var v_oUrlMap = {};
-
- if (v_oOpenSpec && v_oOpenSpec.contentView) {
- v_oUrlMap = $.extend(v_oUrlMap, rsCommon.extractGlassSettings(v_oOpenSpec.contentView));
- }
- var v_sObjRef = v_oCmProperties.id;
- switch (v_oCmProperties.type)
- {
- case 'dataSet2':
- v_oUrlMap.objRef = v_sObjRef;
- break;
- case 'output':
- // For burst output, use the id of the actual output object
- // otherwise use the id of output parent i.e. reportVersion
- // Using the version allows the system to select the most appropriate format/locale based on user's preferences
- // However there is no support for this if the output needs to be filtered by burst key
- // so in that case we go with the specific output object.
- v_oUrlMap.objRef = v_oCmProperties.burstKey ? v_sObjRef : v_oCmProperties.parent[0].id;
- break;
- default:
- v_oUrlMap.objRef = v_sObjRef;
- if (v_oOpenSpec.mode === 'current')
- {
- if (v_oOpenSpec.glassContext.currentAppView)
- {
- var v_oCurrentContentView = v_oOpenSpec.glassContext.currentAppView.currentContentView;
- if (v_oCurrentContentView)
- {
- switch (v_oCurrentContentView.perspective)
- {
- case 'authoring':
- var v_oApplication = v_oCurrentContentView.getAuthoringApplication && v_oCurrentContentView.getAuthoringApplication();
- if (v_oApplication)
- {
- if (v_oApplication.SharedState.Get("isViewer"))
- {
- v_oUrlMap.action = 'run';
-
- var v_sObjectType = v_oApplication.SharedState.Get("objectType");
- if (v_sObjectType != 'interactiveReport')
- {
- // No format needed on active reports
- var v_sViewer = v_oApplication.SharedState.Get("viewer");
- switch(v_sViewer.toUpperCase())
- {
- case "HTML":
- v_oUrlMap.format = "HTML";
- break;
- case "PDF":
- v_oUrlMap.format = "PDF";
- break;
- }
- }
- }
- else
- {
- v_oUrlMap.action = 'edit';
- }
- }
- else
- {
- // Being called before application was loaded so try alternative source of information
- v_oUrlMap.action = v_oCurrentContentView.action || (v_oCurrentContentView.isViewer ? 'run' : 'edit');
- if (v_oUrlMap.action != 'edit')
- {
- v_oUrlMap.format = v_oCurrentContentView.format;
- }
- }
- break;
- case 'classicviewer':
- // If requesting share link in classic viewer for non-output object, then action is
- // always run. No need to check for active report when setting format since
- // classic active reports are displayed stand alone (no glass) so there is no way
- // to request a share URL.
- v_oUrlMap.action = 'run';
-
- var v_sOutputFormat;
- if (v_oCurrentContentView.m_oRVFormParameters && v_oCurrentContentView.m_oRVFormParameters['run.outputFormat'] )
- {
- v_sOutputFormat = v_oCurrentContentView.m_oRVFormParameters['run.outputFormat'];
- }
- else
- {
- v_sOutputFormat = v_oCurrentContentView.format;
- }
-
- v_oUrlMap.format = v_sOutputFormat || 'HTML';
- break;
- }
- }
- }
- }
- break;
- }
- return v_oUrlMap;
- }
- function retrievePromptParameters(v_oOpenSpec, v_oUrlMap) {
- //Only include prompt values if sharing from current view/set as home
- if (v_oOpenSpec.mode == 'current')
- {
- if (v_oOpenSpec.glassContext.currentAppView)
- {
- var v_oCurrentContentView = v_oOpenSpec.glassContext.currentAppView.currentContentView;
- if (v_oCurrentContentView)
- {
- var v_oApplication = v_oCurrentContentView.getAuthoringApplication && v_oCurrentContentView.getAuthoringApplication();
- // If in classic viewer or authoring viewer, then get parameters
- if (v_oCurrentContentView.perspective == 'classicviewer' || (v_oApplication && v_oApplication.SharedState.Get("isViewer")))
- {
- var v_aParameters = v_oCurrentContentView.getParameterValues(true);
- if (v_aParameters && v_aParameters.length > 0)
- {
- v_oUrlMap.prompt = false;
- rsPromptParameters.rsBuildParameterUrl( v_oUrlMap, v_aParameters );
- }
- }
- }
- }
- }
- return v_oUrlMap;
- }
- function buildShareUrl( v_oOpenSpec, v_oCmProperties ) {
- var v_oUrlMap = createShareUrl(v_oOpenSpec, v_oCmProperties);
- return retrievePromptParameters(v_oOpenSpec, v_oUrlMap);
- }
- function prepareShareUrlMap(v_oOpenSpec) {
- var deferred = Q.defer();
- // Only ask for minimal set of properties needed to generate share URL
- OpenHelper.retreiveCMInfo(v_oOpenSpec.cmProperties, v_oOpenSpec.glassContext, M_aShareProperties)
- .then( buildShareUrl.bind(null, v_oOpenSpec) )
- .fail(function(err){
- console.log('OpenHelper.prepareShareUrlMap ... FAILED');
- deferred.reject(err);
- })
- .done( function(v_oUrlMap){
- deferred.resolve(v_oUrlMap);
- });
- return deferred.promise;
- }
- return {
- getShareUrlMap: function(v_oOpenSpec) {
- var deferred = Q.defer();
- prepareShareUrlMap(v_oOpenSpec)
- .catch( function(err){
- console.log('rsShareHelper.getShareUrlMap ... FAILED');
- deferred.reject(err);
- }).done( function(v_oUrlMap) {
- deferred.resolve(v_oUrlMap);
- });
- return deferred.promise;
- },
- buildShareUrlMap: function(v_oContentView ) {
- var v_oCmProperties = v_oContentView.cmProperties;
- var glassContext = v_oContentView.glassContext;
- var v_oOpenSpec = {
- mode: "current",
- glassContext: glassContext,
- contentView: v_oContentView
- };
- return buildShareUrl( v_oOpenSpec, v_oCmProperties );
- },
- isShareable: function(v_oCurrentContentView, v_bEmbed) {
- var v_bShareable = false;
- if (v_oCurrentContentView && v_oCurrentContentView.canRun())
- {
- var v_oAuthoringApp = v_oCurrentContentView.getAuthoringApplication();
- if (v_oCurrentContentView.perspective == 'datasets')
- {
- // Datasets don't support embed from overflow menu
- v_bShareable = !v_bEmbed;
- }
- // Must check shared state for viewer since this can change one perspective is opened (click pencil)
- else if (v_oCurrentContentView.perspective == 'classicviewer' || (v_oAuthoringApp && v_oAuthoringApp.SharedState.Get("isViewer")))
- {
- if (v_oAuthoringApp && v_oAuthoringApp.SharedState.Get("storeID"))
- {
- v_bShareable = true;
- }
- }
- }
- return v_bShareable;
- }
- };
- });
|