functionTree.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2021 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. var functionsTree = null;
  11. var QOS_UNAVAILABLE = "unavailable";
  12. var QOS_RESTRICTED = "restricted";
  13. var QOS_LIMITED = "limited";
  14. var QOS_OK = "OK";
  15. var FUNCTION_ROOT_START = "functionRoot-start";
  16. var FUNCTION_ROOT_END = "functionRoot-end";
  17. var FUNCTION_GROUP_START = "group-start";
  18. var FUNCTION_GROUP_END = "group-end";
  19. var FUNCTION_FUNCTION = "function";
  20. var FUNCTION_TYPE_FUNCTION = "function";
  21. var FUNCTION_TYPE_SUMMARY = "summary";
  22. var FUNCTION_TYPE_OPERATOR = "operator";
  23. var FUNCTION_TYPE_LITERAL = "literal";
  24. var FUNCTION_TYPE_OPERATION = "operation";
  25. // normal response
  26. var FUNCTION_FUNCTIONS_ROOT = "functionsRoot";
  27. var FUNCTION_GROUP = "group";
  28. var FUNCTION_FUNCTION = "function";
  29. var FUNCTION_ATTR_NAME = "name";
  30. var FUNCTION_ATTR_QOSLEVEL = "qosLevel";
  31. var FUNCTION_ATTR_DROPTEXT = "dropText";
  32. var FUNCTION_ATTR_SYNTAX = "syntax";
  33. var FUNCTION_ATTR_TIP = "tip";
  34. var FUNCTION_ATTR_TYPE = "type";
  35. var FUNCTION_ATTR_ID="id";
  36. //function ids
  37. var MEMBER_SEARCH_IN_HIERARCHY = "MEMBER_SEARCH_IN_HIERARCHY";
  38. // an array of nodes that are to be loaded. we need the array
  39. // as the passport might have expired
  40. var loadingfunNodes = new Array();
  41. // utility function
  42. function getFunctionDataRequestString(model)
  43. {
  44. var sURL = "";
  45. var clk = "cl";
  46. var plk = "pl";
  47. var locales = getLocales(clk, plk);
  48. sURL += URIEncode(clk, locales[clk]);
  49. sURL += URIEncode(plk, locales[plk]);
  50. sURL += URIEncode("model", model);
  51. sURL += URIEncode("inlineSpecType","reportServiceMetadataSpecification");
  52. sURL += URIEncode("method", "runSpecification");
  53. sURL += URIEncode("prompt", "false");
  54. sURL += URIEncode("parameterValues", getConnectionParameterValues());
  55. // return the request
  56. return sURL;
  57. }
  58. function promptFunctionResponse(parameters, response, conversation, clientContext, tracking)
  59. {
  60. if (response == "Cancel" || response == "Error")
  61. {
  62. // this is reasonable in this instance - we wouldn't be able to load the metadata tree
  63. // if we cancel out.
  64. closeAGS();
  65. }
  66. else
  67. {
  68. //re write any parameterValues saved
  69. saveParameterValues(parameters);
  70. // send the context and the final response from prompts back
  71. var request = getFunctionDataRequestString()
  72. request += URIEncode("context", clientContext);
  73. request += URIEncode("promptResponse", response);
  74. request += URIEncode("disp_trackingInfo", tracking);
  75. // hide the dialog frame and pop up frame(and make sure they dont re open)
  76. showDialogFrame(0);
  77. doSetPopUpClosureFlag();
  78. // resubmit the request
  79. setTimeout("doFunctionDataRequest('" + request + "');", 100);
  80. }
  81. }
  82. //at this point, we will have been through the meta data request
  83. //and may have connection parameter values to pass
  84. function doFunctionDataRequest(request)
  85. {
  86. // build up the URL
  87. var url = "b_action=xts.run";
  88. url += URIEncode("m","/ags/async/asyncConv.xts");
  89. url += URIEncode("buildRequestXTS","/ags/async/functionTreeRequest.xts");
  90. url += URIEncode("buildResponseXTS","/ags/async/functionTreeResponse.xts");
  91. url += URIEncode("paramterValues",getConnectionParameterValues());
  92. // force a SOAPFault for passport expire rather than getting a logon page
  93. url += URIEncode("forceSOAPFault","false");
  94. url += request;
  95. if (cafContextId != "") {
  96. url += URIEncode("cafcontextid",cafContextId);
  97. }
  98. try{
  99. // send off the resquest
  100. sendDispatcherRequestWithXMLTextResponse(url, functionDataXMLTextResponse);
  101. }catch(ex){
  102. applicationActionManager.httpStop();
  103. }
  104. }
  105. // the double click function
  106. function doubleClickF(evt)
  107. {
  108. insertStartMC(undefined, evt);
  109. }
  110. // the single click function
  111. function singleClickF(evt)
  112. {
  113. //Create dummay function.
  114. var selectedFunction = new fnFunction("", "", "","", "", "");
  115. // get the node which has been selected.
  116. var selectedFunctionNodes = functionsTree.getSelectedLeafNodes();
  117. // this should always be the case - we set the tree up to force single selection
  118. if (selectedFunctionNodes.length == 1) {
  119. var selectedFunctionNode = selectedFunctionNodes[0];
  120. // we've got the tree node - get the object it's carrying
  121. selectedFunction = selectedFunctionNode.getValue();
  122. }
  123. // have to update the information in the tip window
  124. displayInformationTip(selectedFunction);
  125. }
  126. //this function is called when the Function tab is clicked
  127. //it is called by changeMenu() in the layout.js library
  128. function doFunctionTree() {
  129. var cmLastModel = cfgGet("cmLastModel");
  130. if (cmLastModel != null && cfgGet("queryLoaded"))
  131. {
  132. if (functionsTree == null)
  133. {
  134. if (browserCheck.isNav6Up())
  135. {
  136. document.getElementById("functionsTreeContainer").addEventListener("mouseup", function(e) {if(e.target.toString().indexOf("XULElement") > -1){e.cancelBubble = true;return false;}}, true);
  137. document.getElementById("functionsTreeContainer").addEventListener("dragover", function(e) {cancelBub(e);}, true);
  138. document.getElementById("functionsTreeContainer").addEventListener("dragdrop", function(e) {cancelBub(e);}, true);
  139. }
  140. var functionsTreeNode = document.getElementById("functionsTreeContainer");
  141. // at this point - this is the only node with this id
  142. functionsTreeNode.setAttribute("container", "true");
  143. functionsTreeNode.setAttribute("tabindex", "-1");
  144. // now create and render the tree
  145. functionsTree = new CTree (functionsTreeNode, "", false, true, "functionsTree");
  146. functionsTree.setLoadOnTheFlyFunction(functionPushAndLoadFunc);
  147. functionsTree.setSelectionMode(SINGLE_TREE_SELECTION);
  148. functionsTree.setSelectTreeUI(NORMAL_TREE);
  149. functionsTree.setAllowDragDrop(true);
  150. functionsTree.setOnDragStart(onDragStartF);
  151. functionsTree.setOnDrag(onDragF);
  152. functionsTree.setOnDragEnd(onDragEndF);
  153. functionsTree.setTrackSelectionOrder(true);
  154. functionsTree.setHideOuterTable(true);
  155. //functionsTree.setForceSelectionAtLowestLevel(true);
  156. functionsTree.setContextMenu(function contextMenu(){return false;});
  157. // get the function tree to update tips section of condition dialog
  158. functionsTree.setSingleClickFunc(singleClickF);
  159. functionsTree.setDoubleClickFunc(doubleClickF);
  160. functionsTree.setAllowSelectionToggle(true);
  161. functionsTree.drawAll();
  162. functionsTree.checkData();
  163. }
  164. }
  165. else
  166. setTimeout(doFunctionTree, 250);
  167. }
  168. function reloadFunctionsTree()
  169. {
  170. if (cfgGet("reloadFunctionsTree") != null) {
  171. resetFunctionsTree();
  172. // load it up again
  173. doFunctionTree();
  174. } else {
  175. // pop the command stack
  176. setTimeout("getCommandStackManager().processCommandStack()", 100);
  177. }
  178. // clear out the flag
  179. cfgRemove("reloadFunctionsTree");
  180. }
  181. function resetFunctionsTree()
  182. {
  183. if (functionsTree != null) {
  184. // we have to remove the tree
  185. functionsTree = null;
  186. // remove the rendering of the tree
  187. removeTreeRendering("functionsTreeContainer");
  188. // reset this - not sure why though
  189. draggedTreeObj = null;
  190. // say that we've not loaded the tree
  191. cfgSet("META_FunctionTreeLoadedFirstTime",null);
  192. }
  193. }
  194. function functionPushAndLoadFunc(loadingNode)
  195. {
  196. loadingfunNodes.push(loadingNode);
  197. functionLoadFunc(loadingNode);
  198. }
  199. function functionLoadFunc(loadingNode)
  200. {
  201. applicationActionManager.httpStart();
  202. if (cfgGet("META_FunctionTreeLoadedFirstTime") == null)
  203. {
  204. cfgSet("META_FunctionTreeLoadedFirstTime", "loading");
  205. var request = getFunctionDataRequestString(cfgGet("cmLastModel"));
  206. doFunctionDataRequest(request);
  207. }
  208. else if (cfgGet("META_FunctionTreeLoadedFirstTime") != "loading")
  209. {
  210. var request = getFunctionDataRequestString(cfgGet("cmLastModel"));
  211. doFunctionDataRequest(request);
  212. }
  213. }
  214. // if no node is to be loaded, tidyup the tree otherwise load the nodes
  215. function checkfunPassportStatus() {
  216. // no node is in the load mode
  217. if (loadingfunNodes.length < 1 ) {
  218. tidyFunctionsTree();
  219. } else {
  220. // load all the nodes waiting to be loaded
  221. while (loadingfunNodes.length > 0) {
  222. var theLoadingNode = loadingfunNodes.pop();
  223. functionLoadFunc(theLoadingNode);
  224. }
  225. }
  226. }
  227. // add the command to load the nodes to the stack
  228. function addTofunStack()
  229. {
  230. var treeCommand = getCommandStackManager().createCommandStack("checkfunPassportStatus()");
  231. var currentStack = getCommandStackManager().getCommandStack();
  232. var newStack = currentStack.concat(treeCommand);
  233. getCommandStackManager().setCommandStack(newStack);
  234. }
  235. function functionDataXMLTextResponse(responseArray)
  236. {
  237. // get the values returned
  238. var responseXML = responseArray[0];
  239. var responseText = responseArray[1];
  240. var workingRoot = responseXML.getElementsByTagName(ASYNC_WORKING);
  241. var promptingRoot = responseXML.getElementsByTagName(ASYNC_PROMPTING);
  242. var functionsRoot = responseXML.getElementsByTagName(FUNCTION_FUNCTIONS_ROOT);
  243. var httpStop = true;
  244. // the loading nodes should be remembered only if passport has expired
  245. var keeploadingfunNodes = false;
  246. var parsedResponse = parseResponse(responseXML,responseText);
  247. // decide what we're going to do
  248. //This is a case when getContent in asyncConv faults with either session expiry or
  249. //external logon to a different name space fault.
  250. if (parsedResponse.isLogonFault()) {
  251. doPassportExpire(responseXML,addTofunStack,parsedResponse);
  252. // load the nodes after login succeeds
  253. keeploadingmdtNodes = true;
  254. } else if (parsedResponse.isSoapFault()) {
  255. if (parsedResponse.isCancelledWait()) {
  256. //This was a server cancelled wait. We need to resubmit. This could happen
  257. //if we have a SSO on and we hit an password protected external datasource,
  258. //The dispacther will fire the same request again, in this wait fired twice
  259. //Will cancel conversation if first wait fails. WO1903, WO2338
  260. getCommandStackManager().getCommandStack().push("reloadFunctionsTree()");
  261. setTimeout("getCommandStackManager().processCommandStack()", 100);
  262. } else {
  263. // we have a fault which is a genuine fault fault
  264. doSOAPFault(responseXML,tidyFunctionsTree,parsedResponse);
  265. }
  266. } else if (workingRoot.length == 1) {
  267. httpStop = false;
  268. // we have a working response
  269. doWorking(workingRoot[0], "doFunctionDataRequest");
  270. } else if (promptingRoot.length == 1) {
  271. // are we prompting - promptFunctionResponse
  272. doPrompting(promptingRoot[0], 1);
  273. } else if (functionsRoot.length == 1) {
  274. // we have the actually information
  275. // clear the response
  276. response = "";
  277. buildFunctionRoot(functionsRoot[0].childNodes[0]);
  278. } else {
  279. tidyFunctionsTree();
  280. if (parsedResponse.isHTML() && !parsedResponse.isEmptyBody()) {
  281. // check the text response to see if we got a html page back in the response
  282. doHTMLResponse(responseText);
  283. } else {
  284. alert(asyncFunctionError_string);
  285. }
  286. }
  287. if(httpStop){
  288. applicationActionManager.httpStop();
  289. }
  290. if (keeploadingfunNodes == false) {
  291. //empty the array
  292. loadingfunNodes.splice(0, loadingfunNodes.length);
  293. }
  294. }
  295. function tidyFunctionsTree() {
  296. resetFunctionsTree();
  297. var treeContainer = document.getElementById("functionsTreeContainer");
  298. if (treeContainer) {
  299. var html = '<a href="#" class="menuItem_normal" onclick="refreshFunctionsTree()">' + refresh_string + '</a>';
  300. treeContainer.innerHTML = html;
  301. }
  302. }
  303. function refreshFunctionsTree() {
  304. removeTreeRendering('functionsTreeContainer');
  305. doFunctionTree();
  306. }
  307. function buildChildNodes(obj, parentNode)
  308. {
  309. // get all the childNodes
  310. for (var i = 0; obj.childNodes != null && i < obj.childNodes.length; ++i) {
  311. var qosLevel = obj.childNodes[i].getAttribute(FUNCTION_ATTR_QOSLEVEL);
  312. if (!(qosLevel == QOS_UNAVAILABLE)) {
  313. if (obj.childNodes[i].nodeName == FUNCTION_GROUP) {
  314. buildFunctionGroup(obj.childNodes[i], parentNode);
  315. }
  316. if (obj.childNodes[i].nodeName == FUNCTION_FUNCTION) {
  317. buildFunctionFunction(obj.childNodes[i], parentNode);
  318. }
  319. }
  320. }
  321. }
  322. function buildFunctionRoot(obj)
  323. {
  324. try {
  325. functionsTree.getRootNode().setName(functionRoot_string);
  326. functionsTree.setRootNodeType(tntFunctionRoot);
  327. functionsTree.setRootNodeShowing(true);
  328. functionsTree.drawAll();
  329. // decode all the childNodes
  330. buildChildNodes(obj, functionsTree.getRootNode());
  331. // we've finished loading - so remove loading and redraw
  332. var rootNode = functionsTree.getRootNode();
  333. functionsTree.childrenReadyForNode(rootNode);
  334. // we've loaded this up now
  335. cfgSet("META_FunctionTreeLoadedFirstTime", true);
  336. }
  337. catch (ex) {
  338. console.error(ex);
  339. applicationActionManager.httpStop();
  340. }
  341. setTimeout("getCommandStackManager().processCommandStack();", 100);
  342. }
  343. function buildFunctionGroup(obj, parentNode)
  344. {
  345. var name = obj.getAttribute(FUNCTION_ATTR_NAME);
  346. if (name != "") {
  347. // get the attributes of the group element
  348. var qosLevel = obj.getAttribute(FUNCTION_ATTR_QOSLEVEL);
  349. // build the group Tree Node
  350. var groupObj = new fnGroup(name, qosLevel);
  351. var groupNode = new CTreeNode(parentNode, tntGroup, false, name, groupObj, false);
  352. // have to set the indicator for the node
  353. setNodeIndicator(groupNode, qosLevel);
  354. // have to set the node as being loaded as well - if there's a folder which doesn't have
  355. // children it will invoke the load on the fly function which is not needed for the function tree
  356. groupNode.setLoading(true);
  357. // set the tool tip
  358. groupNode.setTooltip(name);
  359. }
  360. buildChildNodes(obj, groupNode);
  361. }
  362. function buildFunctionFunction(obj, parentNode)
  363. {
  364. var id = obj.getAttribute(FUNCTION_ATTR_ID);
  365. var type = obj.getAttribute(FUNCTION_ATTR_TYPE);
  366. //get the qosLevel for hierarchy searches
  367. if (type==FUNCTION_TYPE_OPERATION && id==MEMBER_SEARCH_IN_HIERARCHY) {
  368. cfgSet(MEMBER_SEARCH_IN_HIERARCHY,obj.getAttribute(FUNCTION_ATTR_QOSLEVEL));
  369. }
  370. if (obj.getAttribute(FUNCTION_ATTR_NAME) != "") {
  371. // get the attributes of the function
  372. var dropText = obj.getAttribute(FUNCTION_ATTR_DROPTEXT);
  373. var name = obj.getAttribute(FUNCTION_ATTR_NAME);
  374. var syntax = obj.getAttribute(FUNCTION_ATTR_SYNTAX);
  375. var tip = obj.getAttribute(FUNCTION_ATTR_TIP);
  376. var qosLevel = obj.getAttribute(FUNCTION_ATTR_QOSLEVEL);
  377. // build the function object
  378. var useType = (type == "" ? dropText : type);
  379. var tntType;
  380. if (useType == FUNCTION_TYPE_OPERATOR) {
  381. tntType = tntOperator;
  382. } else if (useType == FUNCTION_TYPE_SUMMARY) {
  383. tntType = tntSummary;
  384. }else if (useType == FUNCTION_TYPE_LITERAL) {
  385. tntType = tntLiteral;
  386. }else if (useType == FUNCTION_TYPE_FUNCTION) {
  387. tntType = tntFunction;
  388. }
  389. var funcObj = new fnFunction(dropText, name, syntax, tip, type, qosLevel);
  390. var funcNode = new CTreeNode(parentNode, tntType, false, name, funcObj, false);
  391. // have to set the indicator for the node
  392. setNodeIndicator(funcNode, qosLevel);
  393. // set the tool tip
  394. funcNode.setTooltip(tip);
  395. }
  396. }
  397. function setNodeIndicator(node, qosLevel)
  398. {
  399. // only do this if the correct function is in PRMT tree
  400. if (node.setIndicator) {
  401. if (qosLevel == QOS_UNAVAILABLE) {
  402. } else if (qosLevel == QOS_RESTRICTED) {
  403. node.setIndicator("../ags/images/tree/qosLevel_restricted.gif");
  404. } else if (qosLevel == QOS_LIMITED) {
  405. node.setIndicator("../ags/images/tree/qosLevel_limited.gif");
  406. } else if (qosLevel == QOS_OK) {
  407. }
  408. }
  409. }
  410. function functionTreextsError(m)
  411. {
  412. // forward it
  413. functionsTree.xtsError(m);
  414. }