CMultipleTimePicker.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. CMultipleTextPicker.js
  14. This script is used to provide interactivity for the
  15. multiple select selectTime prompt component. This component is
  16. a combination of the time picker and a list box.
  17. */
  18. //Constructor to create a checkboxlist component
  19. // oTimePicker: the time 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 CMultipleTimePicker(oTimePicker, oLstChoices, oSubmit, bRequired, sSubmitType, oErrorFeedback, oSizer, oInsertButton, oRemoveButton, sCVId)
  29. {
  30. this.setCVId(sCVId);
  31. this.m_oTimePicker = oTimePicker;
  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. CMultipleTimePicker.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 CMultipleTimePicker_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 CMultipleTimePicker_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 CMultipleTimePicker_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. //check the states of the insert and remove buttons
  89. this.checkInsertRemove();
  90. }
  91. //remove selection from all items
  92. function CMultipleTimePicker_deSelectAll()
  93. {
  94. for (var i=0; i < this.m_oLstChoices.options.length; i++)
  95. {
  96. this.m_oLstChoices.options[i].selected = false;
  97. }
  98. //check the states of the insert and remove buttons
  99. this.checkInsertRemove();
  100. }
  101. //insert values from the picker control
  102. function CMultipleTimePicker_insert()
  103. {
  104. var sDisplayValue = this.m_oTimePicker.sGetFormatTime ();
  105. var sUseValue = this.m_oTimePicker.sGetSQLTime();
  106. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sUseValue, false, false);
  107. this.checkData();
  108. this.resizeList();
  109. this.resizeList();
  110. //check the states of the insert and remove buttons
  111. this.checkInsertRemove();
  112. }
  113. //remove selections from the list of choices
  114. function CMultipleTimePicker_remove()
  115. {
  116. this.removeSelectedChoices();
  117. //check the states of the insert and remove buttons
  118. this.checkInsertRemove();
  119. }
  120. //perform any special processing for the server.
  121. //this function will wrap all list items in XML.
  122. //This is required for cases where the unselected items need
  123. //to be submitted too.
  124. function CMultipleTimePicker_preProcess()
  125. {
  126. var i=0;
  127. if (this.m_sSubmitType == K_PRMT_sXML)
  128. {
  129. var sURLValues = K_PRMT_sEMPTY;
  130. if (this.m_oLstChoices.options.length > 0)
  131. {
  132. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  133. {
  134. sURLValues += '<selectOption';
  135. sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstChoices.options[i].text) +'"';
  136. sURLValues += ' useValue="' + sXmlEncode(this.m_oLstChoices.options[i].value) + '"';
  137. if (this.m_oLstChoices.options[i].selected == true)
  138. {
  139. sURLValues += ' selected="true" />';
  140. }
  141. else
  142. {
  143. sURLValues += ' selected="false" />';
  144. }
  145. }
  146. }
  147. addSelectChoices(this.m_oSubmit, sURLValues);
  148. }
  149. else
  150. {
  151. //select all the choices so they can be submitted with the form
  152. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  153. {
  154. this.m_oLstChoices.options[i].selected = true;
  155. }
  156. }
  157. }
  158. //return true unless this is a required prompt
  159. //and there are no values
  160. function CMultipleTimePicker_checkData()
  161. {
  162. if ((this.m_bRequired == true) && (this.m_oLstChoices.options.length === 0))
  163. {
  164. this.m_bValid = false;
  165. this.checkFail();
  166. return false;
  167. }
  168. else
  169. {
  170. this.m_bValid = true;
  171. this.checkPass();
  172. return true;
  173. }
  174. }
  175. //make sure that choices are always visible and set a minimum size
  176. //resize the list to fit the data if required
  177. //if there are no items, prevent the list from
  178. //shrinking too small
  179. //allow the list to expand to fit the biggest item
  180. function CMultipleTimePicker_resizeList()
  181. {
  182. if (this.m_oSizer)
  183. {
  184. this.m_oLstChoices.style.width='auto';
  185. if (this.m_oSizer.width < 200)
  186. {
  187. this.m_oLstChoices.style.width='200px';
  188. }
  189. }
  190. }
  191. //enable and disable the insert and remove buttons
  192. //based on what the user has selected
  193. function CMultipleTimePicker_checkInsertRemove()
  194. {
  195. if (this.m_oInsertButton)
  196. {
  197. if ((this.m_oTimePicker.getValid() == true) && (this.m_oTimePicker.hasValue()))
  198. {
  199. this.m_oInsertButton.disabled = false;
  200. }
  201. else
  202. {
  203. this.m_oInsertButton.disabled = true;
  204. this.m_oInsertButton.className = "clsInsertRemoveButton";
  205. }
  206. }
  207. if (this.m_oRemoveButton)
  208. {
  209. if (this.m_oLstChoices.selectedIndex == -1)
  210. {
  211. this.m_oRemoveButton.disabled = true;
  212. this.m_oRemoveButton.className = "clsInsertRemoveButton";
  213. }
  214. else
  215. {
  216. this.m_oRemoveButton.disabled = false;
  217. }
  218. }
  219. }
  220. //Prototypes to assign methods to new instances of the object
  221. CMultipleTimePicker.prototype.addNoUpdate = CMultipleTimePicker_addNoUpdate;
  222. CMultipleTimePicker.prototype.update = CMultipleTimePicker_update;
  223. CMultipleTimePicker.prototype.selectAll = CMultipleTimePicker_selectAll;
  224. CMultipleTimePicker.prototype.deSelectAll = CMultipleTimePicker_deSelectAll;
  225. CMultipleTimePicker.prototype.insert = CMultipleTimePicker_insert;
  226. CMultipleTimePicker.prototype.remove = CMultipleTimePicker_remove;
  227. CMultipleTimePicker.prototype.preProcess = CMultipleTimePicker_preProcess;
  228. CMultipleTimePicker.prototype.checkData = CMultipleTimePicker_checkData;
  229. CMultipleTimePicker.prototype.resizeList = CMultipleTimePicker_resizeList;
  230. CMultipleTimePicker.prototype.checkInsertRemove = CMultipleTimePicker_checkInsertRemove;