SnapshotsAction.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2011
  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 SnapshotsAction() {}
  13. SnapshotsAction.prototype = new CognosViewerAction();
  14. SnapshotsAction.prototype.updateMenu = function(jsonSpec) {
  15. var widget = this.m_oCV.getViewerWidget();
  16. jsonSpec.disabled = (widget.getAttributeValue("reportCreatedInCW") == "true") || (widget.getAttributeValue("fromReportPart") == "true") || (this.m_oCV.envParams["reportpart_id"] && this.m_oCV.envParams["reportpart_id"].length) > 0 ? true : false;
  17. jsonSpec.visible = !this.isPromptWidget();
  18. return jsonSpec;
  19. };
  20. SnapshotsAction.prototype.execute = function()
  21. {
  22. var oCV = this.getCognosViewer();
  23. var widget = oCV.getViewerWidget();
  24. if (widget.getSavedOutputsCMResponse() == null) {
  25. this.queryCMForSavedOutputs({"complete" : {"object" : this, "method" : this.handleQueryResponse}});
  26. }
  27. else if (typeof widget.savedOutputMenuUpdated != "undefined" && widget.savedOutputMenuUpdated == false) {
  28. this.populateMenu(true);
  29. widget.savedOutputMenuUpdated = true;
  30. }
  31. };
  32. SnapshotsAction.prototype.queryCMForSavedOutputs = function(callback) {
  33. var oCV = this.getCognosViewer();
  34. var widget = oCV.getViewerWidget();
  35. var searchPath = "";
  36. var formWarpRequest = document.getElementById("formWarpRequest" + oCV.getId());
  37. if (oCV.envParams["originalReport"])
  38. {
  39. searchPath = oCV.envParams["originalReport"];
  40. }
  41. else if (formWarpRequest && formWarpRequest["reRunObj"] != null && formWarpRequest["reRunObj"].value.length > 0)
  42. {
  43. searchPath = formWarpRequest["reRunObj"].value;
  44. }
  45. else
  46. {
  47. searchPath = oCV.envParams["ui.object"];
  48. }
  49. searchPath += "/reportVersion/*[@format='HTML' or @format='XHTML']/..";
  50. var cmRequest =
  51. "<CMRequest>" +
  52. "<searchPath>" + xml_encode(searchPath) + "</searchPath>" +
  53. "<properties>" +
  54. "<property>searchPath</property>" +
  55. "<property>creationTime</property>" +
  56. "<property>storeID</property>" +
  57. "</properties>" +
  58. "<sortBy>" +
  59. "<sortItem>" +
  60. "<property>creationTime</property>" +
  61. "<order>descending</order>" +
  62. "</sortItem>" +
  63. "</sortBy>" +
  64. "</CMRequest>";
  65. var request = new DataDispatcherEntry(oCV);
  66. request.addFormField("ui.action", "CMRequest");
  67. request.addFormField("cv.responseFormat", "CMRequest");
  68. request.addFormField("ui.object", searchPath);
  69. request.addFormField("CMRequest", cmRequest);
  70. request.setCallbacks(callback);
  71. oCV.dispatchRequest(request);
  72. };
  73. SnapshotsAction.prototype.setSavedOutputsCMResponse = function(response) {
  74. var oCV = this.getCognosViewer();
  75. var widget = oCV.getViewerWidget();
  76. var xmlParsedCMresponse = XMLBuilderLoadXMLFromString(response.getResult());
  77. widget.setSavedOutputsCMResponse(xmlParsedCMresponse);
  78. };
  79. SnapshotsAction.prototype.handleQueryResponse = function(response) {
  80. this.setSavedOutputsCMResponse(response);
  81. this.populateMenu(true);
  82. };
  83. SnapshotsAction.prototype.canShowLiveMenuItem = function() {
  84. var oCV = this.getCognosViewer();
  85. return ( oCV.envParams["cv.responseFormat"] !== "activeReport" && (oCV.isLimitedInteractiveMode() || (oCV.envParams["cv.objectPermissions"] && oCV.envParams["cv.objectPermissions"].indexOf("execute") != -1)) );
  86. };
  87. SnapshotsAction.prototype.getMenuItemActionClassHandler = function() {
  88. var oCV = this.getCognosViewer();
  89. return oCV.envParams["cv.responseFormat"] === "activeReport" ? "ViewActiveReport" : "ViewSavedOutput";
  90. };
  91. SnapshotsAction.prototype.populateMenu = function(bOpen) {
  92. var oCV = this.getCognosViewer();
  93. var widget = oCV.getViewerWidget();
  94. var sAction = oCV.envParams["ui.action"];
  95. var cmResponse = widget.savedOutputsCMResponse;
  96. var root = oCV.findBlueDotMenu();
  97. root.open = bOpen;
  98. var buttonSpec = oCV.findToolbarItem("Snapshots", root);
  99. var queryResult = XMLHelper_FindChildByTagName(cmResponse, "result", true);
  100. var queryItems = XMLHelper_FindChildrenByTagName(queryResult, "item", false);
  101. var menuItems = [];
  102. var mostRecentCreationTime = null;
  103. var mostRecentStoreID = null;
  104. var oMenuItem = null;
  105. var bSameAsCurrent;
  106. if ( this.canShowLiveMenuItem() ) {
  107. bSameAsCurrent = (sAction != "view" && sAction != "buxView" && oCV.getStatus() !== "fault");
  108. oMenuItem = { name: "live", label: RV_RES.IDS_JS_SNAPSHOTS_LIVE, action: bSameAsCurrent ? {} : { name: "RunSavedOutputReport", payload: {} }, items: null };
  109. this.addMenuItemChecked(bSameAsCurrent, oMenuItem);
  110. menuItems.push(oMenuItem);
  111. if (queryItems.length > 0) {
  112. menuItems.push({separator: true});
  113. }
  114. }
  115. if (queryItems.length > 0) {
  116. var actionClassHanlder = this.getMenuItemActionClassHandler();
  117. var versions = [];
  118. for (var iIndex=0; iIndex < queryItems.length; iIndex++) {
  119. if (iIndex < 5) {
  120. var queryItem = queryItems[iIndex];
  121. var sItemLabel = XMLHelper_GetText(XMLHelper_FindChildByTagName(queryItem, "creationTime_localized", true));
  122. sItemLabel = enforceTextDir(sItemLabel);
  123. var storeIDNode = XMLHelper_FindChildByTagName(queryItem, "storeID", true);
  124. var sStoreID = XMLHelper_GetText(XMLHelper_FindChildByTagName(storeIDNode, "value", true));
  125. var creationTimeNode = XMLHelper_FindChildByTagName(queryItem, "creationTime", true);
  126. var sCreationTime = XMLHelper_GetText(XMLHelper_FindChildByTagName(creationTimeNode, "value", true));
  127. if (mostRecentCreationTime == null) {
  128. mostRecentCreationTime = sCreationTime;
  129. mostRecentStoreID = sStoreID;
  130. }
  131. bSameAsCurrent = (sAction == "view" || sAction == "buxView") && oCV.envParams["creationTime"] == sCreationTime && widget.getSavedOutputSearchPath() != null;
  132. oMenuItem = { name: "savedOutput", label: sItemLabel, action: bSameAsCurrent ? {} : { name: actionClassHanlder, payload: {obj:sStoreID, creationTime:sCreationTime, mostRecent:false} }, items: null };
  133. this.addMenuItemChecked(bSameAsCurrent, oMenuItem);
  134. versions.push(oMenuItem);
  135. }
  136. else {
  137. versions.push({ name: "viewAllSnapshots", label: RV_RES.IDS_JS_VIEW_ALL_SNAPSHOTS, action: { name: "ViewAllSnapshots", payload: {} }, items: null });
  138. break;
  139. }
  140. }
  141. bSameAsCurrent = false;
  142. if (widget.getSavedOutputSearchPath() == null && (sAction == "view" || sAction == "buxView")) {
  143. bSameAsCurrent = true;
  144. }
  145. oMenuItem = { name: "savedOutput", label: RV_RES.IDS_JS_MOST_RECENT_SNAPSHOT, action: bSameAsCurrent ? {} : { name: actionClassHanlder, payload: {obj:mostRecentStoreID, creationTime:mostRecentCreationTime, mostRecent:true} }, items: null };
  146. this.addMenuItemChecked(bSameAsCurrent, oMenuItem);
  147. menuItems.push(oMenuItem);
  148. menuItems.push({separator: true});
  149. menuItems = menuItems.concat(versions);
  150. }
  151. buttonSpec.open = bOpen;
  152. buttonSpec.items = menuItems;
  153. var updateItems = [];
  154. updateItems.push(buttonSpec);
  155. widget.fireEvent("com.ibm.bux.widgetchrome.toolbar.update", null, updateItems);
  156. };
  157. SnapshotsAction.prototype.resetMenu = function(bOpen) {
  158. var oCV = this.getCognosViewer();
  159. var widget = oCV.getViewerWidget();
  160. var root = oCV.findBlueDotMenu();
  161. var buttonSpec = oCV.findToolbarItem("Snapshots", root);
  162. if (buttonSpec) {
  163. buttonSpec.open = false;
  164. var menuItems = [{ name: "loadng", label: RV_RES.GOTO_LOADING, iconClass: "loading"}];
  165. buttonSpec.items = menuItems;
  166. var updateItems = [buttonSpec];
  167. widget.fireEvent("com.ibm.bux.widgetchrome.toolbar.update", null, updateItems);
  168. }
  169. };