popUp.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2014 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. var x = -1;
  11. var y = -1;
  12. var mouseDown = false;
  13. var previousSubmit = null;
  14. var launchingStack = null;
  15. var popUpClosed = false;
  16. var popUpOpened = true;
  17. var popUpOpen = false;
  18. var popUpClosureFlag = false;
  19. var popUpNextOpenSize = null;
  20. var resetOM = null;
  21. function mouseDownSpan()
  22. {
  23. mouseDown=true;
  24. x=window.event.x;
  25. y=window.event.y;
  26. }
  27. function mouseUpSpan()
  28. {
  29. mouseDown = false;
  30. }
  31. function mouseMoveSpan()
  32. {
  33. if (mouseDown) {
  34. var delx = window.event.x - x;
  35. var dely = window.event.y - y;
  36. // find the span
  37. var span = document.getElementById('popUpSpan');
  38. // get the numbers
  39. var re = /(.*)px/;
  40. var left = span.style.left.replace(re,"$1");
  41. var top = span.style.top.replace(re,"$1");
  42. if (left.length == 0) {
  43. left = "0";
  44. }
  45. if (top.length == 0) {
  46. top = "0";
  47. }
  48. // move it
  49. span.style.left = parseInt(left) + delx + "px";
  50. span.style.top = parseInt(top) + dely + "px";
  51. //save the new pos
  52. x = window.event.x;
  53. y = window.event.y;
  54. }
  55. }
  56. function isPopUpFrame(aFrame){
  57. return aFrame && aFrame.name == 'popUpFrame';
  58. }
  59. function popUpIsOpen()
  60. {
  61. return popUpOpen;
  62. }
  63. function setPopUpState(state)
  64. {
  65. popUpOpen = state;
  66. //Reset the index
  67. history.startIndex = undefined;
  68. }
  69. function doOpenPopUpToSize(width, height)
  70. {
  71. //guard clause when the popup is already open
  72. if(popUpIsOpen()) {
  73. return;
  74. }
  75. var popUpFrameElement = parent.document.getElementById('popUpFrame');
  76. popUpFrameElement.style.display = "inline";
  77. popUpFrameElement.style.height = "100%";
  78. popUpFrameElement.style.width = "100%";
  79. popUpFrameElement.focus();
  80. // show the guard
  81. var guard = parent.document.getElementById('guard');
  82. guard.style.display='inline';
  83. // get the span
  84. var span = parent.document.getElementById('popUpSpan');
  85. span.style.display='inline';
  86. if(browserCheck.isIE5Up()){
  87. span.style.width=width + "px";
  88. span.style.height=height + "px";
  89. }else{
  90. span.style.width=width + "px";
  91. span.style.height=height + "px";
  92. }
  93. //span.style.visibility = 'visible';
  94. var our_top;
  95. var our_width;
  96. if(browserCheck.isIE5Up()){
  97. our_top = parent.document.body.clientHeight / 2 - height / 2;
  98. our_width = parent.document.body.clientWidth / 2 - width / 2;
  99. }else{
  100. our_top = parent.innerHeight / 2 - height / 2;
  101. our_width = parent.innerWidth / 2 - width / 2;
  102. }
  103. span.style.top = our_top;
  104. span.style.left = our_width;
  105. //change the z index -
  106. //Need to pop over the splash screen so makes sure zIndex is hig enough
  107. span.style.zIndex=20101;
  108. popUpFrameElement.style.zIndex=20102;
  109. guard.style.zIndex=2010;
  110. doShim(true);
  111. // we've opened the pop up
  112. setPopUpState(popUpOpened);
  113. }
  114. function setPopUpNextOpenSize(our_width, our_height){
  115. popUpNextOpenSize = new Object();
  116. popUpNextOpenSize.width = our_width;
  117. popUpNextOpenSize.height = our_height;
  118. }
  119. function doOpenPopUp()
  120. {
  121. var our_width = "700";
  122. var our_height = "600";
  123. if(popUpNextOpenSize){
  124. our_width = popUpNextOpenSize.width;
  125. our_height = popUpNextOpenSize.height;
  126. }
  127. var popUpForm = getPopUpFrame().document.forms[0];
  128. if(popUpForm["m"] && popUpForm["m"].value=="prompting/promptDataSource.xts"){
  129. our_width = "350";
  130. our_height = "300";
  131. }
  132. doOpenPopUpToSize(our_width, our_height);
  133. popUpNextOpenSize = null;
  134. }
  135. function doOpenPopUpToCurrentSize() {
  136. //guard clause when the popup is already open
  137. if(popUpIsOpen()) {
  138. return;
  139. }
  140. var popUpFrameElement = parent.document.getElementById('popUpFrame');
  141. popUpFrameElement.style.display = "inline";
  142. popUpFrameElement.style.height = "100%";
  143. popUpFrameElement.style.width = "100%";
  144. // show the guard
  145. var guard = parent.document.getElementById('guard');
  146. guard.style.display='inline';
  147. // get the span
  148. var span = parent.document.getElementById('popUpSpan');
  149. span.style.display='inline';
  150. //span.style.visibility = 'visible';
  151. //change the z index
  152. //Need to pop over the splash screen so makes sure zIndex is hig enough
  153. span.style.zIndex=20101;
  154. popUpFrameElement.style.zIndex=20102;
  155. guard.style.zIndex=2010;
  156. doShim(true);
  157. // we've opened the pop up
  158. setPopUpState(popUpOpened);
  159. }
  160. function doSetPopUpClosureFlag()
  161. {
  162. popUpClosureFlag = true;
  163. }
  164. function doResetPopUpClosureFlag()
  165. {
  166. popUpClosureFlag = false;
  167. }
  168. function popUpIsFlaggedForClosure()
  169. {
  170. return popUpClosureFlag;
  171. }
  172. function doClosePopUp()
  173. {
  174. //no is open guard here as the prompting pages sometimes leave the
  175. //pop up frame closure flag and open state out of synch because the prompting reloads
  176. //pages in the frame and the second time only the frame onload gets called
  177. //and it needs to be closed, but is already open
  178. var guard = document.getElementById('guard');
  179. //guard.style.display='none';
  180. var span = document.getElementById('popUpSpan');
  181. if (!document.all) {
  182. span.style.display='none';
  183. }
  184. var popUpFrameElement = parent.document.getElementById('popUpFrame');
  185. // we've closed the pop_up
  186. setPopUpState(popUpClosed);
  187. // reset the closure flag
  188. popUpClosureFlag = false;
  189. launchingStack = null;
  190. applicationActionManager.allowActions();
  191. //hide the popup by setting the zindex so that the message is displayed on top
  192. //Need to pop over the splash screen but now zIndex need to be changed back.
  193. span.style.zIndex=-20101;
  194. //span.style.visibility = 'hidden';
  195. popUpFrameElement.style.zIndex=-20102;
  196. guard.style.zIndex=-2010;
  197. doShim(false);
  198. }
  199. function utmlClosePopUp()
  200. {
  201. var ret_value = false;
  202. var popUpFrame = getPopUpFrame();
  203. var popUpFrameContentDocument = getFrameDocument(popUpFrame);
  204. var popUpForm = popUpFrameContentDocument.forms[0];
  205. if (popUpForm.ps_nav_op &&
  206. (popUpForm.ps_nav_op.value=='stack-down' ||
  207. popUpForm.ps_nav_op.value=='stack-down-save' ||
  208. popUpForm.ps_nav_op.value=='drop' ||
  209. popUpForm.ps_nav_op.value=='pop') &&
  210. popUpForm.ps_nav_stack &&
  211. popUpForm.ps_nav_stack.value == launchingStack) {
  212. // we can close the pop up
  213. ret_value = true;
  214. }
  215. return ret_value;
  216. }
  217. function controllerTemplateClosePopUp()
  218. {
  219. var ret_value = false;
  220. var popUpFrame = getPopUpFrame();
  221. var popUpFrameContentDocument = getFrameDocument(popUpFrame);
  222. var popUpForm = popUpFrameContentDocument.forms[0];
  223. if (popUpForm.controller_state) {
  224. // get the controller state
  225. var controller_state_value = popUpForm.controller_state.value;
  226. var controller_state_popup_override_value = 'false';
  227. var cf = parent.getConfigFrame();
  228. if(cf){
  229. controller_state_popup_override_value = cf.cfgGet("controller_state_popup_override");
  230. }
  231. // check to see if we end in finished or ok
  232. var finished_re = /.*finished$/;
  233. var cancelled_re = /.*canceled$/;
  234. if ( (controller_state_value.match(finished_re) ||
  235. controller_state_value.match(cancelled_re)) && controller_state_popup_override_value != 'true') {
  236. // we're closing
  237. ret_value = true;
  238. }
  239. }
  240. return ret_value;
  241. }
  242. function popUpFrameSubmitHandler()
  243. {
  244. //return false;
  245. processPopUpSubmit();
  246. }
  247. function resetToOriginalPage() {
  248. history.go(history.loginIndex);
  249. getCommandStackManager().processCommandStack();
  250. }
  251. function processPopUpSubmit() {
  252. // have to get this in different ways for different browsers
  253. var popUpFrame = getPopUpFrame();
  254. var popUpFrameContentDocument = getFrameDocument(popUpFrame);
  255. var popUpForm = popUpFrameContentDocument.forms[0];
  256. var target = popUpForm.target;
  257. //Are we closing the popup?
  258. var closingPopUp = (controllerTemplateClosePopUp() || utmlClosePopUp());
  259. // where are we going
  260. if (closingPopUp) {
  261. //Alter the destination XTS and keep track of original destination
  262. //append this information to the form, and submit.
  263. var m = popUpForm.m;
  264. var original_m = m.value;
  265. m.value = "/ags/doLoginProxy.xts";
  266. //Create hidden inputs
  267. var o_m_input = createHiddenInput(popUpFrameContentDocument,"original_m",original_m);
  268. var orig_input = createHiddenInput(popUpFrameContentDocument,"origin","popUpFrame");
  269. //append to form
  270. popUpForm.appendChild(o_m_input);
  271. popUpForm.appendChild(orig_input);
  272. //stay in the same frame
  273. target = "";
  274. } else {
  275. // Don't allow the form to submit to the _parent which is our main window, otherwise it
  276. // will blow away agent studio.
  277. //
  278. target = popUpForm.target=="_parent"?"messageIFrame":popUpForm.target;
  279. }
  280. var sessionExpired = (popUpForm.h_CAM_action && popUpForm.h_CAM_action.value.indexOf(K_logon) == 0) ? true : false;
  281. if (sessionExpired) {
  282. if(history.startIndex == undefined || history.startIndex < 0) {
  283. //Have a logon fault, and it is the first
  284. //time we see it so start the marker in history.
  285. history.startIndex = 0;
  286. } else {
  287. history.startIndex++;
  288. }
  289. } else {
  290. //We are logged in so remove the marker
  291. history.startIndex = undefined;
  292. }
  293. popUpForm.target = target;
  294. // call the original submit
  295. popUpForm.submit = previousSubmit;
  296. popUpForm.submit();
  297. // Restore our submit handler hook!! Incase the user clicks on the submit button more than once!!
  298. popUpForm.submit = popUpFrameSubmitHandler;
  299. }
  300. function setResetOM(omValue)
  301. {
  302. resetOM = omValue;
  303. }
  304. function popUpFrameOnLoad()
  305. {
  306. // have to get this in different ways for different browsers
  307. var popUpFrame = getPopUpFrame();
  308. var popUpFrameContentDocument = getFrameDocument(popUpFrame);
  309. var popUpHeight="600";
  310. var popUpWidth="700";
  311. var resize = true;
  312. if (popUpFrameContentDocument.forms && popUpFrameContentDocument.forms.length > 0) {
  313. var popUpForm = popUpFrameContentDocument.forms[0];
  314. //register a key down handler to detect changes
  315. eventHandlerChainUtil.doEventHandlerChain(popUpFrameContentDocument,"keydown",keyDownChecker.check);
  316. //Bug: 503051. A fix to set the form size to a reasonable dimesnions to fit in the popup frame.
  317. //Works for IE and firefox. IE seems to default to a minimum size that we can not go beyond.
  318. if (popUpForm["ui.action"] && popUpForm["ui.action"].value=="wait" && popUpForm["m"] && popUpForm["m"].value=="prompting/promptDataSource.xts") {
  319. popUpHeight = "200";
  320. popUpWidth = "280";
  321. }
  322. //check if the height and width have been explicitly set
  323. else {
  324. if (popUpForm["popUpHeight"] && popUpForm["popUpHeight"].value != "") {
  325. popUpHeight = popUpForm["popUpHeight"].value;
  326. resize = false;
  327. }
  328. if (popUpForm["popUpWidth"] && popUpForm["popUpWidth"].value != "") {
  329. popUpWidth = popUpForm["popUpWidth"].value;
  330. resize = false;
  331. }
  332. }
  333. // find the form
  334. previousSubmit = popUpForm.submit;
  335. //install our own onSubmit
  336. popUpForm.submit = popUpFrameSubmitHandler;
  337. if (!popUpIsOpen() && !popUpIsFlaggedForClosure()) {
  338. // open up the pop up
  339. doOpenPopUpToSize(popUpWidth, popUpHeight);
  340. }else if(popUpIsFlaggedForClosure()){
  341. doClosePopUp();
  342. parent.document.getElementById("messageIFrame").focus();
  343. return;
  344. }
  345. // keep the stack value if this is the first load
  346. if(!launchingStack && popUpForm.ps_nav_stack){
  347. // keep a copy of the nav_stack here too
  348. launchingStack = popUpForm.ps_nav_stack.value;
  349. }
  350. //bug#CQ00210567 logon screen was partially displayed after
  351. //session expiry in Event studio.
  352. if(isLogonPage(popUpForm)){
  353. popUpWidth = "100%";
  354. popUpHeight = "100%";
  355. setPopUpSize(popUpWidth, popUpHeight);
  356. resize = false;
  357. }
  358. //only resize if height and width not passed to popup frame
  359. if (resize) {
  360. resizePopUp();
  361. }
  362. }
  363. }
  364. function isLogonPage(popUpForm) {
  365. // look for : <input type="hidden" name="h_CAM_action" value="logonAs">
  366. if (popUpForm["h_CAM_action"]) {
  367. return popUpForm["h_CAM_action"].value.indexOf('logon')==0;
  368. }
  369. else {
  370. return false;
  371. }
  372. }
  373. function setPopUpSize(width, hight) {
  374. var span = parent.document.getElementById('popUpSpan');
  375. span.style.top = 0;
  376. span.style.left =0;
  377. span.style.width = width;
  378. span.style.height = hight;
  379. doShim(true);
  380. }
  381. function resizePopUp() {
  382. var popUpFrameElement = parent.document.getElementById('popUpFrame');
  383. var span = parent.document.getElementById('popUpSpan');
  384. var windowWidth = (!document.all)?window.innerWidth:document.body.clientWidth;
  385. var windowHeight = (!document.all)?window.innerHeight:document.body.clientHeight;
  386. var iMaxWidth = Math.round(windowWidth * 0.70);
  387. var iMaxHeight = Math.round(windowHeight * 0.90);
  388. var iWidth = 0;
  389. var iHeight = 0;
  390. //span.style values can not be used as they are treated as strings, and also
  391. //"px" will be added to the end of them
  392. var issW = 0;
  393. var issH = 0;
  394. var popUpFrame = getPopUpFrame();
  395. var popUpFrameContentDocument = getFrameDocument(popUpFrame);
  396. if (document.all) {
  397. iWidth = popUpFrameContentDocument.body.scrollWidth + 20;
  398. iHeight = popUpFrameContentDocument.body.scrollHeight + 15;
  399. } else {
  400. iWidth = popUpFrameContentDocument.body.offsetWidth + 50;
  401. iHeight = popUpFrameContentDocument.body.offsetHeight + 40;
  402. }
  403. //Defualt is 700X600 if the main window is smaller
  404. //than the popup we then use default values.
  405. if (iWidth < windowWidth) {
  406. iWidth = iWidth > iMaxWidth?iMaxWidth:iWidth;
  407. issW = iWidth;
  408. }
  409. else {
  410. issW = iMaxWidth;
  411. }
  412. //only set the left we are talking horizontaly
  413. if (issW < windowWidth) {
  414. span.style.left = (windowWidth - issW ) / 2;
  415. } else {
  416. span.style.left = 250;
  417. }
  418. if (iHeight < windowHeight) {
  419. iHeight = iHeight > iMaxHeight?iMaxHeight:iHeight;
  420. issH = iHeight;
  421. }
  422. else {
  423. issH = iMaxHeight;
  424. }
  425. //maintain an aspect ratio
  426. issH = (issH > (issW * 1.2)) ? issW * 1.2 : issH;
  427. //only set the top we are talking verticaly
  428. if (issH < windowHeight) {
  429. span.style.top = (windowHeight - issH) / 2;
  430. } else {
  431. span.style.top = 200;
  432. }
  433. span.style.width = issW + "px";
  434. span.style.height = issH + "px";
  435. if (document.all) {
  436. popUpFrameContentDocument.forms[0].style.width=issW-4;
  437. } else {
  438. popUpFrameContentDocument.body.style.width="100%";
  439. popUpFrameContentDocument.body.style.height="100%";
  440. }
  441. popUpFrameContentDocument.body.style.margin = "0";
  442. popUpFrameContentDocument.body.style.padding = "0";
  443. doShim(true);
  444. }
  445. // to enable the pop up div to float above selects
  446. //we must put a rabbish div beneath the span that surrounds our
  447. //proper iframe!
  448. function doShim(bShow){
  449. var popUpFrameShim = parent.document.getElementById('popUpShim');
  450. var span = parent.document.getElementById('popUpSpan');
  451. if(bShow){
  452. popUpFrameShim.style.top = span.style.top;
  453. popUpFrameShim.style.left = span.style.left;
  454. popUpFrameShim.style.height = span.offsetHeight;
  455. popUpFrameShim.style.width = span.offsetWidth;
  456. //popUpFrameShim.style.display = "block";
  457. //Need to pop over the splash screen so make sure zIndex is hig enough
  458. popUpFrameShim.style.zIndex=20100;
  459. }else{
  460. //popUpFrameShim.style.display = "none";
  461. popUpFrameShim.style.zIndex=-20100;
  462. }
  463. }