CPromptButton.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *|
  6. *| US Government Users Restricted Rights - Use, duplication or
  7. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. *|
  9. *+------------------------------------------------------------------------+
  10. */
  11. /*
  12. CPromptButton.js
  13. This script defines the prompt button object
  14. */
  15. //Constructor to create a button component
  16. // oParent: the button element
  17. // sType: the type of button (e.g. OK, Cancel, Back, Next, Finish, Reprompt)
  18. // bEnabled: the initial state of the button (true/false)
  19. function CPromptButton(oParent, iType, bEnabled, sCVId)
  20. {
  21. this.setCVId(sCVId);
  22. this.m_oParent = oParent;
  23. this.m_iType = iType;
  24. this.m_bEnabled = bEnabled;
  25. this.draw();
  26. }
  27. CPromptButton.prototype = new CPromptControl();
  28. //return the type of button
  29. function CPromptButton_getType()
  30. {
  31. return this.m_iType;
  32. }
  33. //change the state of the button
  34. function CPromptButton_setEnabled(bEnabled)
  35. {
  36. this.m_bEnabled = bEnabled;
  37. this.draw();
  38. }
  39. //draw the button in its current state
  40. function CPromptButton_draw()
  41. {
  42. if (typeof this.m_oParent.disabled != K_PRMT_sUNDEFINED)
  43. {
  44. if (this.m_bEnabled == false)
  45. {
  46. this.m_oParent.disabled = true;
  47. PRMTUtils.f_removeClass( this.m_oParent, "bph" );
  48. PRMTUtils.f_addClass( this.m_oParent, "bpd" );
  49. }
  50. else
  51. {
  52. this.m_oParent.disabled = false;
  53. PRMTUtils.f_removeClass( this.m_oParent, "bpd" );
  54. }
  55. // defect 185307; don't need mouseover and mouseout for disabled button
  56. // save generated mouseover and mouseout function in xslt file
  57. this.m_fParentMouseover = this.m_oParent.onmouseover;
  58. this.m_fParentMouseout = this.m_oParent.onmouseout;
  59. if (this.m_oParent.disabled)
  60. {
  61. this.m_oParent.onmouseover = null;
  62. this.m_oParent.onmouseout = null;
  63. }
  64. else
  65. {
  66. this.m_oParent.onmouseover = this.m_fParentMouseover;
  67. this.m_oParent.onmouseout = this.m_fParentMouseout;
  68. }
  69. }
  70. }
  71. //Prototypes to assign methods to new instances of the object
  72. CPromptButton.prototype.getType = CPromptButton_getType;
  73. CPromptButton.prototype.setEnabled = CPromptButton_setEnabled;
  74. CPromptButton.prototype.draw = CPromptButton_draw;
  75. //handle the cancel event, get the back URL from the page if it is available
  76. //perform a browser back if nothing else can be found
  77. function promptButtonCancel(s)
  78. {
  79. //detect for the existance of a predefined cancel
  80. //function in the page (e.g. RV or Cognos Connection page)
  81. //if it exists, call it
  82. if (typeof cancel != K_PRMT_sUNDEFINED)
  83. {
  84. cancel();
  85. return;
  86. }
  87. if ( f_CSW_tryCVPromptAction('cancel',s) )
  88. {
  89. return;
  90. }
  91. var sBackURL = s;
  92. if (sBackURL == K_PRMT_sEMPTY)
  93. {
  94. //close the window if RV does not have
  95. //a backURL
  96. //this function is part of RV
  97. if (typeof getConfigFrame != K_PRMT_sUNDEFINED)
  98. {
  99. var tf = getConfigFrame();
  100. if (tf)
  101. {
  102. var sApp = tf.applicationName;
  103. if ((sApp == "QS") && (typeof tf.cancelPromptPage != K_PRMT_sUNDEFINED)) {
  104. tf.cancelPromptPage();
  105. return;
  106. }
  107. else {
  108. sBackURL = tf.frameBackURL;
  109. if ((sBackURL==null) || (sBackURL==K_PRMT_sEMPTY))
  110. {
  111. tf.close();
  112. }
  113. else
  114. {
  115. tf.location = sBackURL;
  116. }
  117. }
  118. }
  119. }
  120. //check the form for a back URL
  121. if (typeof document.forms["formWarpRequest"] != K_PRMT_sUNDEFINED)
  122. {
  123. var elemBackUrl = document.forms["formWarpRequest"].elements["ui.backURL"];
  124. if ((typeof elemBackUrl != K_PRMT_sUNDEFINED) && (elemBackUrl.value != K_PRMT_sEMPTY))
  125. {
  126. sBackURL = elemBackUrl.value;
  127. }
  128. }
  129. }
  130. if (sBackURL == K_PRMT_sEMPTY)
  131. {
  132. self.history.back();
  133. }
  134. else
  135. {
  136. self.location = sBackURL;
  137. }
  138. }
  139. //set the action method to go back
  140. //method=back
  141. function promptButtonBack()
  142. {
  143. if ( f_CSW_tryCVPromptAction('back') )
  144. {
  145. return;
  146. }
  147. SetPromptContinue('true');
  148. SetPromptMethod(K_ACTION_BACK);
  149. SetPromptControl(K_ACTION_PROMPT);
  150. }
  151. //set the action method to go next
  152. //method=forward
  153. function promptButtonNext()
  154. {
  155. if ( f_CSW_tryCVPromptAction('next') )
  156. {
  157. return;
  158. }
  159. SetPromptContinue('true');
  160. SetPromptMethod(K_ACTION_FORWARD);
  161. SetPromptControl(K_ACTION_PROMPT);
  162. }
  163. //run the report
  164. //method=forward
  165. //prevent further prompt pages
  166. function promptButtonFinish()
  167. {
  168. if ( f_CSW_tryCVPromptAction('finish') )
  169. {
  170. return;
  171. }
  172. SetPromptContinue('false');
  173. SetPromptMethod(K_ACTION_FORWARD);
  174. SetPromptControl(K_ACTION_PROMPT);
  175. }
  176. //submit the dialog
  177. //allow other prompts to show up depending on the user setting for 'prompt'
  178. //method=forward
  179. function promptButtonOK()
  180. {
  181. if ( f_CSW_tryCVPromptAction('ok') )
  182. {
  183. return;
  184. }
  185. SetPromptMethod(K_ACTION_FORWARD);
  186. SetPromptControl(K_ACTION_PROMPT);
  187. }
  188. function promptAction(sAction, sArg)
  189. {
  190. if ( f_CSW_tryCVPromptAction(sAction, sArg) || f_getPromptRequestSubmitFlag() )
  191. {
  192. return false;
  193. }
  194. switch(sAction)
  195. {
  196. case K_ACTION_BACK:
  197. promptButtonBack();
  198. break;
  199. case K_ACTION_CANCEL:
  200. promptButtonCancel(sArg);
  201. break;
  202. case K_ACTION_NEXT:
  203. promptButtonNext();
  204. break;
  205. case K_ACTION_FINISH:
  206. promptButtonFinish();
  207. break;
  208. case K_ACTION_REPROMPT:
  209. SetPromptControl(sAction);
  210. break;
  211. default:
  212. promptButtonOK();
  213. }
  214. f_setPromptRequestSubmitFlag(true);
  215. }
  216. //this function can be called to notify
  217. //any controls that want to observe the
  218. //state of page navigation
  219. function promptButtonNotify()
  220. {
  221. if (typeof bVerifyPageNavigation != K_PRMT_sUNDEFINED)
  222. {
  223. var bCheckNavigation = bVerifyPageNavigation();
  224. notifyPageNavEnabled(bCheckNavigation);
  225. }
  226. }
  227. //this function will check to see if all controls are
  228. //ready for navigation to the next page
  229. function bVerifyPageNavigation()
  230. {
  231. var bFormValid = true;
  232. if ( typeof preProcessControlArray == K_PRMT_sOBJECT )
  233. {
  234. var kCount = preProcessControlArray.length;
  235. var k = 0;
  236. for (k=0; k<kCount; k++)
  237. {
  238. var promptElement = eval(preProcessControlArray[k]);
  239. if ((typeof promptElement.getValid == K_PRMT_sFUNCTION) && !promptElement.getValid())
  240. {
  241. bFormValid = false;
  242. break;
  243. }
  244. }
  245. }
  246. return bFormValid;
  247. }
  248. //iterate through all page navigation observers
  249. //and set their states based on element type
  250. function notifyPageNavEnabled(bEnabled)
  251. {
  252. //broadcast to observers
  253. if ( typeof pageNavigationObserverArray == K_PRMT_sOBJECT )
  254. {
  255. var kCount = pageNavigationObserverArray.length;
  256. //determine if there is a finish button on the page, if so we'll disable the next.
  257. var bFinishPresent = false;
  258. var promptElement = null;
  259. var promptElementType = null;
  260. for (var j=0; j<kCount; j++)
  261. {
  262. promptElement = eval(pageNavigationObserverArray[j]);
  263. promptElementType = promptElement.getType();
  264. if (promptElementType == PROMPTBUTTON_FINISH)
  265. {
  266. bFinishPresent = true;
  267. break;
  268. }
  269. }
  270. for (var k=0; k<kCount; k++)
  271. {
  272. promptElement = eval(pageNavigationObserverArray[k]);
  273. promptElementType = promptElement.getType();
  274. if (bEnabled == false)
  275. {
  276. if ((promptElementType == PROMPTBUTTON_NEXT) || (promptElementType == PROMPTBUTTON_OK) || (promptElementType == PROMPTBUTTON_FINISH))
  277. {
  278. promptElement.setEnabled(false);
  279. }
  280. }
  281. else
  282. {
  283. if (promptElementType == PROMPTBUTTON_FINISH)
  284. {
  285. if (bCanFinish == true)
  286. {
  287. promptElement.setEnabled(true);
  288. }
  289. else
  290. {
  291. promptElement.setEnabled(false);
  292. }
  293. }
  294. else if (promptElementType == PROMPTBUTTON_NEXT)
  295. {
  296. if ((bNextPage == false) && (bFinishPresent == true))
  297. {
  298. promptElement.setEnabled(false);
  299. }
  300. else
  301. {
  302. promptElement.setEnabled(true);
  303. }
  304. }
  305. else if (promptElementType == PROMPTBUTTON_OK)
  306. {
  307. promptElement.setEnabled(true);
  308. }
  309. }
  310. }
  311. }
  312. }
  313. //constants
  314. var PROMPTBUTTON_OK = 0;
  315. var PROMPTBUTTON_CANCEL = 1;
  316. var PROMPTBUTTON_BACK = 2;
  317. var PROMPTBUTTON_NEXT = 3;
  318. var PROMPTBUTTON_FINISH = 4;
  319. var PROMPTBUTTON_REPROMPT = 5;