123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- define(['bi/authoring/utils/pat/rsPromptParameters', 'bi/authoring/utils/rsOpenHelper','bi/authoring/utils/rsCommon', 'jquery', 'q'], function(rsPromptParameters, OpenHelper, rsCommon, $, Q){
- 'use strict';
-
- 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':
-
-
-
-
-
- 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')
- {
-
- 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
- {
-
- 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':
-
-
-
-
- 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) {
-
- 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 (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();
-
- 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')
- {
-
- v_bShareable = !v_bEmbed;
- }
-
- 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;
- }
- };
- });
|