cognoslaunch.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2016
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. // cognosLaunch() utility
  10. //
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. //
  14. // Usage: cognosLaunch("ui.gateway","<gateway_uri>", "ui.tool","<studio_name>" [,"<name>","value>"]*)
  15. // Example: cognosLaunch("gateway","http://myserver:80/series8/cgi-bin/(cognosgateway)","ui.tool","ReportStudio");
  16. // parameter "ui.gateway" is mandatory. If "gateway" is a null string, the function will assume a relative path.
  17. //
  18. //
  19. // Usage: cognosLaunchInWindow(winName, winProperties,
  20. // "ui.gateway","<gateway_uri>", "ui.tool","<studio_name>" [,"<name>","value>"]*)
  21. // Example: cognosLaunch( "mywindow", "height=300,width=400,scrollbars=yes,resizable=yes",
  22. // "ui.gateway","http://myserver:80/series8/cgi-bin/(cognosgateway)","ui.tool","ReportStudio");
  23. //
  24. // if winName is null, empty or "_blank", a new window will be created with a random name
  25. // if no window named winName exists, a new window with that name will be created
  26. // if a window named winName already exists, the studio will be loaded into that window.
  27. // winProperties is a string containing a list of parameters that control the aspect/behavior of the new window
  28. //
  29. function cognosLaunch()
  30. {
  31. var JSINFRAMEPARAM="launch.openJSStudioInFrame";
  32. var jsinframeSpecified = false;
  33. var numArgs = arguments.length;
  34. var argsOut = new Array();
  35. for(i=0;i<numArgs;i+=2)
  36. {
  37. argsOut[i] = arguments[i];
  38. argsOut[i+1] = arguments[i+1];
  39. if ((jsinframeSpecified == false) && (arguments[i]==JSINFRAMEPARAM))
  40. {
  41. jsinframeSpecified = true;
  42. }
  43. }
  44. //If launch.openJSStudioInFrame hasn't been specified, set it to true as when using cognosLaunch() we want the studio to open up in the existing window.
  45. if (jsinframeSpecified == false)
  46. {
  47. argsOut[numArgs] = JSINFRAMEPARAM;
  48. argsOut[numArgs + 1] = 'true';
  49. }
  50. cognosLaunchArgArray(argsOut, "_self");
  51. }
  52. function cognosLaunchWithTarget(target)
  53. {
  54. //remove the target from the arguments array so we can pass the rest onto the usual congosLaunchArgArray
  55. var newArguments= new Array();
  56. var index;
  57. for (index =1;index < arguments.length ;index++)
  58. {
  59. newArguments[index-1] = arguments[index];
  60. }
  61. if (target == '')
  62. cognosLaunchArgArray(newArguments, "_self");
  63. else
  64. cognosLaunchArgArray(newArguments, target);
  65. }
  66. var gCognosWindowCount = 0;
  67. function cognosLaunchInWindow(winName, winProperties)
  68. {
  69. var target = winName;
  70. var newWindow = null;
  71. if (winName==null || winName=="_blank" || winName=="")
  72. {
  73. target = winName= "cognos_window" + (gCognosWindowCount++) + (Math.random() + "").substring(2);
  74. }
  75. if (! (winName=="_top" || winName=="_parent" || winName=="_self"))
  76. {
  77. var webRoot = (window.psWebContentRoot !== undefined && window.psWebContentRoot !== null )? window.psWebContentRoot : "../ps/";
  78. newWindow = window.open(webRoot + "images/space.gif",winName,winProperties)
  79. newWindow.focus();
  80. }
  81. var argsOut = new Array();
  82. for (i = 2; i < arguments.length; i++)
  83. {
  84. argsOut[i-2] = arguments[i];
  85. }
  86. var numArgs = argsOut.length;
  87. argsOut[numArgs] = 'launch.launchInWindow';
  88. argsOut[numArgs + 1] = 'true';
  89. cognosLaunchArgArray(argsOut, target);
  90. }
  91. function cognosLaunchArgArray(argArray, strTarget, winTarget)
  92. {
  93. var ERR_NOGATEWAY="cognosLaunch() error: ui.gateway parameter is missing.";
  94. var ERR_UNEVEN="cognosLaunch() error: Uneven number of arguments.";
  95. var GATEWAYPARAM="ui.gateway";
  96. var numArgs = argArray.length;
  97. var gateway="";
  98. var gatewaySpecified = false;
  99. var docTarget = window.document;
  100. if (winTarget != null)
  101. {
  102. docTarget = winTarget.document;
  103. }
  104. var formElement = docTarget.createElement("form");
  105. formElement.setAttribute("name","xtslaunch");
  106. formElement.setAttribute("method","POST");
  107. formElement.setAttribute("target",strTarget);
  108. if ((numArgs%2) != 0)
  109. {
  110. alert(ERR_UNEVEN);
  111. return;
  112. }
  113. for(i=0;i<numArgs;i+=2)
  114. {
  115. if(argArray[i]==GATEWAYPARAM)
  116. {
  117. gateway = argArray[i+1];
  118. gatewaySpecified = true;
  119. break;
  120. }
  121. }
  122. if(!gatewaySpecified)
  123. {
  124. alert(ERR_NOGATEWAY);
  125. return;
  126. }
  127. // IE has a problem where it strips the brackets from the location.host value, so determine the host and port
  128. // by extracting it out of the full URI
  129. var startIdx = location.href.indexOf("//") + 2;
  130. var endIdx = location.href.indexOf("/", startIdx);
  131. var hostPort = location.href.substring(startIdx, endIdx);
  132. if(gateway == "")
  133. {
  134. //No gateway specified. Generate an absolute gateway from the current location. NOTE: An absolute gateway is needed so the that created form will properly submit in FireFox.
  135. gateway=location.protocol + "//" + hostPort + location.pathname.replace(/[\<\>]/g,'');
  136. }
  137. //Convert a relative gateway into an absolute gateway for the created form. NOTE: An absolute gateway is needed so the that created form will properly submit in FireFox.
  138. if ((gateway.indexOf("http://") != 0) && (gateway.indexOf("https://") != 0))
  139. {
  140. gateway = location.protocol + "//" + hostPort + gateway;
  141. }
  142. formElement.setAttribute("action", gateway);
  143. var hiddenElement = docTarget.createElement("input");
  144. hiddenElement.setAttribute("type","hidden");
  145. hiddenElement.setAttribute("name","b_action");
  146. hiddenElement.setAttribute("value","xts.run");
  147. formElement.appendChild(hiddenElement);
  148. hiddenElement = docTarget.createElement("input");
  149. hiddenElement.setAttribute("type","hidden");
  150. hiddenElement.setAttribute("name","m");
  151. hiddenElement.setAttribute("value","portal/launch.xts");
  152. formElement.appendChild(hiddenElement);
  153. for(i=0;i<numArgs;i+=2)
  154. {
  155. hiddenElement = docTarget.createElement("input");
  156. hiddenElement.setAttribute("type","hidden");
  157. hiddenElement.setAttribute("name",argArray[i]);
  158. hiddenElement.setAttribute("value",argArray[i+1]);
  159. formElement.appendChild(hiddenElement);
  160. }
  161. try
  162. {
  163. docTarget.body.appendChild(formElement);
  164. formElement.submit();
  165. docTarget.body.removeChild(formElement);
  166. }
  167. catch (exception)
  168. {
  169. // Handles an older IE
  170. docTarget.appendChild(formElement);
  171. formElement.submit();
  172. docTarget.removeChild(formElement);
  173. }
  174. formElement = null;
  175. }
  176. //function directLaunch takes the 'smarts' of what was being done in launch.xts using the spec portal\launch\DashboardConsoleLaunch.xml and applies it here
  177. // So changes to this function need to be applied to the spec portal\launch\DashboardConsoleLaunch.xml
  178. function directLaunch()
  179. {
  180. var numArgs = arguments.length;
  181. var argsOut = new Array();
  182. for(i=0;i<numArgs;i+=2)
  183. {
  184. argsOut[i] = arguments[i];
  185. argsOut[i+1] = arguments[i+1];
  186. }
  187. directLaunchArgArray(argsOut, "_self");
  188. }
  189. function directLaunchArgArray(argArray, strTarget)
  190. {
  191. var ERR_NOGATEWAY="directLaunch() error: ui.gateway parameter is missing.";
  192. var ERR_UNEVEN="directLaunch() error: Uneven number of arguments.";
  193. var ERR_NOSUPPORT="directLaunch() error: Not supported.";
  194. var GATEWAYPARAM="ui.gateway";
  195. var UITOOL="ui.tool";
  196. var UIACTION = "ui.action";
  197. var UIID = "ui.id";
  198. var numArgs = argArray.length;
  199. var gatewayAbsolute="";
  200. var gateway="";
  201. var gatewaySpecified = false;
  202. var uitoolSpecified = false;
  203. var uitool="";
  204. var uiaction="";
  205. var uiactionSpecified = false;
  206. var uiid = "";
  207. var uiidSpecified = false;
  208. var docTarget = window.document;
  209. if ((numArgs%2) != 0)
  210. {
  211. alert(ERR_UNEVEN);
  212. return;
  213. }
  214. for(i=0;i<numArgs;i+=2)
  215. {
  216. if(argArray[i]==GATEWAYPARAM)
  217. {
  218. gateway = argArray[i+1];
  219. gatewaySpecified = true;
  220. }
  221. if(argArray[i]==UITOOL)
  222. {
  223. uitool = argArray[i+1];
  224. uitoolSpecified = true;
  225. }
  226. if(argArray[i]==UIACTION)
  227. {
  228. uiaction = argArray[i+1];
  229. uiactionSpecified = true;
  230. }
  231. if(argArray[i]==UIID)
  232. {
  233. uiid = argArray[i+1];
  234. uiidSpecified = true;
  235. }
  236. if(gatewaySpecified && uitoolSpecified && uiactionSpecified && uiidSpecified)
  237. break;
  238. }
  239. var formElement = docTarget.createElement("form");
  240. formElement.setAttribute("name","xtsdirect");
  241. formElement.setAttribute("method","GET");
  242. formElement.setAttribute("target",strTarget);
  243. if(!gatewaySpecified)
  244. {
  245. alert(ERR_NOGATEWAY);
  246. return;
  247. }
  248. // IE has a problem where it strips the brackets from the location.host value, so determine the host and port
  249. // by extracting it out of the full URI
  250. var startIdx = location.href.indexOf("//") + 2;
  251. var endIdx = location.href.indexOf("/", startIdx);
  252. var hostPort = location.href.substring(startIdx, endIdx);
  253. if(gateway == "")
  254. {
  255. //No gateway specified. Generate an absolute gateway from the current location. NOTE: An absolute gateway is needed so the that created form will properly submit in FireFox.
  256. var gatewayForm =location.protocol + "//" + hostPort + location.pathname.replace(/[\<\>]/g,'');
  257. }
  258. //Convert a relative gateway into an absolute gateway for the created form. NOTE: An absolute gateway is needed so the that created form will properly submit in FireFox.
  259. if ((gateway.indexOf("http://") != 0) && (gateway.indexOf("https://") != 0))
  260. {
  261. gatewayAbsolute = location.protocol + "//" + hostPort + gateway;
  262. }
  263. formElement.setAttribute("action", gatewayAbsolute);
  264. var hiddenElement = "";
  265. if ( uitoolSpecified && uitool === "DashboardConsole")
  266. {
  267. hiddenElement = docTarget.createElement("input");
  268. hiddenElement.setAttribute("type","hidden");
  269. hiddenElement.setAttribute("name","b_action");
  270. hiddenElement.setAttribute("value","icd");
  271. formElement.appendChild(hiddenElement);
  272. hiddenElement = docTarget.createElement("input");
  273. hiddenElement.setAttribute("type","hidden");
  274. hiddenElement.setAttribute("name","pathinfo");
  275. hiddenElement.setAttribute("value","/main");
  276. formElement.appendChild(hiddenElement);
  277. if (uiaction === 'edit' )
  278. {
  279. var srcURL = gateway + "/icd/feeds/cm/id/" + uiid + "?entry="
  280. hiddenElement = docTarget.createElement("input");
  281. hiddenElement.setAttribute("type","hidden");
  282. hiddenElement.setAttribute("name","src");
  283. hiddenElement.setAttribute("value",srcURL);
  284. formElement.appendChild(hiddenElement);
  285. }
  286. }
  287. else
  288. alert(ERR_NOSUPPORT);
  289. for(i=0;i<numArgs;i+=2)
  290. {
  291. if ( argArray[i] !== 'ui.id')
  292. {
  293. hiddenElement = docTarget.createElement("input");
  294. hiddenElement.setAttribute("type","hidden");
  295. hiddenElement.setAttribute("name",argArray[i]);
  296. hiddenElement.setAttribute("value",argArray[i+1]);
  297. formElement.appendChild(hiddenElement);
  298. }
  299. }
  300. try
  301. {
  302. docTarget.body.appendChild(formElement);
  303. formElement.submit();
  304. docTarget.body.removeChild(formElement);
  305. }
  306. catch (exception)
  307. {
  308. // Handles an older IE
  309. docTarget.appendChild(formElement);
  310. formElement.submit();
  311. docTarget.removeChild(formElement);
  312. }
  313. formElement = null;
  314. }