ChangeDisplayTypeAction.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2013
  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. function ChangeDisplayTypeAction()
  13. {
  14. this.m_requestParams = null;
  15. this.m_sAction = 'ChangeDataContainerType';
  16. this.m_iMAX_NUM_SUGGESTED_DISPLAY_TYPES = 5;
  17. }
  18. //base class for change display type action
  19. ChangeDisplayTypeAction.prototype = new ModifyReportAction();
  20. ChangeDisplayTypeAction.prototype.getUndoHint = function()
  21. {
  22. return RV_RES.IDS_JS_CHANGE_DISPLAY;
  23. };
  24. ChangeDisplayTypeAction.prototype.setRequestParms = function(parms)
  25. {
  26. this.m_requestParams = parms;
  27. };
  28. ChangeDisplayTypeAction.prototype.addActionContextAdditionalParms = function()
  29. {
  30. this._cleaerPinAndFreeze();
  31. var bestVisualization = false;
  32. if (this.m_requestParams.bestVisualization) {
  33. bestVisualization = true;
  34. } else if (((this.m_requestParams.targetType.targetType == undefined) ||
  35. (this.m_requestParams.targetType.targetType == "undefined")) &&
  36. (this.m_requestParams.targetType.templateId == undefined))
  37. {
  38. var paramObject = eval("(" + this.m_requestParams.targetType + ")"); //from dialog.
  39. } else {
  40. var paramObject = this.m_requestParams.targetType; //from dialog.
  41. }
  42. var canvas = this.m_oCV.getViewerWidget().findContainerDiv();
  43. var sWidgetSize = "";
  44. if (canvas) {
  45. sWidgetSize = "<widgetWidth>" + (parseInt(canvas.style.width, 10) -ResizeChartAction.PADDING.getWidth()) + "px</widgetWidth>" +
  46. "<widgetHeight>" + (parseInt(canvas.style.height, 10) - ResizeChartAction.PADDING.getHeight()) + "px</widgetHeight>";
  47. }
  48. var sActionContext = "";
  49. if (bestVisualization) {
  50. sActionContext += "<bestVisualization>true</bestVisualization>"
  51. sActionContext += this.getDataItemInfoMap();
  52. } else {
  53. sActionContext += "<target>";
  54. sActionContext += paramObject.targetType;
  55. sActionContext += "</target>";
  56. if (paramObject.templateId) {
  57. sActionContext += "<templateId>";
  58. sActionContext += ((paramObject.templateId)? paramObject.templateId : "");
  59. sActionContext += "</templateId>";
  60. sActionContext += "<variationId>";
  61. sActionContext += ((paramObject.variationId)? paramObject.variationId : "");
  62. sActionContext += "</variationId>";
  63. sActionContext += this.getDataItemInfoMap();
  64. }
  65. sActionContext += "<label>";
  66. sActionContext += paramObject.label;
  67. sActionContext += "</label>";
  68. }
  69. sActionContext += sWidgetSize;
  70. sActionContext += this.addClientContextData(/*maxValuesPerRDI*/3);
  71. return (sActionContext);
  72. };
  73. ChangeDisplayTypeAction.prototype._cleaerPinAndFreeze = function() {
  74. var pinFreezeManager = this.m_oCV.getPinFreezeManager();
  75. if (pinFreezeManager) {
  76. var containerId = this.getContainerId(this.m_oCV.getSelectionController());
  77. pinFreezeManager.clearPinInfo(containerId);
  78. }
  79. };
  80. ChangeDisplayTypeAction.prototype.updateMenu = function(jsonSpec)
  81. {
  82. var oRAPReportInfo = this.getCognosViewer().getRAPReportInfo();
  83. jsonSpec.visible = (oRAPReportInfo) ? oRAPReportInfo.containsInteractiveDataContainer() : jsonSpec.visible;
  84. if (! jsonSpec.visible)
  85. {
  86. return jsonSpec;
  87. }
  88. var reportInfo = this.getSelectedReportInfo();
  89. jsonSpec.disabled = (reportInfo == null || reportInfo.displayTypeId == null || !this.isInteractiveDataContainer(reportInfo.displayTypeId));
  90. if (jsonSpec.disabled)
  91. {
  92. jsonSpec.iconClass = "chartTypesDisabled";
  93. return jsonSpec;
  94. }
  95. jsonSpec.iconClass = "chartTypes";
  96. return this.buildDynamicMenuItem(jsonSpec, "ChangeDisplayType");
  97. };
  98. ChangeDisplayTypeAction.prototype.createEmptyMenuItem = function()
  99. {
  100. return {name: "None", label: RV_RES.IDS_JS_CHANGE_DISPLAY_SELECT_DATA, iconClass: "", action: null, items: null };
  101. };
  102. ChangeDisplayTypeAction.prototype.getActionContextString = function(groupId)
  103. {
  104. var actionContext = "<getInfoActions>";
  105. actionContext += "<getInfoAction name=\"GetInfo\">";
  106. actionContext += "<include><suggestedDisplayTypes/></include>";
  107. actionContext += this.getDataItemInfoMap();
  108. actionContext += "<groupId>";
  109. actionContext += groupId;
  110. actionContext += "</groupId>";
  111. actionContext += this.addClientContextData(/*maxValuesPerRDI*/3);
  112. actionContext += "</getInfoAction>";
  113. actionContext += "</getInfoActions>";
  114. return actionContext;
  115. };
  116. ChangeDisplayTypeAction.prototype.fetchSuggestedDisplayTypes = function(groupId)
  117. {
  118. var oCV = this.getCognosViewer();
  119. var asynchRequest = new AsynchJSONDispatcherEntry(oCV);
  120. asynchRequest.addFormField("ui.action", "getInfoFromReportSpec");
  121. asynchRequest.addFormField("bux", "true");
  122. asynchRequest.addFormField("ui.object", oCV.envParams["ui.object"]);
  123. asynchRequest.addFormField("cv.actionContext", this.getActionContextString(groupId));
  124. asynchRequest.addDefinedFormField("ui.spec", oCV.envParams["ui.spec"]);
  125. asynchRequest.addNonEmptyStringFormField("modelPath", oCV.getModelPath());
  126. if (groupId == "undefined") {
  127. asynchRequest.setCallbacks({"complete" : {"object" : this, "method" : this.handleSuggestedDisplayTypesResponse}});
  128. } else {
  129. asynchRequest.setCallbacks({"complete" : {"object" : this, "method" : this.handleSuggestedDisplayVariationsResponse}});
  130. }
  131. oCV.dispatchRequest(asynchRequest);
  132. };
  133. ChangeDisplayTypeAction.prototype.handleSuggestedDisplayTypesResponse = function(asynchJSONResponse)
  134. {
  135. var viewer = this.getCognosViewer();
  136. var viewerWidget = viewer.getViewerWidget();
  137. this.addSuggestedDisplayTypesMenuItems(asynchJSONResponse.getResult());
  138. };
  139. ChangeDisplayTypeAction.prototype.addSuggestedDisplayTypesMenuItems = function (reportInfos)
  140. {
  141. var buttonSpec = this.getCognosViewer().findToolbarItem("ChangeDisplayType");
  142. if (buttonSpec) {
  143. buttonSpec.open = false;
  144. }
  145. var menuItems = [];
  146. var reportInfo = this.getSelectedReportInfo();
  147. var container = undefined;
  148. for (var x=0; x < reportInfos.containers.length; x++)
  149. {
  150. if (reportInfo.container == reportInfos.containers[x].container)
  151. {
  152. container = reportInfos.containers[x];
  153. break;
  154. }
  155. }
  156. if (container == undefined)
  157. {
  158. return;
  159. }
  160. var nbrToDisplay = container.suggestedDisplayTypes.length <= this.m_iMAX_NUM_SUGGESTED_DISPLAY_TYPES ? container.suggestedDisplayTypes.length : this.m_iMAX_NUM_SUGGESTED_DISPLAY_TYPES;
  161. menuItems.push({title: RV_RES.IDS_JS_CHANGE_DISPLAY_RECOMMENDED});
  162. menuItems.push({separator: true});
  163. for (var i=0; i < nbrToDisplay; i++)
  164. {
  165. menuItems.push({ name: container.suggestedDisplayTypes[i].name, label: container.suggestedDisplayTypes[i].title, description: container.suggestedDisplayTypes[i].description, iconClass: container.suggestedDisplayTypes[i].iconClass, action: { name: "ChangeDisplayType", payload: {targetType: {templateId: container.suggestedDisplayTypes[i].templateId }, label: container.suggestedDisplayTypes[i].title}}, items: null });
  166. }
  167. menuItems.push({separator: true});
  168. menuItems.push({ name: "ChangeDisplayMore", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_MORE, iconClass: "ChartTypeOther", action: { name: "InvokeChangeDisplayTypeDialog", payload: {}}, items: null });
  169. buttonSpec.open = true;
  170. buttonSpec.items = menuItems;
  171. var updateItems = [];
  172. updateItems.push(buttonSpec);
  173. this.getCognosViewer().getViewerWidget().fireEvent("com.ibm.bux.widgetchrome.toolbar.update", null, updateItems);
  174. return menuItems;
  175. };
  176. ChangeDisplayTypeAction.prototype.buildMenu = function(jsonSpec)
  177. {
  178. var oRAPReportInfo = this.getCognosViewer().getRAPReportInfo();
  179. jsonSpec.visible = (oRAPReportInfo) ? oRAPReportInfo.containsInteractiveDataContainer() : jsonSpec.visible;
  180. if (! jsonSpec.visible)
  181. {
  182. return jsonSpec;
  183. }
  184. var reportInfo = this.getSelectedReportInfo();
  185. jsonSpec.disabled = (reportInfo == null || reportInfo.displayTypeId == null || !this.isInteractiveDataContainer(reportInfo.displayTypeId));
  186. if (jsonSpec.disabled)
  187. {
  188. jsonSpec.iconClass = "chartTypesDisabled";
  189. }
  190. else
  191. {
  192. jsonSpec.iconClass = "chartTypes";
  193. var enableVisCoach = this.getCognosViewer().getAdvancedServerProperty("VIEWER_JS_enableVisCoach");
  194. if (enableVisCoach !== 'false' && (typeof reportInfo.suggestedDisplayTypesEnabled != "undefined") && (reportInfo.suggestedDisplayTypesEnabled != null) && (reportInfo.suggestedDisplayTypesEnabled == "true"))
  195. {
  196. //toolbar menu, so generate the dynamic menu
  197. this.fetchSuggestedDisplayTypes("undefined");
  198. return this.buildDynamicMenuItem(jsonSpec, "ChangeDisplayType");
  199. }
  200. else
  201. {
  202. jsonSpec.items = [];
  203. var isV2 = (reportInfo.displayTypeId.match("v2_") != null || reportInfo.displayTypeId == "crosstab" || reportInfo.displayTypeId == "list");
  204. if(isV2)
  205. {
  206. jsonSpec.items.push({ name: "ChangeDisplayBar", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_BAR, iconClass: "ChartTypeBar", action: { name: "ChangeDisplayType", payload: {targetType: "v2_bar_rectangle_clustered" }}, items: null });
  207. jsonSpec.items.push({ name: "ChangeDisplayColumn", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_COLUMN, iconClass: "ChartTypeColumn", action: { name: "ChangeDisplayType", payload: {targetType: "v2_column_rectangle_clustered" }}, items: null });
  208. jsonSpec.items.push({ name: "ChangeDisplayLine", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_LINE, iconClass: "ChartTypeLine", action: { name: "ChangeDisplayType", payload: {targetType: "v2_line_clustered_markers" }}, items: null });
  209. jsonSpec.items.push({ name: "ChangeDisplayPie", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_PIE, iconClass: "ChartTypePie", action: { name: "ChangeDisplayType", payload: {targetType: "v2_pie" }}, items: null });
  210. jsonSpec.items.push({ name: "ChangeDisplayCrosstab", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_CROSSTAB, iconClass: "ChartTypeCrosstab", action: { name: "ChangeDisplayType", payload: {targetType: "Crosstab" }}, items: null });
  211. jsonSpec.items.push({ name: "ChangeDisplayList", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_LIST, iconClass: "ChartTypeList", action: { name: "ChangeDisplayType", payload: {targetType: "List" }}, items: null });
  212. jsonSpec.items.push({ name: "ChangeDisplayMore", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_MORE, iconClass: "ChartTypeOther", action: { name: "InvokeChangeDisplayTypeDialog", payload: "" }, items: null });
  213. }
  214. else
  215. {
  216. jsonSpec.items.push({ name: "ChangeDisplayBar", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_BAR, iconClass: "ChartTypeBar", action: { name: "ChangeDisplayType", payload: {targetType: "bar_clustered_flat" }}, items: null });
  217. jsonSpec.items.push({ name: "ChangeDisplayColumn", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_COLUMN, iconClass: "ChartTypeColumn", action: { name: "ChangeDisplayType", payload: {targetType: "column_clustered_flat" }}, items: null });
  218. jsonSpec.items.push({ name: "ChangeDisplayLine", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_LINE, iconClass: "ChartTypeLine", action: { name: "ChangeDisplayType", payload: {targetType: "line_clustered_flat_markers" }}, items: null });
  219. jsonSpec.items.push({ name: "ChangeDisplayPie", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_PIE, iconClass: "ChartTypePie", action: { name: "ChangeDisplayType", payload: {targetType: "pie_flat" }}, items: null });
  220. jsonSpec.items.push({ name: "ChangeDisplayCrosstab", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_CROSSTAB, iconClass: "ChartTypeCrosstab", action: { name: "ChangeDisplayType", payload: {targetType: "Crosstab" }}, items: null });
  221. jsonSpec.items.push({ name: "ChangeDisplayList", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_LIST, iconClass: "ChartTypeList", action: { name: "ChangeDisplayType", payload: {targetType: "List" }}, items: null });
  222. jsonSpec.items.push({ name: "ChangeDisplayMore", label: RV_RES.IDS_JS_CHANGE_DISPLAY_TYPE_MORE, iconClass: "ChartTypeOther", action: { name: "InvokeChangeDisplayTypeDialog", payload: "" }, items: null });
  223. }
  224. }
  225. for (var i in jsonSpec.items)
  226. {
  227. jsonSpec.items[i].action.payload = { targetType: jsonSpec.items[i].action.payload };
  228. jsonSpec.items[i].action.payload.targetType.label = jsonSpec.items[i].label;
  229. }
  230. }
  231. return jsonSpec;
  232. };