CSelectValueSelectList.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. CSelectValueSelectList.js
  14. This script is used to provide interactivity for the SelectValue single and
  15. multiple select prompt components.
  16. */
  17. //Constructor to create a checkboxlist component
  18. // oForm: the name of the form list box 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. // oSizer: image object used to control the minimum size of the list
  26. // bDisabled: the control has been disabled [true|false]
  27. // sAutoSubmitType: specify whether the autosubmit should stay on the same page (reprompt)
  28. // or move to the next prompt page (prompt)
  29. // ['prompt'|'reprompt']
  30. // sRef: the name of the javascript variable for this object
  31. // sParameterName: the name of the prompt parameter
  32. //
  33. function CSelectValueSelectList(oForm, oSubmit, oImgTest, bRequired, sSubmitType, oErrorFeedback, oSizer, bDisabled, sAutoSubmitType, sRef, sParameterName, sCVId)
  34. {
  35. this.setCVId(sCVId);
  36. this.m_oForm = oForm;
  37. this.m_oSubmit = oSubmit;
  38. this.m_bRequired = bRequired;
  39. this.m_bValid = false;
  40. this.m_sSubmitType = sSubmitType;
  41. this.m_sRef = sRef;
  42. this.m_sParameterName = sParameterName;
  43. this.m_oSelectElt = document.getElementById("selectList" + sRef);
  44. this.m_sAutoSubmitType = (sAutoSubmitType == K_ACTION_REPROMPT ? K_ACTION_REPROMPT : K_ACTION_PROMPT);
  45. //this variable is used to trap auto-submit
  46. //behavior in drop down lists
  47. this.m_bAutoSubmitTrigger = false;
  48. if (bDisabled)
  49. {
  50. this.m_bDisabled = true;
  51. }
  52. else
  53. {
  54. this.m_bDisabled = false;
  55. }
  56. this.m_oErrorFeedback = oErrorFeedback;
  57. //skin folder
  58. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  59. //images for handling errors
  60. this.m_oImgCheck = oImgTest;
  61. if (this.m_oImgCheck != null)
  62. {
  63. this.m_oImgErrorFalse= new Image();
  64. this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  65. this.m_oImgErrorTrue = new Image();
  66. this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  67. }
  68. this.checkData(oForm);
  69. //check to see if the user has hardcoded the size
  70. if (oForm.style && oForm.style.width != K_PRMT_sEMPTY)
  71. {
  72. oSizer = null;
  73. }
  74. this.oOptionsHTML = new StringArray();
  75. }
  76. CSelectValueSelectList.prototype = new CPromptControl();
  77. function CSelectValueSelectList_addNoUpdate(sDisplayValue, sInsertText, sel)
  78. {
  79. var sDisplay = sDecodeU003( sDisplayValue );
  80. var sUse = sDecodeU003( sInsertText );
  81. var bSelected = (sel == true);
  82. if (window.ie)
  83. {
  84. this.oOptionsHTML.append('<option value="' + sQuotEncode( sUse ) + '"' +(bSelected ? ' selected="selected"' : K_PRMT_sEMPTY) + ' displayValue="' + sQuotEncode( sDisplay ) + '">' + sHtmlEncode(sDisplay).replace(/\s/g, '&#160;') + '</option>');
  85. }
  86. else
  87. {
  88. var o = new Option(sDisplay, sUse, bSelected, bSelected);
  89. o.style.whiteSpace = "pre";
  90. this.m_oSelectElt.options[this.m_oSelectElt.options.length] = o;
  91. }
  92. }
  93. function CSelectValueSelectList_update()
  94. {
  95. if (window.ie)
  96. {
  97. var sId = this.m_oSelectElt.id;
  98. var bReplaceFormControl = ( this.m_oForm == this.m_oSelectElt );
  99. var sOuter = this.m_oSelectElt.outerHTML;
  100. this.m_oSelectElt.outerHTML = sOuter.replace(/<\/select.*/i, K_PRMT_sEMPTY) + this.oOptionsHTML.toString() + '<' + '/' + 'SELECT>';
  101. // need to refresh references to objects after using outerHTML.
  102. this.m_oSelectElt = document.getElementById(sId);
  103. if (bReplaceFormControl) {
  104. this.m_oForm = this.m_oSelectElt;
  105. }
  106. this.oOptionsHTML.reset();
  107. }
  108. this.checkData();
  109. CPromptControl_updateSelectWidth( document.getElementById("selectList" + this.m_sRef) );
  110. }
  111. //select all check box items
  112. function CSelectValueSelectList_selectAll()
  113. {
  114. if (this.m_bDisabled != true)
  115. {
  116. var i=0;
  117. for (i=0; i < this.m_oForm.options.length; i++)
  118. {
  119. this.m_oForm.options[i].selected = true;
  120. }
  121. this.checkData();
  122. }
  123. }
  124. //remove selection from all check box items
  125. function CSelectValueSelectList_deSelectAll()
  126. {
  127. if (this.m_bDisabled != true)
  128. {
  129. var i=0;
  130. for (i=0; i < this.m_oForm.options.length; i++)
  131. {
  132. this.m_oForm.options[i].selected = false;
  133. }
  134. this.checkData();
  135. }
  136. }
  137. //render the validated state
  138. function CSelectValueSelectList_checkPass()
  139. {
  140. if ((this.m_oImgCheck != null) && (this.m_oImgCheck.src != this.m_oImgErrorFalse.src))
  141. {
  142. this.m_oImgCheck.src = this.m_oImgErrorFalse.src;
  143. }
  144. if (this.m_oErrorFeedback)
  145. {
  146. this.m_oErrorFeedback.className ="clsFeedbackWidget";
  147. }
  148. this.notify(gPASS, this);
  149. }
  150. //render the validation error state
  151. function CSelectValueSelectList_checkFail()
  152. {
  153. if (this.m_oImgCheck != null)
  154. {
  155. this.m_oImgCheck.src = this.m_oImgErrorTrue.src + '?' + Math.random();
  156. }
  157. if (this.m_oErrorFeedback)
  158. {
  159. this.m_oErrorFeedback.className ="clsFeedbackWidgetParseErrorArrowLeft";
  160. }
  161. this.notify(gFAIL, this);
  162. }
  163. //validate the input into the control
  164. function CSelectValueSelectList_checkData()
  165. {
  166. //check to see if any of the items are selected
  167. var bCheckSelect = false;
  168. var i=0;
  169. for (i=0; i < this.m_oForm.options.length; i++)
  170. {
  171. if ((this.m_oForm.options[i].selected == true) && (this.m_oForm.options[i].value != K_PRMT_sEMPTY))
  172. {
  173. bCheckSelect = true;
  174. }
  175. }
  176. if ((this.m_bRequired == true) && (bCheckSelect == false))
  177. {
  178. this.m_bValid = false;
  179. this.checkFail();
  180. return false;
  181. }
  182. else
  183. {
  184. this.m_bValid = true;
  185. this.checkPass();
  186. return true;
  187. }
  188. }
  189. function CSelectValueSelectList_preProcess()
  190. {
  191. if (this.m_sSubmitType == K_PRMT_sXML)
  192. {
  193. var sURLValues = "";
  194. if (this.m_oForm.options.length > 0)
  195. {
  196. for(var i = 0; i < this.m_oForm.options.length; i ++)
  197. {
  198. if ((this.m_oForm.options[i].selected == true) && (this.m_oForm.options[i].value!=K_PRMT_sEMPTY))
  199. {
  200. var sDisplayValue = this.m_oForm.options[i].displayValue;
  201. if ( !sDisplayValue )
  202. {
  203. sDisplayValue = this.m_oForm.options[i].text;
  204. }
  205. sURLValues += '<selectOption';
  206. sURLValues += ' displayValue="' + sXmlEncode(sDisplayValue) +'"';
  207. sURLValues += ' useValue="' + sXmlEncode(this.m_oForm.options[i].value) + '"';
  208. sURLValues += ' selected="true" />';
  209. }
  210. }
  211. }
  212. else
  213. {
  214. sURLValues = "<selectChoices></selectChoices>";
  215. }
  216. addSelectChoices(this.m_oSubmit, sURLValues);
  217. }
  218. }
  219. //update the control, then submit the page
  220. //submit the page
  221. function CSelectValueSelectList_autoSubmit()
  222. {
  223. this.checkData();
  224. if (!this.m_bRequired || this.m_bValid)
  225. {
  226. var oCV = this.getCV();
  227. if (oCV && typeof oCV.submitPromptValues == K_PRMT_sFUNCTION && typeof ViewerDispatcherEntry == K_PRMT_sFUNCTION){
  228. var oReq = new ViewerDispatcherEntry(oCV);
  229. oReq.addFormField("ui.action", K_ACTION_FORWARD);
  230. oReq.addFormField("_autosubmitParameter", this.m_sParameterName);
  231. oReq.addFormField("_promptControl", this.m_sAutoSubmitType);
  232. oCV.submitPromptValues(oReq);
  233. }
  234. else
  235. {
  236. SetPromptMethod(K_ACTION_FORWARD);
  237. if (document.forms[0]._autosubmitParameter) {
  238. document.forms[0]._autosubmitParameter.value = this.m_sParameterName;
  239. }
  240. SetPromptControl(this.m_sAutoSubmitType);
  241. }
  242. }
  243. }
  244. //return a valid value from the selected index
  245. //use only with the single select version of the control
  246. function CSelectValueSelectList_sGetValue()
  247. {
  248. this.checkData();
  249. if ((this.m_bValid == true) && (this.m_oForm.options.length > 0) && (this.m_oForm.options.selectedIndex != -1))
  250. {
  251. return this.m_oForm.options[this.m_oForm.options.selectedIndex].value;
  252. }
  253. return false;
  254. }
  255. //return a valid value from the selected index
  256. //use only with the single select version of the control
  257. function CSelectValueSelectList_sGetFormatValue()
  258. {
  259. this.checkData();
  260. if ((this.m_bValid == true) && (this.m_oForm.options.length > 0) && (this.m_oForm.options.selectedIndex != -1))
  261. {
  262. return this.m_oForm.options[this.m_oForm.options.selectedIndex].text;
  263. }
  264. return false;
  265. }
  266. function CSelectValueSelectList_hasValue()
  267. {
  268. if (this.m_oForm.value == K_PRMT_sEMPTY)
  269. {
  270. return false;
  271. }
  272. return true;
  273. }
  274. //used to set the list to a particular use value if it exists
  275. //in the list.
  276. function CSelectValueSelectList_selectByUseValue(sUseValue)
  277. {
  278. for (var j=0; j < this.m_oForm.options.length; j++)
  279. {
  280. if (this.m_oForm.options[j].value == sUseValue)
  281. {
  282. this.m_oForm.options[j].selected = true;
  283. this.checkData(this.m_oForm);
  284. return;
  285. }
  286. }
  287. }
  288. //Prototypes to assign methods to new instances of the object
  289. CSelectValueSelectList.prototype.addNoUpdate = CSelectValueSelectList_addNoUpdate;
  290. CSelectValueSelectList.prototype.update = CSelectValueSelectList_update;
  291. CSelectValueSelectList.prototype.selectAll = CSelectValueSelectList_selectAll;
  292. CSelectValueSelectList.prototype.deSelectAll = CSelectValueSelectList_deSelectAll;
  293. CSelectValueSelectList.prototype.preProcess = CSelectValueSelectList_preProcess;
  294. CSelectValueSelectList.prototype.checkData = CSelectValueSelectList_checkData;
  295. CSelectValueSelectList.prototype.checkPass = CSelectValueSelectList_checkPass;
  296. CSelectValueSelectList.prototype.checkFail = CSelectValueSelectList_checkFail;
  297. CSelectValueSelectList.prototype.autoSubmit = CSelectValueSelectList_autoSubmit;
  298. CSelectValueSelectList.prototype.sGetValue = CSelectValueSelectList_sGetValue;
  299. CSelectValueSelectList.prototype.sGetFormatValue = CSelectValueSelectList_sGetFormatValue;
  300. CSelectValueSelectList.prototype.hasValue = CSelectValueSelectList_hasValue;
  301. CSelectValueSelectList.prototype.selectByUseValue = CSelectValueSelectList_selectByUseValue;