selectValues.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2010 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. var SV_ROOT = "selectValues";
  11. var SV_VALUES = "values";
  12. var SV_VALUE = "value";
  13. var SV_TYPE = "type";
  14. var SV_SECONDARY_REQUESTS = "secondaryRequests";
  15. var SV_SECONDARY_REQUEST = "secondaryRequest";
  16. var SV_VALUE_USE_ATTR = "use";
  17. var SV_VALUE_DISPLAY_ATTR = "display";
  18. var dataRequest = null;
  19. var callbackFn = null;
  20. var sv_conversation = null;
  21. var sv_tracking = null;
  22. var sv_useValues = null;
  23. var sv_displayValues = null;
  24. var sv_secondaryRequests = null;
  25. var sv_type = null;
  26. var sv_page = null;
  27. // some messages that we can passback to the client so it know's what's going on
  28. var SV_PASSPORT = "passport";
  29. var SV_FAULT = "fault";
  30. var SV_WORKING = "working";
  31. var SV_PROMPTING = "prompting";
  32. var SV_FINISHED = "finished";
  33. var SV_CANCEL = "cancel";
  34. var SV_PROMPTING_FINISHED = "prompting_finished"
  35. // utility function
  36. function doSelectValuesRequest(callback_function, method, treeObj, sort, filter, filter_type, tracking, conversation)
  37. {
  38. // save the callback function
  39. callbackFn = callback_function;
  40. // get the request
  41. var request = getDataRequestString(method, treeObj, sort, filter, filter_type, tracking, conversation);
  42. // do it
  43. doDataRequest(request);
  44. }
  45. function getDataRequestString(method, treeObj, sort, filter, filter_type, tracking, conversation)
  46. {
  47. var sURL = "";
  48. var cl="";
  49. var pl="";
  50. //define the expression locale
  51. var el="";
  52. var clk = "cl";
  53. var plk = "pl";
  54. var locales = getLocales(clk, plk);
  55. sURL += URIEncode(clk, locales[clk]);
  56. sURL += URIEncode(plk, locales[plk]);
  57. sURL += URIEncode("el",getExpressionLocale());
  58. // add the sort order
  59. sURL += URIEncode("sort", sort);
  60. // add the filters - have to duplicate apostrophe's in filters
  61. if (filter) {
  62. sURL += URIEncode("filter", filter.replace(/'/g, "''"));
  63. }
  64. sURL += URIEncode("filter_type", filter_type);
  65. // conversation
  66. sURL += URIEncode("disp_trackingInfo", tracking);
  67. sURL += URIEncode("conversation", conversation);
  68. // more stuff
  69. sURL += URIEncode("xslURL", "selectValue.xslt");
  70. sURL += URIEncode("model", cfgGet("cmLastModel"));
  71. // have to determine what sort of query we're doing - if we're looking for members we
  72. // have to use the caption() function
  73. if (treeObj.type == "level" || treeObj.type == "hierarchy") {
  74. sURL += URIEncode("memberRequest","1");
  75. }
  76. // add the other parametetshttp://c1.zedo.com/jsc/c1/ff2.html?n=162;c=1159;s=175;d=16;w=720;h=300;t=UndertoneNetworks.com-Advertisement
  77. sURL += URIEncode("method",method);
  78. sURL += URIEncode("inlineSpecType","reportServiceReportSpecification");
  79. // add the other parametets
  80. sURL += URIEncode("prompt", "false");
  81. if (treeObj != null) {
  82. sURL += URIEncode("queryRef",treeObj.name);
  83. var referencedQueryItems = cf.getTreeValues(getDataItemsTree());
  84. var itemsStr="";
  85. //build the XMl for the data item that has been selected
  86. //Use aggregates only if it is a dataitem. i.e noAggregate should be false.
  87. var noAggregate = !(treeObj instanceof aiDataItem);
  88. itemsStr = buildDataItemXML(treeObj,sort,noAggregate);
  89. /*
  90. Loop though the query items and create a <dataItem/> XML fragment for each one e.g.
  91. <dataItem name="Unit price" aggregate="average">
  92. <expression>[gosales_goretailers].[Orders].[Unit price]</expression>
  93. </dataItem>
  94. */
  95. for (var i=0;i<referencedQueryItems.length;i++) {
  96. var qi=referencedQueryItems[i];
  97. //exclude the queryRef data item
  98. if (qi.ref != treeObj.ref) {
  99. itemsStr += buildDataItemXML(qi);
  100. }
  101. }
  102. }
  103. sURL += URIEncode("queryItems",itemsStr);
  104. // add the 888 parameter condom - safe sex sort of thing
  105. sURL += URIEncode("parameterValues",getConnectionParameterValues());
  106. // return the request
  107. return sURL;
  108. }
  109. function doDataRequest(request)
  110. {
  111. var url = "b_action=xts.run";
  112. url += URIEncode("m","/ags/async/asyncConv.xts");
  113. url += URIEncode("buildRequestXTS","/ags/async/selectValuesRequest.xts");
  114. url += URIEncode("buildResponseXTS","/ags/async/selectValuesResponse.xts");
  115. // force SOAPFault for passport expire instead of getting a logon page
  116. url += URIEncode("forceSOAPFault","false");
  117. url += request;
  118. if (cafContextId != "") {
  119. url += URIEncode("cafcontextid",cafContextId);
  120. }
  121. // remove the previous request if it's possible
  122. if (dataRequest!= null) {
  123. cancelDispatcherRequest(dataRequest);
  124. }
  125. // send off the resquest - keep hold of the request object this time
  126. dataRequest = sendDispatcherRequestWithXMLTextResponse(url, selectDataXMLTextResponse);
  127. }
  128. function promptSelectDataResponse(parameters, response, conversation, clientContext, tracking)
  129. {
  130. if (response == "Cancel" || response == "Error")
  131. {
  132. doClosePopUp();
  133. // we just want to cancel out of here - though error should be different
  134. callClientCallback(SV_CANCEL);
  135. }
  136. else
  137. {
  138. callClientCallback(SV_PROMPTING_FINISHED);
  139. //re write any parameterValues saved
  140. saveParameterValues(parameters);
  141. // send the context and the final response from prompts back
  142. var request = URIEncode("context", clientContext);
  143. request += URIEncode("promptResponse", response);
  144. request += URIEncode("disp_trackingInfo", tracking);
  145. // hide the dialog frame and pop up frame(and make sure they dont re open)
  146. showDialogFrame(0);
  147. doSetPopUpClosureFlag();
  148. // resubmit the request
  149. setTimeout("doDataRequest('" + request + "');", 100);
  150. }
  151. }
  152. function callClientCallback(status)
  153. {
  154. if (callbackFn != null)
  155. {
  156. try {
  157. callbackFn(status);
  158. } catch(ex) {
  159. //This might fail so capture the expection and do nothing
  160. }
  161. }
  162. }
  163. function selectDataXMLTextResponse(responseArray)
  164. {
  165. // get the values returned
  166. var responseXML = responseArray[0];
  167. var responseText = responseArray[1];
  168. // the request is finished - we can just remove it
  169. dataRequest = null;
  170. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  171. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  172. var valuesRoot = responseXML.getElementsByTagName(ASYNC_RESPONSE);
  173. var parsedResponse = parseResponse(responseXML,responseText);
  174. // decide what we're going to do
  175. //This is a case when getContent in asyncConv faults with either session expiry or
  176. //external logon to a different name space fault.
  177. if (parsedResponse.isLogonFault()) {
  178. // tell the client what's going on
  179. callClientCallback(SV_PASSPORT);
  180. doPassportExpire(responseXML,null,parsedResponse);
  181. } else if (parsedResponse.isSoapFault()) {
  182. // tell the client what's going on
  183. callClientCallback(SV_FAULT);
  184. // we have a fault which is a genuine fault fault
  185. doSOAPFault(responseXML,null,parsedResponse);
  186. } else if (workingRoot.length == 1) {
  187. // tell the client what's going on
  188. callClientCallback(SV_WORKING);
  189. // we have a working response
  190. doWorking(workingRoot[0], "doDataRequest");
  191. } else if (promptingRoot.length == 1) {
  192. // tell the client what's going after getting all the values
  193. callClientCallback(SV_PROMPTING);
  194. // are we prompting
  195. //7.doPrompting(promptingRoot[0],"parent.getConfigFrame().promptSelectDataResponse","selectValue.xslt");
  196. doPrompting(promptingRoot[0], 7, "selectValue.xslt");
  197. } else if (valuesRoot.length == 1) {
  198. buildSelectValues(valuesRoot[0]);
  199. // tell the client what's going after getting all the values
  200. callClientCallback(SV_FINISHED);
  201. } else {
  202. // tell the client what's going on
  203. callClientCallback(SV_FAULT);
  204. // check the text response to see if we got a html page back in the response
  205. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  206. doHTMLResponse(responseText);
  207. } else {
  208. alert(asyncSelectValuesError_string);
  209. }
  210. }
  211. }
  212. function buildSelectValues(obj)
  213. {
  214. // get the conversation element
  215. var conversationElements = obj.getElementsByTagName(ASYNC_CONVERSATION);
  216. // get the tracking element
  217. var trackingElements = obj.getElementsByTagName(ASYNC_TRACKING);
  218. // get the values element
  219. var valuesElements = obj.getElementsByTagName(SV_VALUES);
  220. // get the type element
  221. var typeElements = obj.getElementsByTagName(SV_TYPE);
  222. // get the secondary request elements
  223. var secondaryRequestsElements = obj.getElementsByTagName(SV_SECONDARY_REQUESTS);
  224. // we want the actual values
  225. sv_conversation = null;
  226. sv_tracking = null;
  227. sv_useValues = new Array();
  228. sv_displayValues = new Array();
  229. sv_secondaryRequests = new Array();
  230. // check to see if the converstaion/tracking is valid - we might return nothing
  231. // if the conversation completed.
  232. if (conversationElements[0].childNodes.length > 0) {
  233. sv_conversation = getTextNodeValue(conversationElements[0]);
  234. }
  235. if (trackingElements[0].childNodes.length > 0) {
  236. sv_tracking = getTextNodeValue(trackingElements[0]);
  237. }
  238. // clear out the type
  239. sv_type = null;
  240. // get the type if there is one
  241. if (typeElements.length == 1) {
  242. if (typeElements[0].childNodes.length == 1) {
  243. sv_type = getTextNodeValue(typeElements[0]);
  244. }
  245. }
  246. // have to get all the values - loop over the childNodes
  247. if (valuesElements.length == 1) {
  248. var valueElements = valuesElements[0].getElementsByTagName(SV_VALUE);
  249. for (var i = 0; i < valueElements.length; i++) {
  250. var useValue = valueElements[i].getAttribute(SV_VALUE_USE_ATTR);
  251. var displayValue = valueElements[i].getAttribute(SV_VALUE_DISPLAY_ATTR);
  252. // use value might not be present - so copy the display value if not
  253. if (useValue == null) {
  254. useValue = displayValue;
  255. }
  256. // borrowed wholesale from ReportStudio - types refer to CCLDBType enumeration:
  257. var v_sQuote = "";
  258. switch (sv_type) {
  259. case "1": //cclDTypeString
  260. case "25": //cclDTypeMemberUniqueName
  261. case "26": //cclDTypeMemberCaption
  262. case "27": //cclDTypeDimensionUniqueName
  263. case "28": //cclDTypeParentUniqueName
  264. case "29": //cclDTypeDescription
  265. case "30": //cclDTypeHierarchyUniqueName
  266. case "31": //cclDTypeParentLevel
  267. case "32": //cclDTypeLevelUniqueName
  268. case "34": //cclDTypeLevelLabel
  269. case "35": //cclDTypeFormattedValue
  270. case "36": //cclDTypeFont
  271. case "43": //cclDTypeMemberType
  272. case "45": //cclDTypeExternalBuffer
  273. case "55": //cclDTypeNChar
  274. case "56": //cclDTypeNVarChar
  275. v_sQuote = "'";
  276. break;
  277. }
  278. // use only display values for the time being
  279. useValue = displayValue;
  280. // have to double quote the useValue if there are any quotes in it & trim trailing spaces.
  281. useValue = useValue.replace(/'/g, "''");
  282. useValue = useValue.replace(/[\s]+$/g,"");
  283. // do the type magic on it
  284. useValue = v_sQuote + useValue + v_sQuote;
  285. // keep the pair of them
  286. sv_useValues.push(useValue);
  287. sv_displayValues.push(displayValue);
  288. }
  289. }
  290. // have to get all the secondary requests - loop over the secondaryRequests
  291. var secondaryRequestElements = secondaryRequestsElements[0].getElementsByTagName(SV_SECONDARY_REQUEST);
  292. for (var i = 0; i < secondaryRequestElements.length; ++i) {
  293. if (secondaryRequestElements[i].childNodes.length == 1) {
  294. sv_secondaryRequests.push(getTextNodeValue(secondaryRequestElements[i]));
  295. }
  296. }
  297. }