CSelectValueInputList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2016
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /*
  13. CSelectValueInputList.js
  14. This script is used to provide interactivity for the SelectValue check box
  15. and radio button prompt components.
  16. */
  17. //Constructor to create a checkboxlist component
  18. // oForm: the name of the form checkbox control
  19. // oSubmit: the form control to submit selections to the server
  20. // oImgTest: the image object used for validation handling
  21. // bRequired: a flag to determine whether input is required
  22. // sSubmitType: 'default' will submit as a standard form
  23. // 'XML' will convert the submission to XML and submit
  24. // oErrorFeedback: object used to provide validation feedback
  25. // iItemCount: the total number of items in the input list
  26. // iSelectedCount: the number of selected items in the input list
  27. // bDisabled: the control has been disabled [true|false]
  28. // sAutoSubmitType: specify whether the autosubmit should stay on the same page (reprompt)
  29. // or move to the next prompt page (prompt)
  30. // ['prompt'|'reprompt']
  31. // sRef: the name of the javascript variable for this object
  32. // bAutoSubmit:
  33. // sType:
  34. // sName:
  35. // sParameterName: the name of the prompt parameter
  36. //
  37. // Global variables
  38. var goSelectValueResizeHeightList = {};
  39. var goSelectValueResizeHeightTimer = null;
  40. function CSelectValueInputList(sFormName, sFormElements, oSubmit, oImgTest, bRequired, sSubmitType, oErrorFeedback, iItemCount, iSelectedCount, bDisabled, sAutoSubmitType, sRef, bAutoSubmit, sType, sName, sParameterName, sCVId)
  41. {
  42. this.setCVId(sCVId);
  43. this.m_sRef = sRef;
  44. this.m_sParameterName = sParameterName;
  45. this.m_sFormName = sFormName;
  46. this.m_sFormElements = sFormElements;
  47. this.m_oSubmit = oSubmit;
  48. this.m_sName = sName;
  49. this.m_oSelectElt = document.getElementById("selectList" + sRef);
  50. this.m_bRequired = bRequired;
  51. this.m_bAutoSubmit = bAutoSubmit;
  52. this.m_sType = sType;
  53. this.m_bValid = false;
  54. this.m_sSubmitType = sSubmitType;
  55. this.m_iItemCount = iItemCount;
  56. this.m_iSelectedCount = iSelectedCount;
  57. if (bDisabled)
  58. {
  59. this.m_bDisabled = true;
  60. }
  61. else
  62. {
  63. this.m_bDisabled = false;
  64. }
  65. this.m_sAutoSubmitType = (sAutoSubmitType == K_ACTION_REPROMPT ? K_ACTION_REPROMPT : K_ACTION_PROMPT);
  66. this.m_oErrorFeedback = oErrorFeedback;
  67. //skin folder
  68. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  69. //images for handling errors
  70. this.m_oImgCheck = oImgTest;
  71. if (this.m_oImgCheck != null)
  72. {
  73. this.m_oImgErrorFalse= new Image();
  74. this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  75. this.m_oImgErrorTrue = new Image();
  76. this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  77. }
  78. this.listHTML = new StringArray();
  79. this.checkData();
  80. }
  81. CSelectValueInputList.prototype = new CPromptControl();
  82. //add an item to the list without any checking by the control
  83. //this method provides an efficient way to add items, but
  84. //the update() method should be called to clean up the control
  85. //when finished adding
  86. function CSelectValueInputList_addNoUpdate(sText, sValue, bSelected, sParentDetail)
  87. {
  88. var sStyle = K_PRMT_sEMPTY;
  89. if (this.m_oSelectElt != null)
  90. {
  91. if (window.ie) {
  92. sStyle = this.m_oSelectElt.style.cssText;
  93. }
  94. else {
  95. sStyle = this.m_oSelectElt.getAttribute("style");
  96. }
  97. // Array of Style Attributes To Remove
  98. var aSatr = [
  99. "display", "visibility", "zIndex", "position", "clip", "float",
  100. "top", "bottom", "left", "right", "height", "width",
  101. "(margin|padding)(-left)*(-right)*(-top)*(-bottom)*",
  102. "border(-left|-right|-top|-bottom)*(-style|-width|-color|-spacing|-collapse)*",
  103. "(pos|pixel)(Top)*(Bottom)*(Left)*(Right)*(Height)*(Width)*"
  104. ];
  105. for (var i = 0; i < aSatr.length; ++i)
  106. {
  107. var re = new RegExp("(^|;)+\\s*" + aSatr[i] + "\\s*:[^;]*", K_PRMT_sGI);
  108. sStyle = sStyle.replace(re, K_PRMT_sEMPTY);
  109. }
  110. // remove starting semi-colons
  111. sStyle = sStyle.replace(/^\s*(;\s*)+/gi, K_PRMT_sEMPTY);
  112. }
  113. sText = sDecodeU003( sText );
  114. if (this.m_sSubmitType == K_PRMT_sXML) {
  115. this.listHTML.append("<input type='hidden' name='" + this.m_sFormElements + "Text" + this.m_iItemCount + "' value=\"" + sQuotEncode( sText ) + "\"/>");
  116. }
  117. this.listHTML.append('<div class="clsCheckBox"'+ (sStyle!=K_PRMT_sEMPTY? ' style="'+sStyle+'"' : K_PRMT_sEMPTY) +'><nobr>');
  118. sValue = sDecodeU003( sValue );
  119. this.listHTML.append("<label><input name='" + this.m_sFormElements + "' type='" + this.m_sType + "' value=\"" + sQuotEncode( sValue ) + "\" align='middle' style='vertical-align:middle' ");
  120. this.listHTML.append("onClick='" + this.m_sName + ".updateSelected(this.checked);" + this.m_sName + ".checkData();");
  121. if (this.m_bAutoSubmit) {
  122. this.listHTML.append(this.m_sName + ".autoSubmit();");
  123. }
  124. this.listHTML.append("' ");
  125. if (this.m_bDisabled) {
  126. this.listHTML.append("disabled='disabled' ");
  127. }
  128. if (bSelected)
  129. {
  130. this.listHTML.append("checked='checked'");
  131. this.m_iSelectedCount++;
  132. }
  133. this.listHTML.append(">");
  134. this.listHTML.append( sQuotEncode( sHtmlEncode(sText) ).replace(/\s/g, "&#160;") + "</input></label>" );
  135. if (typeof sParentDetail == K_PRMT_sSTRING) {
  136. this.listHTML.append("<span class='clsParentDetail'> ");
  137. var reOne = new RegExp( "\\^1", K_PRMT_sG);
  138. this.listHTML.append(PMT_UIM_PARENTDETAILS.replace(reOne,sParentDetail));
  139. this.listHTML.append("</span>");
  140. }
  141. this.listHTML.append("</nobr></div>");
  142. this.m_iItemCount++;
  143. }
  144. function CSelectValueInputList_update()
  145. {
  146. this.m_oSelectElt.innerHTML = this.listHTML.toString();
  147. this.m_oForm = eval("document.forms['" + this.m_sFormName + "'].elements['" + this.m_sFormElements + "'];");
  148. var bottomRowTR = document.getElementById("selectListBottomRow" + this.m_sRef);
  149. if (bottomRowTR != null)
  150. {
  151. if (this.m_iItemCount == 1)
  152. {
  153. bottomRowTR.style.display = "none";
  154. }
  155. else
  156. {
  157. bottomRowTR.removeAttribute("style");
  158. }
  159. }
  160. var selectListDIV = document.getElementById("selectList" + this.m_sRef);
  161. if (selectListDIV != null)
  162. {
  163. if (this.m_iItemCount == 1)
  164. {
  165. selectListDIV.className = K_PRMT_sEMPTY;
  166. }
  167. else
  168. {
  169. selectListDIV.className = selectListDIV.getAttribute("oldclass");
  170. }
  171. }
  172. this.checkData();
  173. CPromptControl_updateSelectWidth( document.getElementById("selectList" + this.m_sRef) );
  174. CSelectValueInputList_updateHeight( document.getElementById("selectList" + this.m_sRef) );
  175. }
  176. function CSelectValueInputList_updateHeight( oSelect )
  177. {
  178. if ( typeof goSelectValueResizeHeightList == K_PRMT_sUNDEFINED )
  179. {
  180. goSelectValueResizeHeightList = {};
  181. }
  182. if ( oSelect && !oSelect.id && oSelect.name)
  183. {
  184. oSelect.id = oSelect.name;
  185. }
  186. if ( oSelect && !goSelectValueResizeHeightList[ oSelect.id ] )
  187. {
  188. oSelect.m_sOriginalHeight = oSelect.style.height;
  189. goSelectValueResizeHeightList[ oSelect.id ] = oSelect;
  190. }
  191. if (document.readyState == "complete")
  192. {
  193. for (var sId in goSelectValueResizeHeightList)
  194. {
  195. var oTemp = goSelectValueResizeHeightList[ sId ];
  196. if ( oTemp && typeof oTemp.style && !CSelectValueInputList_hasExplicitHeight( oTemp ) )
  197. {
  198. // Setting the height to "auto" will resize the box
  199. oTemp.style.height = "auto";
  200. if (oTemp.offsetHeight > 165)
  201. {
  202. oTemp.style.height = "165px";
  203. }
  204. }
  205. }
  206. }
  207. else if ( document.readyState )
  208. {
  209. // IE is still loading the page.
  210. if ( goSelectValueResizeHeightTimer )
  211. {
  212. clearTimeout( goSelectValueResizeHeightTimer );
  213. }
  214. goSelectValueResizeHeightTimer = setTimeout(CSelectValueInputList_updateHeight, 100);
  215. }
  216. else
  217. {
  218. // Firefox, Mozilla
  219. if ( !CSelectValueInputList_hasExplicitHeight( oSelect ) )
  220. {
  221. oSelect.style.height = "auto";
  222. oSelect.style.maxHeight = "165px";
  223. }
  224. }
  225. }
  226. function CSelectValueInputList_hasExplicitHeight( oHTMLElement )
  227. {
  228. var sHeight = null;
  229. if (oHTMLElement)
  230. {
  231. sHeight = oHTMLElement.m_sOriginalHeight;
  232. if ( typeof sHeight == K_PRMT_sUNDEFINED )
  233. {
  234. sHeight = oHTMLElement.style.height;
  235. }
  236. }
  237. // Only update if the height was previously set and it's not 'auto'
  238. return ( sHeight && sHeight.match(/\d/g) );
  239. }
  240. //select all check box items
  241. function CSelectValueInputList_selectAll()
  242. {
  243. if (this.m_bDisabled != true)
  244. {
  245. if (typeof this.m_oForm != K_PRMT_sUNDEFINED)
  246. {
  247. var i=0;
  248. for (i=0; i < this.m_oForm.length; i++)
  249. {
  250. this.m_oForm[i].checked = true;
  251. }
  252. this.m_iSelectedCount = this.m_iItemCount;
  253. this.checkData();
  254. }
  255. }
  256. }
  257. //remove selection from all check box items
  258. function CSelectValueInputList_deSelectAll()
  259. {
  260. if (this.m_bDisabled != true)
  261. {
  262. if (typeof this.m_oForm != K_PRMT_sUNDEFINED)
  263. {
  264. var i=0;
  265. for (i=0; i < this.m_oForm.length; i++)
  266. {
  267. this.m_oForm[i].checked = false;
  268. }
  269. this.m_iSelectedCount = 0;
  270. this.checkData();
  271. }
  272. }
  273. }
  274. //render the validated state
  275. function CSelectValueInputList_checkPass()
  276. {
  277. if ((this.m_oImgCheck != null) && (this.m_oImgCheck.src != this.m_oImgErrorFalse.src))
  278. {
  279. this.m_oImgCheck.src = this.m_oImgErrorFalse.src;
  280. }
  281. if (this.m_oErrorFeedback)
  282. {
  283. this.m_oErrorFeedback.className ="clsFeedbackWidget";
  284. }
  285. this.notify(gPASS, this);
  286. }
  287. //render the validation error state
  288. function CSelectValueInputList_checkFail()
  289. {
  290. if (this.m_oImgCheck != null)
  291. {
  292. this.m_oImgCheck.src = this.m_oImgErrorTrue.src + '?' + Math.random();
  293. }
  294. if (this.m_oErrorFeedback)
  295. {
  296. this.m_oErrorFeedback.className ="clsFeedbackWidgetParseErrorArrowLeft";
  297. }
  298. this.notify(gFAIL, this);
  299. }
  300. function CSelectValueInputList_updateSelected(bSelected)
  301. {
  302. if (bSelected == true)
  303. {
  304. this.m_iSelectedCount += 1;
  305. if (this.m_iSelectedCount > this.m_iItemCount) {
  306. this.m_iSelectedCount = this.m_iItemCount;
  307. }
  308. }
  309. else
  310. {
  311. this.m_iSelectedCount -= 1;
  312. if (this.m_iSelectedCount < 0) {
  313. this.m_iSelectedCount = 0;
  314. }
  315. }
  316. }
  317. //validate the input into the control
  318. function CSelectValueInputList_checkData()
  319. {
  320. //check to see if any of the items are selected
  321. if (this.m_bRequired && this.m_iSelectedCount === 0)
  322. {
  323. this.m_bValid = false;
  324. this.checkFail();
  325. return false;
  326. }
  327. else
  328. {
  329. this.m_bValid = true;
  330. this.checkPass();
  331. return true;
  332. }
  333. }
  334. function CSelectValueInputList_preProcess()
  335. {
  336. if (this.m_sSubmitType == K_PRMT_sXML)
  337. {
  338. var sURLValues = K_PRMT_sEMPTY;
  339. if (this.m_oForm)
  340. {
  341. var sTextElement = K_PRMT_sEMPTY;
  342. var oTextElement = null;
  343. var sTextValue = K_PRMT_sEMPTY;
  344. if (this.m_oForm.length > 0)
  345. {
  346. for(var i = 0; i < this.m_oForm.length; i ++)
  347. {
  348. if (this.m_oForm[i].checked)
  349. {
  350. sTextElement = "document." + this.m_oForm[i].form.name + K_PRMT_sDOT + this.m_oForm[i].name + "Text" + i;
  351. oTextElement = eval(sTextElement);
  352. if (oTextElement != null)
  353. {
  354. sTextValue = oTextElement.value;
  355. sURLValues += '<selectOption';
  356. sURLValues += ' displayValue="' + sXmlEncode(sTextValue) +'"';
  357. sURLValues += ' useValue="' + sXmlEncode(this.m_oForm[i].value) + '"';
  358. sURLValues += ' selected="true" />';
  359. }
  360. if (this.m_sType == "radio")
  361. {
  362. this.m_oSubmit.value = K_PRMT_sEMPTY;
  363. break;
  364. }
  365. }
  366. }
  367. }
  368. else if (this.m_oForm.checked)
  369. {
  370. sTextElement = "document." + this.m_oForm.form.name + K_PRMT_sDOT + this.m_oForm.name + "Text0";
  371. oTextElement = eval(sTextElement);
  372. sTextValue = oTextElement.value;
  373. sURLValues += '<selectOption';
  374. sURLValues += ' displayValue="' + sXmlEncode(sTextValue) +'"';
  375. sURLValues += ' useValue="' + sXmlEncode(this.m_oForm.value) + '"';
  376. sURLValues += ' selected="true" />';
  377. }
  378. }
  379. addSelectChoices(this.m_oSubmit, sURLValues);
  380. }
  381. }
  382. //update the control, then submit the page
  383. //submit the page
  384. function CSelectValueInputList_autoSubmit()
  385. {
  386. this.checkData();
  387. if (!this.m_bRequired || this.m_bValid)
  388. {
  389. var oCV = this.getCV();
  390. if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION){
  391. var oReq = new ViewerDispatcherEntry(oCV);
  392. oReq.addFormField("ui.action", K_ACTION_FORWARD);
  393. oReq.addFormField("_autosubmitParameter", this.m_sParameterName);
  394. oReq.addFormField("_promptControl", this.m_sAutoSubmitType);
  395. oCV.submitPromptValues(oReq);
  396. }
  397. else
  398. {
  399. SetPromptMethod(K_ACTION_FORWARD);
  400. if (document.forms[0]._autosubmitParameter) {
  401. document.forms[0]._autosubmitParameter.value = this.m_sParameterName;
  402. }
  403. SetPromptControl(this.m_sAutoSubmitType);
  404. }
  405. }
  406. }
  407. // Show/Hide parent details
  408. // Set CSS class clsParentDetail's display attribute to 'inline' or 'none'
  409. function CSelectValueInputList_showParentDetails(bShow)
  410. {
  411. var cssClass = null;
  412. var c = "clsParentDetail";
  413. for (var i = 0; i < document.styleSheets.length; i++)
  414. {
  415. var ss = document.styleSheets[i];
  416. var aCSSRules = (ss.cssRules ? ss.cssRules : ss.rules);
  417. for (var j = 0; j < aCSSRules.length; j++)
  418. {
  419. var cr = aCSSRules[j];
  420. var reClass = new RegExp('\\b' + c + '\\b', K_PRMT_sG);
  421. if (cr.selectorText && cr.selectorText.match(reClass)) {
  422. cssClass = cr;
  423. }
  424. }
  425. }
  426. if (cssClass != null) {
  427. cssClass.style['display'] = (bShow ? 'inline' : 'none');
  428. }
  429. var link = document.getElementById('showParentLink' + this.m_sRef);
  430. if (link)
  431. {
  432. link.href = "javascript:" + this.m_sName + ".showParentDetails(" + (bShow ? "false" : "true") + ")";
  433. var textNode = link;
  434. while(textNode.firstChild != null) {
  435. textNode = textNode.firstChild;
  436. }
  437. textNode.nodeValue = (bShow ? PMT_UIM_HIDEPARENTDETAILS : PMT_UIM_SHOWPARENTDETAILS);
  438. }
  439. CPromptControl_updateSelectWidth( document.getElementById("selectList" + this.m_sRef) );
  440. }
  441. //Prototypes to assign methods to new instances of the object
  442. CSelectValueInputList.prototype.addNoUpdate = CSelectValueInputList_addNoUpdate;
  443. CSelectValueInputList.prototype.update = CSelectValueInputList_update;
  444. CSelectValueInputList.prototype.selectAll = CSelectValueInputList_selectAll;
  445. CSelectValueInputList.prototype.deSelectAll = CSelectValueInputList_deSelectAll;
  446. CSelectValueInputList.prototype.preProcess = CSelectValueInputList_preProcess;
  447. CSelectValueInputList.prototype.checkData = CSelectValueInputList_checkData;
  448. CSelectValueInputList.prototype.checkPass = CSelectValueInputList_checkPass;
  449. CSelectValueInputList.prototype.checkFail = CSelectValueInputList_checkFail;
  450. CSelectValueInputList.prototype.updateSelected = CSelectValueInputList_updateSelected;
  451. CSelectValueInputList.prototype.autoSubmit = CSelectValueInputList_autoSubmit;
  452. CSelectValueInputList.prototype.showParentDetails = CSelectValueInputList_showParentDetails;