WidgetContextManager.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2013, 2014
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. dojo.provide("WidgetContextManager");
  13. dojo.declare("WidgetContextManager", null, {
  14. // PP stands for Property of Payload
  15. PP_WIDGET_CONTEXT: "com.ibm.widget.context",
  16. PP_REPORT_PROMPT_CONTEXT: "com.ibm.widget.context.report.prompt",
  17. PP_REPORT_DRILL_CONTEXT: "com.ibm.widget.context.report.drill",
  18. PP_VALUES: "values",
  19. PP_RANGES: "ranges",
  20. PP_MULTIVALUED: "multivalued",
  21. PP_MODELITEM: "modelItem",
  22. PP_MODELINFO: "modelInfo",
  23. PP_PROMPT: "prompt",
  24. PP_DRILL: "drill",
  25. PP_SELECT_CHOICES: "selectChoices",
  26. PP_BUX_SELECTVALUECONTROL_CONTEXT: "com.ibm.widget.context.bux.selectValueControl",
  27. PP_BUX_SELECTION_CONTEXT: "com.ibm.widget.context.bux.selection",
  28. PP_CASCADEPROMPT_CLEAR: "clearCascadePromptParams",
  29. EVENT_NAME_PROMPT: "com.ibm.widget.contextChanged.prompt",
  30. EVENT_NAME_DRILL: "com.ibm.widget.contextChanged.drill",
  31. EVENT_NAME_SELECTVALUECONTROL: "com.ibm.widget.contextChanged.selectValueControl",
  32. DEFAULT_MODEL_PATH: ".",
  33. m_widget: null, //Viewer Widget Instance
  34. m_oWidgetContextContainer: null, //Contains complete context of current widget
  35. m_oPromptContextContainer: null, //Contains complete prompt context of current widget
  36. m_oDrillContextContainer : null, //contains complete drill context container
  37. m_oPromptGenericContext : null, //contains the prompt in generic context format
  38. m_oDrillGenericContext : null, // contains the drill info in generic context format
  39. m_oFilterGenericContext : null, // contains the Filter (slider/selectValue) info in generic context format
  40. m_oSelectionFilterContext: null, // contains the selection filter info in generic context format
  41. m_oContextCollection: null, // contains the any context info in generic context format. Used for Active Report
  42. m_oWidgetContextObject: null, //Working object to share between functions
  43. m_oPromptContextObject: null, //Working object to share between functions
  44. m_oDrillContextObject: null, //Working object to share between functions
  45. m_aSelectionFilterObjects: null, // contains serialized json format of selection objects to be used in re-select
  46. constructor: function(widget) {
  47. this.m_widget = widget;
  48. this.m_oWidgetContextContainer = {};
  49. this.m_oPromptContextContainer = {};
  50. this.m_oDrillContextContainer = {};
  51. this.m_oPromptGenericContext = {};
  52. this.m_oDrillGenericContext = {};
  53. this.m_oFilterGenericContext = {};
  54. this.m_oSelectionFilterContext = {};
  55. this.m_oContextCollection = {};
  56. this.m_oWidgetContextObject = {};
  57. this.m_oPromptContextObject = {};
  58. this.m_oDrillContextObject = {};
  59. this.m_aSelectionFilterObjects = null;
  60. },
  61. /*
  62. * This function is to support onDrop filter.
  63. * Canvas collects all widgets' widget context and send array of contexts to the widget being dropped.
  64. *
  65. * m_oWidgetContextContainer stores name/value pairs of its prompt and drill context
  66. *
  67. * returns an object with the following fields in it
  68. * {'com.ibm.widget.context': object,
  69. * 'clientId': string
  70. * }
  71. */
  72. getWidgetContextObject: function() {
  73. var payload = {};
  74. if (this.m_oWidgetContextContainer) {
  75. payload[this.PP_WIDGET_CONTEXT] = this.m_oWidgetContextContainer;
  76. if (this.m_widget) {
  77. payload.clientId = this.m_widget.getWidgetId();
  78. }
  79. }
  80. return payload;
  81. },
  82. /*
  83. * This function is called from ViewerIWidget.canFilter
  84. */
  85. getFilterFirstItemName: function() {
  86. var genericContext = this.m_oFilterGenericContext;
  87. if (genericContext) {
  88. var valuesOrRanges=(genericContext.values ? genericContext.values : genericContext.ranges);
  89. for (firstName in valuesOrRanges) {
  90. return firstName;
  91. }
  92. }
  93. //When facets are being cleared, they supply the name as neither values or ranges.
  94. for (var firstName in genericContext) {
  95. return firstName;
  96. }
  97. return null;
  98. },
  99. getItemNames: function(payload) {
  100. var names = [];
  101. var genericContext = payload[this.PP_WIDGET_CONTEXT];
  102. if (genericContext) {
  103. var valuesOrRanges=(genericContext.values ? genericContext.values : genericContext.ranges);
  104. for (var field in valuesOrRanges) {
  105. names.push(field);
  106. }
  107. return names;
  108. }
  109. //When facets are being cleared, they supply the name as neither values or ranges.
  110. for (var field in genericContext) {
  111. names.push(field);
  112. }
  113. return names;
  114. },
  115. /*
  116. * publish prompt event with generic payload
  117. *
  118. */
  119. raisePromptEvent: function(sSharedPrompts, aServerRequestEnvParams, sActionParam, sModelPath,clearCascadePromptParams) {
  120. var oGeneralizedPayload = this._buildGeneralizedPromptPayload(sSharedPrompts, aServerRequestEnvParams, sActionParam, sModelPath,clearCascadePromptParams);
  121. if (oGeneralizedPayload) {
  122. this.m_widget.fireEvent(this.EVENT_NAME_PROMPT, null, oGeneralizedPayload);
  123. this._updatePromptContext(oGeneralizedPayload);
  124. this._updateWidgetContextContainer();
  125. }
  126. },
  127. _updatePromptContext : function( payload ) {
  128. this._updatePromptGenericContext( payload );
  129. this._updatePromptContextContainer(payload);
  130. },
  131. _resetWorkingMembers: function () {
  132. this.m_oWidgetContextObject = {};
  133. this.m_oPromptContextObject = {};
  134. this.m_oDrillContextObject = {};
  135. },
  136. /*
  137. * This function is called from ViewerIWidget.onGenericSelectValueControl
  138. */
  139. updateFilterContext: function(contextJSON) {
  140. this.m_oFilterGenericContext = contextJSON[this.PP_WIDGET_CONTEXT];
  141. this._updateWidgetContextContainer();
  142. },
  143. /*
  144. * If this payload represents a selectValueControl, return the controlType...otherwise, return null.
  145. *
  146. * {
  147. * "com.ibm.widget.context": {
  148. * "values": { "productcategory": [ "Electronics" ] }
  149. * },
  150. * "com.ibm.widget.context.bux.selectValueControl": {
  151. * "selectValueControl": { "controlType": "facet", "id": "testID" }
  152. * }
  153. * }
  154. */
  155. getSelectValueControlTypeFromPayload: function( payload ) {
  156. var selectValueControlContext = payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT];
  157. if (selectValueControlContext && selectValueControlContext["selectValueControl"]) {
  158. return selectValueControlContext["selectValueControl"]["controlType"];
  159. }
  160. return null;
  161. },
  162. getSelectValuePropertyFromPayload: function( payload, property ) {
  163. var selectValueControlContext = payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT];
  164. if (selectValueControlContext && selectValueControlContext["selectValueControl"]) {
  165. return selectValueControlContext["selectValueControl"][property];
  166. }
  167. return null;
  168. },
  169. /**
  170. * It is important that prompt context and drill context be updated prior to calling this function.
  171. */
  172. _updateWidgetContextContainer: function() {
  173. this.m_oWidgetContextContainer = {};
  174. var values = null;
  175. if (this.m_oDrillGenericContext[this.PP_VALUES]) {
  176. values = dojo.mixin( values, this.m_oDrillGenericContext[this.PP_VALUES] );
  177. }
  178. if (this.m_oPromptGenericContext[this.PP_VALUES]) {
  179. values = dojo.mixin( values, this.m_oPromptGenericContext[this.PP_VALUES] );
  180. }
  181. if (this.m_oFilterGenericContext[this.PP_VALUES]) {
  182. values = dojo.mixin( values, this.m_oFilterGenericContext[this.PP_VALUES] );
  183. }
  184. if (this.m_oSelectionFilterContext[this.PP_VALUES]) {
  185. values = dojo.mixin( values, this.m_oSelectionFilterContext[this.PP_VALUES] );
  186. }
  187. if (values) {
  188. this.m_oWidgetContextContainer[this.PP_VALUES] = values;
  189. }
  190. var ranges = null;
  191. if (this.m_oPromptGenericContext[this.PP_RANGES]) {
  192. ranges = dojo.mixin( ranges, this.m_oPromptGenericContext[this.PP_RANGES] );
  193. }
  194. if (this.m_oFilterGenericContext[this.PP_RANGES]) {
  195. ranges = dojo.mixin( ranges, this.m_oFilterGenericContext[this.PP_RANGES] );
  196. }
  197. if (ranges) {
  198. this.m_oWidgetContextContainer[this.PP_RANGES] = ranges;
  199. }
  200. },
  201. /**
  202. * Updates the prompt generic context and the widget context.
  203. */
  204. _updatePromptGenericContext : function(payload) {
  205. if ( payload[this.PP_WIDGET_CONTEXT] ) {
  206. this.m_oPromptGenericContext = payload[this.PP_WIDGET_CONTEXT];
  207. }
  208. },
  209. _updatePromptContextContainer: function(payload) {
  210. if (payload[this.PP_REPORT_PROMPT_CONTEXT] && payload[this.PP_REPORT_PROMPT_CONTEXT][this.PP_PROMPT]) {
  211. this.m_oPromptContextContainer = payload[this.PP_REPORT_PROMPT_CONTEXT][this.PP_PROMPT];
  212. }
  213. },
  214. /*
  215. * returns generalized form of prompt payload
  216. *
  217. */
  218. _buildGeneralizedPromptPayload: function(sSharedPrompts, aServerRequestEnvParams, sActionParam, sModelPath,clearCascadePromptParams) {
  219. var payload = null;
  220. this._resetWorkingMembers();
  221. var bResult = this._buildContextsFromPrompt(sSharedPrompts, aServerRequestEnvParams);
  222. if (bResult) {
  223. payload = {};
  224. payload[this.PP_WIDGET_CONTEXT] = this.m_oWidgetContextObject;
  225. var oItemSpecObject = {};
  226. oItemSpecObject[sModelPath]= this.m_oPromptContextObject;
  227. payload[this.PP_REPORT_PROMPT_CONTEXT] = {
  228. "prompt": {
  229. "id": this.m_widget.iContext.widgetId,
  230. "action": sActionParam,
  231. "itemSpecification": oItemSpecObject
  232. }
  233. };
  234. payload[this.PP_CASCADEPROMPT_CLEAR]=clearCascadePromptParams;
  235. }
  236. return payload;
  237. },
  238. _getReportParameterNodes: function(sSharedPrompts) {
  239. var xmlDom = XMLBuilderLoadXMLFromString(sSharedPrompts);
  240. if (!xmlDom) {
  241. return null;
  242. }
  243. var cvTransientSpec = xmlDom.firstChild;
  244. if (!cvTransientSpec) {
  245. return null;
  246. }
  247. var reportParameters = XMLHelper_FindChildByTagName( cvTransientSpec, "reportParameters", true);
  248. if (!reportParameters) {
  249. return null;
  250. }
  251. var reportParameterNodes = XMLHelper_FindChildrenByTagName( reportParameters, "reportParameter", false);
  252. if (!reportParameterNodes) {
  253. return null;
  254. }
  255. return reportParameterNodes;
  256. },
  257. _getSelectChoicesXMLString : function(sName, aServerRequestEnvParams) {
  258. var sSelectChoicesXML = null;
  259. var sp_ParameterName = 'p_' + sName;
  260. if( aServerRequestEnvParams.get(sp_ParameterName )) {
  261. sSelectChoicesXML = aServerRequestEnvParams.get(sp_ParameterName);
  262. }
  263. return sSelectChoicesXML;
  264. },
  265. _getSelectChoicesNode : function(sSelectChoicesXML) {
  266. var nNode = null;
  267. if( sSelectChoicesXML) {
  268. var xmlDom = XMLBuilderLoadXMLFromString(sSelectChoicesXML, true);
  269. if (xmlDom && xmlDom.firstChild) {
  270. nNode = xmlDom.firstChild;
  271. }
  272. }
  273. return nNode;
  274. },
  275. /*
  276. * Main processor for prompt, handles ranges and single/multi-selects
  277. *
  278. */
  279. _buildContextsFromPrompt: function(sSharedPrompts, aServerRequestEnvParams) {
  280. var reportParameterNodes = this._getReportParameterNodes(sSharedPrompts);
  281. if (reportParameterNodes===null) {
  282. return false;
  283. }
  284. for ( var i in reportParameterNodes )
  285. {
  286. var reportParameterNode = reportParameterNodes[i];
  287. var sName = reportParameterNode.getAttribute( "parameterName");
  288. var sSelectChoicesXML = this._getSelectChoicesXMLString(sName, aServerRequestEnvParams);
  289. var nSelectChoicesNode = this._getSelectChoicesNode(sSelectChoicesXML);
  290. if (nSelectChoicesNode) {
  291. var oPromptDetailObject, aValue, sValuesOrRanges;
  292. if (!this._isPromptRangeType(sSelectChoicesXML)) {
  293. var aPromptContextValues = this._buildReportContextValuesFromPromptSelectOption(nSelectChoicesNode);
  294. oPromptDetailObject = this._createPromptDetailObject(sSelectChoicesXML, reportParameterNode.getAttribute( "modelItem"), reportParameterNode.getAttribute( "multivalued"), aPromptContextValues);
  295. aValue = this._buildValuesArrayFromReportContextValueArray(aPromptContextValues);
  296. sValuesOrRanges = this.PP_VALUES;
  297. } else { // Range type
  298. aValue = this._buildMinMaxArrayFromRangePrompt(nSelectChoicesNode);
  299. oPromptDetailObject = this._createPromptDetailObject(sSelectChoicesXML, reportParameterNode.getAttribute( "modelItem"), reportParameterNode.getAttribute( "multivalued"), aValue);
  300. sValuesOrRanges = this.PP_RANGES;
  301. }
  302. //Working area for Prompt Context
  303. this.m_oPromptContextObject[sName] = oPromptDetailObject;
  304. //Working area for Widget Context Values or Ranges
  305. if(!this.m_oWidgetContextObject[sValuesOrRanges]) {
  306. this.m_oWidgetContextObject[sValuesOrRanges] = {};
  307. };
  308. this.m_oWidgetContextObject[sValuesOrRanges][sName] = aValue;
  309. }
  310. }
  311. return true;
  312. },
  313. _createPromptDetailObject: function (sSelectChoicesXML, sModelItem, multivalued, aPromptContextValues) {
  314. var oPromptDetail = {};
  315. oPromptDetail[this.PP_SELECT_CHOICES] = sSelectChoicesXML;
  316. if (sModelItem !== null) {
  317. oPromptDetail[this.PP_MODELITEM] = sModelItem;
  318. }
  319. if (multivalued !== null) {
  320. oPromptDetail[this.PP_MULTIVALUED] = true;
  321. }
  322. oPromptDetail[this.PP_VALUES] = aPromptContextValues;
  323. return oPromptDetail;
  324. },
  325. _isPromptRangeType: function(sSelectChoicesXML) {
  326. var regExp = new RegExp(/^<selectChoices><select[\s\S]*Range/);
  327. return regExp.test(sSelectChoicesXML);
  328. },
  329. /*
  330. * returns an array which contains below objects. the array is values of 'values' property of an item in Report Context
  331. {
  332.                [
  333.                   {
  334.                      "caption":"2004",
  335.                      "mun":"[Great Outdoors Company].[Years].[Year]->:PC].[@MEMBER].[20040101-20041231]"
  336.                   },
  337.                   {
  338.                      "caption":"2005",
  339.                      "mun":"[Great Outdoors Company].[Years].[Year]->:PC].[@MEMBER].[20050101-20051231]"
  340.                   }
  341.                ]
  342. }
  343. */
  344. _buildReportContextValuesFromPromptSelectOption: function (nSelectChoices) {
  345. var aValues = [];
  346. if(nSelectChoices) {
  347. var nodeList = dojo.query("selectOption[displayValue]", nSelectChoices);
  348. if (nodeList.length > 0) {
  349. for (var i = 0; i < nodeList.length; i++) {
  350. var caption = nodeList[i].getAttribute("displayValue");
  351. var useValue = nodeList[i].getAttribute("useValue");
  352. var value = {"caption": caption, "use": useValue};
  353. aValues.push(value);
  354. }
  355. }
  356. }
  357. return aValues;
  358. },
  359. /*
  360. * returns an array which contains value of caption property from Report Context Values array
  361. {
  362. [
  363. "2004",
  364. "2005"
  365. ]
  366. }
  367. */
  368. _buildValuesArrayFromReportContextValueArray: function (aReportContextValues) {
  369. var aWidgetContextValues = [];
  370. if (aReportContextValues && aReportContextValues.length>0) {
  371. for( var i=0; i<aReportContextValues.length; i++) {
  372. var caption = aReportContextValues[i].caption;
  373. if (caption) {
  374. aWidgetContextValues.push(caption);
  375. }
  376. }
  377. }
  378. return aWidgetContextValues;
  379. },
  380. /**
  381. * returns json object if input include select<any>Range node.
  382. [
  383. { "min: 123.45,
  384. "minDisplay": "$123.45",
  385. "max": 999.99,
  386. "maxDisplay": "$999.99" }
  387. },
  388. { "min: 1123.45,
  389. "minDisplay": "$1,123.45",
  390. "max": 9599.99,
  391. "maxDisplay": "$9,599.99"
  392. }
  393. ]
  394. *
  395. *
  396. *
  397. * @param {node} nSelectBoundRange is a node which may include selectBoundRange child.
  398. * examples,
  399. * "<selectChoices><selectBoundRange selected=\"true\"><start useValue=\"Camping\" displayValue=\"Camping\"/><end useValue=\"Golf\" displayValue=\"Golf\"/></selectBoundRange></selectChoices>";
  400. * <selectChoices><selectUnboundedEndRange selected="true"><start useValue="2004-07-12T00:00:00.000" displayValue="Jul 12, 2004"/></selectUnboundedEndRange></selectChoices>
  401. * <selectChoices><selectUnboundedStartRange selected="true"><end useValue="2011-07-11T23:59:59.999" displayValue="Jul 11, 2011"/></selectUnboundedStartRange></selectChoices>
  402. */
  403. _buildMinMaxArrayFromRangePrompt: function (nSelectChoices) {
  404. var aRanges = [];
  405. if (nSelectChoices && nSelectChoices.childNodes && nSelectChoices.childNodes.length>0) {
  406. var length = nSelectChoices.childNodes.length;
  407. for (var i=0; i<length; i++ ) {
  408. var oMinMax = this._buildMinMaxFromSelectAnyRange(nSelectChoices.childNodes[i] );
  409. if (oMinMax) {
  410. aRanges.push(oMinMax);
  411. }
  412. }
  413. }
  414. return aRanges;
  415. },
  416. /**
  417. * returns
  418. { "min:" 123.45,
  419. "minDisplay": "$123.45",
  420. "max": 999.99,
  421. "maxDisplay": "$999.99" }
  422. }
  423. *
  424. */
  425. _buildMinMaxFromSelectAnyRange: function (nRangeNode) {
  426. var oMinMax = null;
  427. if(nRangeNode) {
  428. var nodeList = dojo.query("[displayValue]", nRangeNode);
  429. if (nodeList.length > 0) {
  430. oMinMax = {};
  431. for (var i = 0; i < nodeList.length; i++) {
  432. var node = nodeList[i];
  433. var sPropertyName = (node.nodeName === "start") ? "min" : "max";
  434. oMinMax[sPropertyName] = node.getAttribute("useValue");
  435. oMinMax[ sPropertyName + 'Display' ] = node.getAttribute("displayValue");
  436. }
  437. }
  438. }
  439. return oMinMax;
  440. },
  441. /*
  442. * handling incoming prompt event with generalized payload.
  443. */
  444. handleIncomingPromptEvent: function(evt) {
  445. if (!evt || !evt.payload) {
  446. return;
  447. }
  448. var oLegacyPayload = this._convertToLegacyPromptPayload(evt.payload);
  449. if (oLegacyPayload) {
  450. var oNewEvt = {"payload": oLegacyPayload};
  451. this.m_widget.onPromptLegacyPayload(oNewEvt);
  452. }
  453. },
  454. /*
  455. * return prompt payload that is pre-generic event.
  456. */
  457. _convertToLegacyPromptPayload: function (oGeneralizedPayload) {
  458. var oPayload = null;
  459. var oPromptContext = oGeneralizedPayload[this.PP_REPORT_PROMPT_CONTEXT];
  460. if (oPromptContext && oPromptContext.prompt ) {
  461. oPromptContext = oPromptContext.prompt;
  462. oPayload = {};
  463. oPayload.cv_id = oPromptContext.id;
  464. oPayload.parameters = this._genLegacyPromptParameterArrayFromItemSpec(oPromptContext.itemSpecification);
  465. oPayload.clearCascadePromptParams = oGeneralizedPayload[this.PP_CASCADEPROMPT_CLEAR];
  466. }
  467. else if (oGeneralizedPayload[this.PP_WIDGET_CONTEXT] && oGeneralizedPayload[this.PP_WIDGET_CONTEXT].values) {
  468. // Handle simple name/value pairs
  469. oPayload = {};
  470. oPayload.parameters = [];
  471. var paramValues = oGeneralizedPayload[this.PP_WIDGET_CONTEXT].values;
  472. for (var param in paramValues) {
  473. var paramValue = paramValues[param];
  474. if (paramValue && paramValue.length > 0) {
  475. // We already have a selectChoices
  476. if (paramValue.length == 1 && paramValue[0].indexOf("<selectChoices>") === 0) {
  477. oPayload.parameters.push({"parmName" : param, "parmValue" : paramValue[0]});
  478. }
  479. else {
  480. // We have simple values, build a select choices out of them
  481. var selectChoice = "<selectChoices>";
  482. for (var i=0; i < paramValue.length; i++) {
  483. selectChoice += "<selectOption useValue=\"" + paramValue[i] + "\" displayValue=\"" + paramValue[i] + "\"/>";
  484. }
  485. selectChoice += "</selectChoices>";
  486. oPayload.parameters.push({"parmName" : param, "parmValue" : selectChoice});
  487. }
  488. }
  489. }
  490. oPayload.clearCascadePromptParams = oGeneralizedPayload[this.PP_CASCADEPROMPT_CLEAR];
  491. }
  492. return oPayload;
  493. },
  494. /*
  495. *
  496. var paramAttributes = {
  497. parmName: sParameterName,
  498. parmValue: decodeURIComponent(this.m_oServerRequest.m_oParams[ sp_ParameterName ]),
  499. modelItem: sModelItem,
  500. multivalued: true //optional
  501. };
  502. */
  503. _genLegacyPromptParameterArrayFromItemSpec: function (oSpec) {
  504. if (!oSpec) {
  505. return null;
  506. }
  507. var oItemObject = this._getFirstPropertyOfObject(oSpec);
  508. var aParameters = [];
  509. for(var sName in oItemObject) {
  510. var oDetail = oItemObject[sName];
  511. var paramAttributes = {
  512. parmName: sName,
  513. parmValue: oDetail[this.PP_SELECT_CHOICES],
  514. modelItem: oDetail[this.PP_MODELITEM]
  515. };
  516. if ( oDetail[this.PP_MULTIVALUES] !== null ) {
  517. paramAttributes.multivalued = true;
  518. }
  519. aParameters.push( paramAttributes );
  520. }
  521. return aParameters;
  522. },
  523. /*
  524. * return true if min or max property is present on the object passed.
  525. *
  526. */
  527. _isRangeTypeValues: function (oValues) {
  528. if (oValues) {
  529. if (oValues.min || oValues.max) {
  530. return true;
  531. }
  532. }
  533. return false;
  534. },
  535. _getFirstPropertyOfObject: function (oSpec) {
  536. var oItemObject = null;
  537. for(var sProperty in oSpec) {
  538. oItemObject = oSpec[sProperty];
  539. break;
  540. }
  541. return oItemObject;
  542. },
  543. _getFirstPropertyNameOfObject: function (oSpec) {
  544. var sName = null;
  545. for(var sProperty in oSpec) {
  546. sName = sProperty;
  547. break;
  548. }
  549. return sName;
  550. },
  551. /*
  552. * returns object with widge context part in it
  553. */
  554. extractWidgetContextObject: function(oGeneralizedPayload) {
  555. if (oGeneralizedPayload) {
  556. var oCommon = oGeneralizedPayload[this.PP_WIDGET_CONTEXT];
  557. if (oCommon) {
  558. var obj = {};
  559. obj[this.PP_WIDGET_CONTEXT] = oCommon;
  560. return obj;
  561. }
  562. }
  563. return null;
  564. },
  565. /*
  566. * This function is to support Active Report onDrop and filtering interactions with other widgets.
  567. *
  568. * Returns generic payload object that includes superset of name value pairs in m_oContextCollection
  569. */
  570. genMergedWidgetContextObject: function() {
  571. var oMergedValuesObj = null;
  572. var oMergedRangesObj = null;
  573. for (var key in this.m_oContextCollection) {
  574. var oGeneralizedPayload = this.m_oContextCollection[key];
  575. if (oGeneralizedPayload) {
  576. var oCommon = oGeneralizedPayload[this.PP_WIDGET_CONTEXT];
  577. if (oCommon) {
  578. if (oCommon[this.PP_VALUES]) {
  579. oMergedValuesObj = dojo.mixin(oMergedValuesObj, oCommon[this.PP_VALUES]);
  580. }
  581. if (oCommon[this.PP_RANGES]) {
  582. oMergedRangesObj = dojo.mixin(oMergedRangesObj, this._convertRangeArrayToObjectForActiveReport(oCommon[this.PP_RANGES]) );
  583. }
  584. }
  585. }
  586. }
  587. if (oMergedValuesObj || oMergedRangesObj) {
  588. var obj = {};
  589. obj[this.PP_WIDGET_CONTEXT] = {};
  590. if (oMergedValuesObj) {
  591. obj[this.PP_WIDGET_CONTEXT][this.PP_VALUES] = oMergedValuesObj;
  592. }
  593. if (oMergedRangesObj) {
  594. obj[this.PP_WIDGET_CONTEXT][this.PP_RANGES] = oMergedRangesObj;
  595. }
  596. return obj;
  597. }
  598. return null;
  599. },
  600. /*
  601. * publish drill event with generic payload
  602. *
  603. */
  604. raiseDrillEvent: function(aDrillSpecObjects, sActionParam, sModelPath) {
  605. var oGeneralizedPayload = this._buildGeneralizedDrillPayload(aDrillSpecObjects, sActionParam, sModelPath);
  606. if (oGeneralizedPayload) {
  607. this.m_widget.fireEvent(this.EVENT_NAME_DRILL, null, oGeneralizedPayload);
  608. this._updateDrillContext( oGeneralizedPayload );
  609. this._updateWidgetContextContainer();
  610. }
  611. },
  612. _updateDrillContext : function( payload ) {
  613. this._updateDrillGenericContext( payload );
  614. this._updateDrillContextContainer( payload );
  615. },
  616. _updateDrillGenericContext : function( payload ) {
  617. if (payload[this.PP_WIDGET_CONTEXT]) {
  618. this.m_oDrillGenericContext = payload[this.PP_WIDGET_CONTEXT];
  619. }
  620. },
  621. _updateDrillContextContainer : function( payload ) {
  622. if (payload[this.PP_REPORT_DRILL_CONTEXT] && payload[this.PP_REPORT_DRILL_CONTEXT][this.PP_DRILL]) {
  623. this.m_oDrillContextContainer = payload[this.PP_REPORT_DRILL_CONTEXT][this.PP_DRILL];
  624. }
  625. },
  626. /*
  627. *
  628. oDrillSpecObject = {
  629. "dataItem": "",
  630. "mun": "",
  631. "lun": "",
  632. "hun": "",
  633. "displayValue": "",
  634. "summary": ""
  635. };
  636. */
  637. _buildGeneralizedDrillPayload: function(aDrillSpecObjects, sActionParam, sModelPath) {
  638. if(!aDrillSpecObjects || !sActionParam) {
  639. return null;
  640. }
  641. var oDrillContextValuesObject = {};
  642. var oWidgetContextValuesObject = {};
  643. for(var i in aDrillSpecObjects) {
  644. var oDrillSpec = aDrillSpecObjects[i];
  645. var mun = (oDrillSpec.mun)? oDrillSpec.mun: "";
  646. var lun = (oDrillSpec.lun)? oDrillSpec.lun: "";
  647. var hun = (oDrillSpec.hun)? oDrillSpec.hun: "";
  648. var oDrillParamObject = {};
  649. oDrillParamObject[this.PP_VALUES] = [{
  650. "caption": oDrillSpec.displayValue,
  651. "mun": mun,
  652. "lun": lun,
  653. "hun": hun
  654. }];
  655. if(oDrillSpec.summary) {
  656. oDrillParamObject["summary"] = oDrillSpec.summary;
  657. }
  658. oDrillContextValuesObject[oDrillSpec.dataItem] = oDrillParamObject;
  659. oWidgetContextValuesObject[oDrillSpec.dataItem] = [oDrillSpec.displayValue];
  660. }
  661. var oWidgetContextObject = {};
  662. oWidgetContextObject[this.PP_VALUES] = oWidgetContextValuesObject;
  663. var oItemSpecObject = {};
  664. oItemSpecObject[sModelPath]= oDrillContextValuesObject;
  665. var oDrillContextObject = {};
  666. oDrillContextObject[sActionParam] = {
  667. "id": this.m_widget.iContext.widgetId,
  668. "action": sActionParam,
  669. "itemSpecification": oItemSpecObject
  670. };
  671. var payload = {};
  672. payload[this.PP_WIDGET_CONTEXT] = oWidgetContextObject;
  673. payload[this.PP_REPORT_DRILL_CONTEXT] = oDrillContextObject;
  674. return payload;
  675. },
  676. /*
  677. * returns array of DrillSpec objects which are built from genenric drill payload
  678. */
  679. genDrillSpecObjects: function(oPayload) {
  680. if(!oPayload || !oPayload[this.PP_REPORT_DRILL_CONTEXT]) {
  681. return null;
  682. }
  683. var aDrillSpecObjects = [];
  684. var oDrillContextObject = oPayload[this.PP_REPORT_DRILL_CONTEXT];
  685. var oDrillUpOrDown = this._getFirstPropertyOfObject(oDrillContextObject);
  686. var oItemSpecObject = this._getFirstPropertyOfObject(oDrillUpOrDown.itemSpecification);
  687. for(var sName in oItemSpecObject) {
  688. var oDrillParamObject = oItemSpecObject[sName];
  689. var aValues = oDrillParamObject[this.PP_VALUES];
  690. if (aValues && aValues.length>0) {
  691. var oValue = aValues[0];
  692. var oDrillSpecObject = {
  693. "dataItem": sName,
  694. "displayValue": oValue.caption,
  695. "mun": oValue.mun,
  696. "lun": oValue.lun,
  697. "hun": oValue.hun
  698. };
  699. if(oValue.summary) {
  700. oDrillSpecObject["summary"] = oValue.summary;
  701. }
  702. aDrillSpecObjects.push(oDrillSpecObject);
  703. }
  704. }
  705. return (aDrillSpecObjects.length>0)? aDrillSpecObjects : null;
  706. },
  707. getDrillActionType: function(oPayload) {
  708. if(!oPayload || !oPayload[this.PP_REPORT_DRILL_CONTEXT]) {
  709. return null;
  710. }
  711. return this._getFirstPropertyNameOfObject(oPayload[this.PP_REPORT_DRILL_CONTEXT]);
  712. },
  713. /*
  714. * An object not array is expected as Range value type in Active Report.
  715. * However in generic payload, the value is an array to support multimple range values.
  716. *
  717. * This function is to convert array range value to object.
  718. * The value in the array is in used.
  719. *
  720. */
  721. _convertRangeArrayToObjectForActiveReport: function(oRanges) {
  722. if (oRanges) {
  723. var newRanges = {};
  724. for (var name in oRanges) {
  725. var value = oRanges[name];
  726. if (value && value.length>0) {
  727. //Pass first item because Active report takes only one range input.
  728. newRanges[name] = value[0];
  729. } else {
  730. newRanges[name] = value;
  731. }
  732. }
  733. return newRanges;
  734. }
  735. return oRanges;
  736. },
  737. /*
  738. * returns value of
  739. * "com.ibm.widget.context.bux.selectValueControl"/"selectValueControl"/"itemSpecification"
  740. */
  741. getItemsInItemSpecification: function( payload ) {
  742. var selectValueControlContext = payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT];
  743. if (selectValueControlContext && selectValueControlContext["selectValueControl"] &&
  744. selectValueControlContext["selectValueControl"]["itemSpecification"]) {
  745. return this._getFirstPropertyOfObject(selectValueControlContext["selectValueControl"]["itemSpecification"])
  746. }
  747. return null;
  748. },
  749. /*
  750. * return clearComment payload of discrete type SelectValueControl
  751. * "com.ibm.widget.context.bux.selectValueControl"/"selectValueControl"/"itemSpecification"
  752. *
  753. * @param widgetId: widgetId of control
  754. */
  755. genRemoveDiscreteFilterPayload: function(widgetId) {
  756. var payload = {
  757. "clientId": widgetId,
  758. "com.ibm.widget.context": {
  759. },
  760. "com.ibm.widget.context.bux.selectValueControl":{
  761. "selectValueControl":{
  762. "id":widgetId,
  763. "controlType":"selectValueFilter",
  764. "type":"discrete",
  765. "valueType":"string"
  766. }
  767. }
  768. };
  769. return payload;
  770. },
  771. /**
  772. * Creates an empty selection payload
  773. */
  774. genEmptySelectionPayload: function(oCV, sWidgetId) {
  775. var obj = {
  776. "clientId":sWidgetId,
  777. "com.ibm.widget.context": {},
  778. "com.ibm.widget.context.bux.selection":{
  779. "selection":{
  780. "id":sWidgetId,
  781. "valueType":"string"
  782. }
  783. }
  784. };
  785. this.m_oSelectionFilterContext = {};
  786. this._updateWidgetContextContainer();
  787. this.setSelectionFilterObjects(null);
  788. return obj;
  789. },
  790. /*
  791. * returns generic selection payload with current selection objects
  792. *
  793. */
  794. genSelectionPayload: function(oCV, sWidgetId, bExcludeContext ) {
  795. var valuesObj = {};
  796. var selectionObj = {
  797. "id":sWidgetId,
  798. "valueType":"string"
  799. };
  800. var obj = {
  801. "clientId":sWidgetId,
  802. "com.ibm.widget.context": valuesObj,
  803. "com.ibm.widget.context.bux.selection":{
  804. "selection":selectionObj
  805. }
  806. };
  807. var foundData = false;
  808. var aSelectionFilterObjects = [];
  809. var oSC = oCV.getSelectionController();
  810. var aSelectedObjects = oSC.getAllSelectedObjects();
  811. if ( aSelectedObjects && aSelectedObjects.length >0 ) {
  812. var oUniqueCtxs = {};
  813. var ctxString = null;
  814. var nameValueObject = {};
  815. var itemSpecModelObj = {}
  816. for (var i=0; i < aSelectedObjects.length; i++) {
  817. if (aSelectedObjects[i].populateSelectionPayload(nameValueObject, itemSpecModelObj, bExcludeContext) ){
  818. foundData = true;
  819. ctxString = aSelectedObjects[i].getCtxAttributeString();
  820. if (typeof oUniqueCtxs[ctxString] == 'undefined') {
  821. oUniqueCtxs[ctxString] = true;
  822. aSelectionFilterObjects.push(aSelectedObjects[i].marshal(oSC, oCV.getId()));
  823. }
  824. }
  825. }
  826. if (foundData) {
  827. valuesObj.values = nameValueObject;
  828. var itemSpecObj = {};
  829. var modelPath = oCV.getModelPath();
  830. var modelPathName = (modelPath)? modelPath : ".";
  831. itemSpecObj[modelPathName] = itemSpecModelObj;
  832. selectionObj.itemSpecification = itemSpecObj;
  833. }
  834. }
  835. this.m_oSelectionFilterContext = obj[this.PP_WIDGET_CONTEXT];
  836. this._updateWidgetContextContainer();
  837. this.setSelectionFilterObjects( aSelectionFilterObjects.length>0? aSelectionFilterObjects : null);
  838. return obj;
  839. },
  840. isSelectionPayloadForReset: function(obj) {
  841. if (obj && obj[this.PP_WIDGET_CONTEXT]) {
  842. return this.isEmptyObject(obj[this.PP_WIDGET_CONTEXT]);
  843. }
  844. return true;
  845. },
  846. setSelectionFilterObjects: function(aSelectionFilterObjects) {
  847. this.m_aSelectionFilterObjects = aSelectionFilterObjects;
  848. },
  849. getSelectionFilterObjects: function() {
  850. return this.m_aSelectionFilterObjects;
  851. },
  852. toStringSelectionFilterObjects: function() {
  853. var str = "";
  854. for( var idx in this.m_aSelectionFilterObjects) {
  855. if (str.length>0) {
  856. str += ",";
  857. }
  858. str += JSON.stringify(this.m_aSelectionFilterObjects[idx]);
  859. }
  860. return "[" + str +"]";
  861. },
  862. convertSelectionToSelectValueControlPayload: function(oSelectionPayload) {
  863. if (oSelectionPayload["com.ibm.widget.context.bux.selection"]) {
  864. //add controlType and type
  865. var selectionObj = oSelectionPayload["com.ibm.widget.context.bux.selection"]["selection"];
  866. selectionObj.controlType = "selectValueFilter";
  867. selectionObj.type = "discrete";
  868. //copy to selectionValueControl
  869. oSelectionPayload["com.ibm.widget.context.bux.selectValueControl"] = {"selectValueControl": selectionObj};
  870. delete oSelectionPayload["com.ibm.widget.context.bux.selection"];
  871. }
  872. return oSelectionPayload;
  873. },
  874. /**
  875. * If we receive a generic event, build up a selectValueControl payload so the rest
  876. * of our javascript doesn't know the difference
  877. */
  878. convertGenericToSelectValueControlPayload: function(payload) {
  879. if (this._hasItemSpecification(payload) ) {
  880. return;
  881. }
  882. //Remove names without values
  883. if(payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES]) {
  884. var contextObject = payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES];
  885. //Delete the name with empty array value so that the name filter gets removed.
  886. for(dataItem in contextObject) {
  887. if (contextObject[dataItem].length == 0) {
  888. delete contextObject[dataItem];
  889. }
  890. }
  891. //If contextObject is empty, remove it
  892. var bEmpty = true;
  893. for(dataItem in contextObject) {
  894. bEmpty = false;
  895. break;
  896. }
  897. if (bEmpty) {
  898. delete payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES];
  899. }
  900. };
  901. if(payload[this.PP_WIDGET_CONTEXT][this.PP_RANGES]) {
  902. var contextObject = payload[this.PP_WIDGET_CONTEXT][this.PP_RANGES];
  903. //If contextObject is empty, remove it
  904. var bEmpty = true;
  905. for(dataItem in contextObject) {
  906. bEmpty = false;
  907. break;
  908. }
  909. if (bEmpty) {
  910. delete payload[this.PP_WIDGET_CONTEXT][this.PP_RANGES];
  911. }
  912. }
  913. var contextObject = null;
  914. if(payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES]) {
  915. key = this.PP_VALUES;
  916. contextObject = payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES];
  917. }
  918. else {
  919. key = this.PP_RANGES;
  920. contextObject = payload[this.PP_WIDGET_CONTEXT][this.PP_RANGES];
  921. }
  922. var cv = this.m_widget.getViewerObject();
  923. var dataManager = null;
  924. if (cv) {
  925. var sc = cv.getSelectionController();
  926. dataManager = sc.getCCDManager();
  927. }
  928. for(dataItem in contextObject) {
  929. var foundAllMuns = true;
  930. var itemValues = {};
  931. for (var modelItem in contextObject) {
  932. var values = [];
  933. for (var i=0; i < contextObject[modelItem].length; i++) {
  934. var useValue = contextObject[modelItem][i];
  935. var value = {"caption" : useValue};
  936. // We need all the MUNs or none at all. So keep getting them as long as we've all the needed ones so far
  937. if (foundAllMuns) {
  938. var mun = dataManager ? dataManager.getMUNForRDIAndUseValue(modelItem, useValue) : null;
  939. if (mun != null) {
  940. value.mun = mun;
  941. }
  942. else {
  943. // We didn't find the MUN in our cotext information, loop through the array of
  944. // values we've built so far and delete the MUN information
  945. foundAllMuns = false;
  946. for (var i=0; i < values.length; i++) {
  947. delete values[i].mun;
  948. }
  949. }
  950. }
  951. values.push(value);
  952. }
  953. itemValues[modelItem] = {"values" : values};
  954. }
  955. var itemSpecification = {};
  956. var modelPath = cv ? cv.getModelPath() : null;
  957. var modelPathName = (modelPath) ? modelPath : "unknown";
  958. itemSpecification[modelPathName] = itemValues;
  959. payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT] = {
  960. "selectValueControl" : {
  961. "valueType":"string",
  962. "type":"discrete",
  963. "controlType": "selectValueFilter",
  964. "id" : payload.clientId ? payload.clientId : "",
  965. "itemSpecification" : itemSpecification
  966. }
  967. };
  968. }
  969. },
  970. /*
  971. * returns MUN of the first value of the itemName in itemSpecification/package_name
  972. *
  973. * @param payload
  974. * @param itemName the itemName MUN it is looking for
  975. *
  976. */
  977. getMUNOfItemValueInItemSpecification: function( payload, itemName ) {
  978. var oPackage = this.getItemsInItemSpecification(payload)
  979. if (oPackage && oPackage[itemName]) {
  980. var oItem = oPackage[itemName];
  981. if( oItem.values && oItem.values.length>0) {
  982. return oItem.values[0].mun;
  983. }
  984. }
  985. return null;
  986. },
  987. _hasItemSpecification: function(payload) {
  988. if (payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT] &&
  989. payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT]["selectValueControl"] &&
  990. payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT]["selectValueControl"]["itemSpecification"] ) {
  991. return true;
  992. }
  993. if (payload[this.PP_BUX_SELECTION_CONTEXT] &&
  994. payload[this.PP_BUX_SELECTION_CONTEXT]["selection"] &&
  995. payload[this.PP_BUX_SELECTION_CONTEXT]["selection"]["itemSpecification"] ) {
  996. return true;
  997. }
  998. return false;
  999. },
  1000. getSourceUniqueId: function(payload, actionNameOverride) {
  1001. var id = null;
  1002. var action = null;
  1003. if (payload["clientId"]) {
  1004. id = payload["clientId"];
  1005. }
  1006. if (payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT]) {
  1007. action = "selectValueControl";
  1008. if (!id && payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT]["selectValueControl"] && payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT]["selectValueControl"]["id"] ) {
  1009. id = payload[this.PP_BUX_SELECTVALUECONTROL_CONTEXT]["selectValueControl"]["id"];
  1010. }
  1011. } else
  1012. if (payload[this.PP_BUX_SELECTION_CONTEXT]) {
  1013. action = "selection";
  1014. if (!id && payload[this.PP_BUX_SELECTION_CONTEXT]["selection"] && payload[this.PP_BUX_SELECTION_CONTEXT]["selection"]["id"] ) {
  1015. id = payload[this.PP_BUX_SELECTION_CONTEXT]["selection"]["id"];
  1016. }
  1017. } else
  1018. if (payload[this.PP_REPORT_PROMPT_CONTEXT] ) {
  1019. action = "prompt";
  1020. if (!id && payload[this.PP_REPORT_PROMPT_CONTEXT]["prompt"] && payload[this.PP_REPORT_PROMPT_CONTEXT]["prompt"]["id"] ) {
  1021. id = payload[this.PP_REPORT_PROMPT_CONTEXT]["prompt"]["id"];
  1022. }
  1023. } else
  1024. if (payload[this.PP_REPORT_DRILL_CONTEXT]) {
  1025. action = "drill";
  1026. if (!id && payload[this.PP_REPORT_DRILL_CONTEXT]["DrillUp"] && payload[this.PP_REPORT_DRILL_CONTEXT]["DrillUp"]["id"] ) {
  1027. id = payload[this.PP_REPORT_DRILL_CONTEXT]["DrillUp"]["id"];
  1028. }
  1029. } else
  1030. if (payload[this.PP_REPORT_DRILL_CONTEXT]) {
  1031. action = "drill";
  1032. if (!id && payload[this.PP_REPORT_DRILL_CONTEXT]["DrillDown"] &&payload[this.PP_REPORT_DRILL_CONTEXT]["DrillDown"]["id"] ) {
  1033. id = payload[this.PP_REPORT_DRILL_CONTEXT]["DrillDown"]["id"];
  1034. }
  1035. }
  1036. if(!id) {
  1037. id = "unknown";
  1038. }
  1039. if(!action) {
  1040. action = "unknown";
  1041. }
  1042. if(typeof actionNameOverride == "string") {
  1043. action = actionNameOverride;
  1044. }
  1045. return id + "_" + action;
  1046. },
  1047. /**
  1048. * returns true
  1049. * if payload has no 'com.ibm.widget.context' field or the field is empty object, or
  1050. * if the'com.ibm.widget.context' field has no 'values' or 'ranges' field
  1051. */
  1052. isWidgetContextEmpty: function(payload) {
  1053. return ( this.isEmptyObject(payload[this.PP_WIDGET_CONTEXT]) ||
  1054. (this.isEmptyObject(payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES]) &&
  1055. this.isEmptyObject(payload[this.PP_WIDGET_CONTEXT][this.PP_RANGES]))
  1056. );
  1057. },
  1058. isEmptyObject: function(obj) {
  1059. var bEmpty = true;
  1060. if (obj) {
  1061. for(var field in obj) {
  1062. bEmpty = false;
  1063. break;
  1064. }
  1065. }
  1066. return bEmpty;
  1067. },
  1068. updateContextCollection: function(payload) {
  1069. if (!this.isEmptyObject(payload)) {
  1070. var uniqueId = this.getSourceUniqueId(payload);
  1071. if (this.isWidgetContextEmpty(payload)) {
  1072. if (this.m_oContextCollection[uniqueId]) {
  1073. this.setEmptyArrayToWidgetContextValues(this.m_oContextCollection[uniqueId]);
  1074. } else {
  1075. var onDropId = this.getSourceUniqueId(payload, "unknown");
  1076. if (this.m_oContextCollection[onDropId]) {
  1077. this.setEmptyArrayToWidgetContextValues(this.m_oContextCollection[onDropId]);
  1078. }
  1079. }
  1080. } else {
  1081. if (payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES]) {
  1082. //Delete filters on same data item from other widgets
  1083. for (var name in payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES]) {
  1084. for( var key in this.m_oContextCollection) {
  1085. var otherFilter = this.m_oContextCollection[key];
  1086. if (otherFilter[this.PP_WIDGET_CONTEXT][this.PP_VALUES] &&
  1087. otherFilter[this.PP_WIDGET_CONTEXT][this.PP_VALUES][name]) {
  1088. delete otherFilter[this.PP_WIDGET_CONTEXT][this.PP_VALUES][name];
  1089. }
  1090. }
  1091. }
  1092. }
  1093. this.m_oContextCollection[uniqueId] = dojo.clone(payload);
  1094. }
  1095. return this.m_oContextCollection;
  1096. }
  1097. },
  1098. /*
  1099. * Set value to empty string. Can't delete the name because the name must be passed to Active report.
  1100. */
  1101. setEmptyArrayToWidgetContextValues: function(payload) {
  1102. if(payload && payload[this.PP_WIDGET_CONTEXT] && payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES] ) {
  1103. var oNameValuePairs = payload[this.PP_WIDGET_CONTEXT][this.PP_VALUES];
  1104. for(var name in oNameValuePairs) {
  1105. oNameValuePairs[name] = [];
  1106. }
  1107. }
  1108. }
  1109. });