CMultipleIntervalPicker.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2011
  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. CMultipleIntervalPicker.js
  14. This script is used to provide interactivity for the
  15. multiple select selectInterval prompt component. This component is
  16. a combination of the interval picker and a list box.
  17. */
  18. //Constructor to create a checkboxlist component
  19. // oIntervalPicker: the interval picker control
  20. // oLstChoices: the name of the select form control
  21. // oSubmit: the form control to submit selections to the server
  22. // bRequired: is this a required field true/false
  23. // sSubmitType: submit this as a standard form, or as XML
  24. // oErrorFeedback: object used to provide validation feedback
  25. // oSizer: image object used to control the minimum size of the list
  26. // oInsertButton: the insert button
  27. // oRemoveButton: the remove button
  28. function CMultipleIntervalPicker(oIntervalPicker, oLstChoices, oSubmit, bRequired, sSubmitType, oErrorFeedback, oSizer, oInsertButton, oRemoveButton, sCVId)
  29. {
  30. this.setCVId(sCVId);
  31. this.m_oIntervalPicker = oIntervalPicker;
  32. this.m_oLstChoices = oLstChoices;
  33. this.m_oSubmit = oSubmit;
  34. this.m_bRequired = bRequired;
  35. this.m_bValid = false;
  36. this.m_sSubmitType = sSubmitType;
  37. this.m_oErrorFeedback = oErrorFeedback;
  38. if (oInsertButton)
  39. {
  40. this.m_oInsertButton = oInsertButton;
  41. }
  42. if (oRemoveButton)
  43. {
  44. this.m_oRemoveButton = oRemoveButton;
  45. }
  46. this.checkData();
  47. //resize the list if necessary
  48. if(oSizer)
  49. {
  50. this.m_oSizer = oSizer;
  51. this.resizeList();
  52. }
  53. //check the states of the insert and remove buttons
  54. this.checkInsertRemove();
  55. }
  56. CMultipleIntervalPicker.prototype = new CPromptControl();
  57. //add an item to the list without any checking by the control
  58. //this method provides an efficient way to add items, but
  59. //the update() method should be called to clean up the control
  60. //when finished adding
  61. function CMultipleIntervalPicker_addNoUpdate(sDisplayValue, sInsertText, sel)
  62. {
  63. sDisplayValue = sDecodeU003( sDisplayValue );
  64. sInsertText = sDecodeU003( sInsertText );
  65. if (sel == true) {
  66. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, true, true);
  67. }
  68. else {
  69. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, false, false);
  70. }
  71. }
  72. //clean up the control
  73. function CMultipleIntervalPicker_update()
  74. {
  75. this.checkData();
  76. this.resizeList();
  77. this.resizeList();
  78. //check the states of the insert and remove buttons
  79. this.checkInsertRemove();
  80. }
  81. //select all items
  82. function CMultipleIntervalPicker_selectAll()
  83. {
  84. for (var i=0; i < this.m_oLstChoices.options.length; i++)
  85. {
  86. this.m_oLstChoices.options[i].selected = true;
  87. }
  88. this.checkData();
  89. //check the states of the insert and remove buttons
  90. this.checkInsertRemove();
  91. }
  92. //remove selection from all items
  93. function CMultipleIntervalPicker_deSelectAll()
  94. {
  95. for (var i=0; i < this.m_oLstChoices.options.length; i++)
  96. {
  97. this.m_oLstChoices.options[i].selected = false;
  98. }
  99. this.checkData();
  100. //check the states of the insert and remove buttons
  101. this.checkInsertRemove();
  102. }
  103. //insert values from the picker control
  104. function CMultipleIntervalPicker_insert()
  105. {
  106. var sInsertInterval = this.m_oIntervalPicker.sGetInterval();
  107. var sInsertFormatInterval = this.m_oIntervalPicker.sGetFormatInterval();
  108. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sInsertFormatInterval, sInsertInterval, false, false);
  109. this.checkData();
  110. this.resizeList();
  111. this.resizeList();
  112. }
  113. //remove selections from the list of choices
  114. function CMultipleIntervalPicker_remove()
  115. {
  116. this.removeSelectedChoices();
  117. }
  118. //perform any special processing for the server.
  119. //this function will wrap all list items in XML.
  120. //This is required for cases where the unselected items need
  121. //to be submitted too.
  122. function CMultipleIntervalPicker_preProcess()
  123. {
  124. var i=0;
  125. if (this.m_sSubmitType == K_PRMT_sXML)
  126. {
  127. var sURLValues = K_PRMT_sEMPTY;
  128. if (this.m_oLstChoices.options.length > 0)
  129. {
  130. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  131. {
  132. sURLValues += '<selectOption';
  133. sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstChoices.options[i].text) +'"';
  134. sURLValues += ' useValue="' + sXmlEncode(this.m_oLstChoices.options[i].value) + '"';
  135. if (this.m_oLstChoices.options[i].selected == true)
  136. {
  137. sURLValues += ' selected="true" />';
  138. }
  139. else
  140. {
  141. sURLValues += ' selected="false" />';
  142. }
  143. }
  144. }
  145. addSelectChoices(this.m_oSubmit, sURLValues);
  146. }
  147. else
  148. {
  149. //select all the choices so they can be submitted with the form
  150. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  151. {
  152. this.m_oLstChoices.options[i].selected = true;
  153. }
  154. }
  155. }
  156. //return true unless this is a required prompt
  157. //and there are no values
  158. function CMultipleIntervalPicker_checkData()
  159. {
  160. if ((this.m_bRequired == true) && (this.m_oLstChoices.options.length === 0))
  161. {
  162. this.m_bValid = false;
  163. this.checkFail();
  164. return false;
  165. }
  166. else
  167. {
  168. this.m_bValid = true;
  169. this.checkPass();
  170. return true;
  171. }
  172. }
  173. //make sure that choices are always visible and set a minimum size
  174. //resize the list to fit the data if required
  175. //if there are no items, prevent the list from
  176. //shrinking too small
  177. //allow the list to expand to fit the biggest item
  178. function CMultipleIntervalPicker_resizeList()
  179. {
  180. if (this.m_oSizer)
  181. {
  182. this.m_oLstChoices.style.width='auto';
  183. if (this.m_oSizer.width < 200)
  184. {
  185. this.m_oLstChoices.style.width='200px';
  186. }
  187. }
  188. }
  189. //enable and disable the insert and remove buttons
  190. //based on what the user has selected
  191. function CMultipleIntervalPicker_checkInsertRemove()
  192. {
  193. if (this.m_oInsertButton)
  194. {
  195. if ((this.m_oIntervalPicker.getValid() == true) && this.m_oIntervalPicker.hasValue())
  196. {
  197. this.m_oInsertButton.disabled = false;
  198. }
  199. else
  200. {
  201. this.m_oInsertButton.disabled = true;
  202. this.m_oInsertButton.className = "clsInsertRemoveButton";
  203. }
  204. }
  205. if (this.m_oRemoveButton)
  206. {
  207. if (this.m_oLstChoices.selectedIndex == -1)
  208. {
  209. this.m_oRemoveButton.disabled = true;
  210. this.m_oRemoveButton.className = "clsInsertRemoveButton";
  211. }
  212. else
  213. {
  214. this.m_oRemoveButton.disabled = false;
  215. }
  216. }
  217. }
  218. CMultipleIntervalPicker.prototype.addNoUpdate = CMultipleIntervalPicker_addNoUpdate;
  219. CMultipleIntervalPicker.prototype.update = CMultipleIntervalPicker_update;
  220. CMultipleIntervalPicker.prototype.selectAll = CMultipleIntervalPicker_selectAll;
  221. CMultipleIntervalPicker.prototype.deSelectAll = CMultipleIntervalPicker_deSelectAll;
  222. CMultipleIntervalPicker.prototype.insert = CMultipleIntervalPicker_insert;
  223. CMultipleIntervalPicker.prototype.remove = CMultipleIntervalPicker_remove;
  224. CMultipleIntervalPicker.prototype.preProcess = CMultipleIntervalPicker_preProcess;
  225. CMultipleIntervalPicker.prototype.checkData = CMultipleIntervalPicker_checkData;
  226. CMultipleIntervalPicker.prototype.resizeList = CMultipleIntervalPicker_resizeList;
  227. CMultipleIntervalPicker.prototype.checkInsertRemove = CMultipleIntervalPicker_checkInsertRemove;