CMultipleDatePicker.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. CMultipleDatePicker.js
  14. This script is used to provide interactivity for the
  15. multiple selectDate prompt component. This component is
  16. a combination of the date picker and a list box.
  17. */
  18. //Constructor to create a checkboxlist component
  19. // oPicker: the date 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 CMultipleDatePicker(oPicker, oLstChoices, oSubmit, bRequired, sSubmitType, oErrorFeedback, oSizer, oInsertButton, oRemoveButton, sCVId)
  29. {
  30. this.setCVId(sCVId);
  31. this.m_oPicker = oPicker;
  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. CMultipleDatePicker.prototype = new CPromptControl();
  57. //select all items
  58. function CMultipleDatePicker_selectAll()
  59. {
  60. for (var i = 0; i < this.m_oLstChoices.options.length; i++)
  61. {
  62. this.m_oLstChoices.options[i].selected = true;
  63. }
  64. //check the states of the insert and remove buttons
  65. this.checkInsertRemove();
  66. }
  67. //remove selection from all items
  68. function CMultipleDatePicker_deSelectAll()
  69. {
  70. for (var i = 0; i < this.m_oLstChoices.options.length; i++)
  71. {
  72. this.m_oLstChoices.options[i].selected = false;
  73. }
  74. //check the states of the insert and remove buttons
  75. this.checkInsertRemove();
  76. }
  77. //insert values from the picker control
  78. function CMultipleDatePicker_insert()
  79. {
  80. var dInsertDate = this.m_oPicker.m_dDate;
  81. if (dInsertDate)
  82. {
  83. var sDisplayValue = this.m_oPicker.sGetFormatValue();
  84. var sUseValue = this.m_oPicker.sGetValue();
  85. if ((sDisplayValue) && (sUseValue))
  86. {
  87. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sUseValue, false, false);
  88. }
  89. }
  90. this.checkData();
  91. this.resizeList();
  92. this.resizeList();
  93. //check the states of the insert and remove buttons
  94. this.checkInsertRemove();
  95. }
  96. //remove selections from the list of choices
  97. function CMultipleDatePicker_remove()
  98. {
  99. this.removeSelectedChoices();
  100. //check the states of the insert and remove buttons
  101. this.checkInsertRemove();
  102. }
  103. //perform any special processing for the server.
  104. //this function will wrap all list items in XML.
  105. //This is required for cases where the unselected items need
  106. //to be submitted too.
  107. function CMultipleDatePicker_preProcess()
  108. {
  109. var i = 0;
  110. if (this.m_sSubmitType == K_PRMT_sXML)
  111. {
  112. var sURLValues = K_PRMT_sEMPTY;
  113. if (this.m_oLstChoices.options.length > 0)
  114. {
  115. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  116. {
  117. sURLValues += '<selectOption';
  118. sURLValues += ' displayValue="' + sXmlEncode(this.m_oLstChoices.options[i].text) +'"';
  119. sURLValues += ' useValue="' + sXmlEncode(this.m_oLstChoices.options[i].value) + '"';
  120. if (this.m_oLstChoices.options[i].selected == true)
  121. {
  122. sURLValues += ' selected="true" />';
  123. }
  124. else
  125. {
  126. sURLValues += ' selected="false" />';
  127. }
  128. }
  129. }
  130. addSelectChoices(this.m_oSubmit, sURLValues);
  131. }
  132. else
  133. {
  134. //select all the choices so they can be submitted with the form
  135. for(i = 0; i < this.m_oLstChoices.options.length; i ++)
  136. {
  137. this.m_oLstChoices.options[i].selected = true;
  138. }
  139. }
  140. }
  141. //return true unless this is a required prompt
  142. //and there are no values
  143. function CMultipleDatePicker_checkData()
  144. {
  145. if ((this.m_bRequired == true) && (this.m_oLstChoices.options.length === 0))
  146. {
  147. this.m_bValid = false;
  148. this.checkFail();
  149. return false;
  150. }
  151. else
  152. {
  153. this.m_bValid = true;
  154. this.checkPass();
  155. return true;
  156. }
  157. }
  158. //make sure that choices are always visible and set a minimum size
  159. //resize the list to fit the data if required
  160. //if there are no items, prevent the list from
  161. //shrinking too small
  162. //allow the list to expand to fit the biggest item
  163. function CMultipleDatePicker_resizeList()
  164. {
  165. if (this.m_oSizer)
  166. {
  167. this.m_oLstChoices.style.width='auto';
  168. if (this.m_oSizer.width < 200)
  169. {
  170. this.m_oLstChoices.style.width='200px';
  171. }
  172. }
  173. }
  174. //enable and disable the insert and remove buttons
  175. //based on what the user has selected
  176. function CMultipleDatePicker_checkInsertRemove()
  177. {
  178. if (this.m_oInsertButton)
  179. {
  180. if ((this.m_oPicker.getValid() == true) && (this.m_oPicker.hasValue()))
  181. {
  182. this.m_oInsertButton.disabled = false;
  183. }
  184. else
  185. {
  186. this.m_oInsertButton.disabled = true;
  187. this.m_oInsertButton.className = "clsInsertRemoveButton";
  188. }
  189. }
  190. if (this.m_oRemoveButton)
  191. {
  192. if (this.m_oLstChoices.selectedIndex == -1)
  193. {
  194. this.m_oRemoveButton.disabled = true;
  195. this.m_oRemoveButton.className = "clsInsertRemoveButton";
  196. }
  197. else
  198. {
  199. this.m_oRemoveButton.disabled = false;
  200. }
  201. }
  202. }
  203. //add a value to the list via javascript
  204. function CMultipleDatePicker_add(sDisplayValue, sInsertText)
  205. {
  206. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, false, false);
  207. this.checkData();
  208. this.resizeList();
  209. this.resizeList();
  210. //check the states of the insert and remove buttons
  211. this.checkInsertRemove();
  212. }
  213. //add an item to the list without any checking by the control
  214. //this method provides an efficient way to add items, but
  215. //the update() method should be called to clean up the control
  216. //when finished adding
  217. function CMultipleDatePicker_addNoUpdate(sDisplayValue, sInsertText, sel)
  218. {
  219. sDisplayValue = sDecodeU003( sDisplayValue );
  220. sInsertText = sDecodeU003( sInsertText );
  221. if (sel == true) {
  222. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, true, true);
  223. }
  224. else {
  225. this.m_oLstChoices.options[this.m_oLstChoices.options.length] = new Option(sDisplayValue, sInsertText, false, false);
  226. }
  227. }
  228. //clean up the control
  229. function CMultipleDatePicker_update()
  230. {
  231. this.checkData();
  232. this.resizeList();
  233. this.resizeList();
  234. //check the states of the insert and remove buttons
  235. this.checkInsertRemove();
  236. }
  237. //Prototypes to assign methods to new instances of the object
  238. CMultipleDatePicker.prototype.selectAll = CMultipleDatePicker_selectAll;
  239. CMultipleDatePicker.prototype.deSelectAll = CMultipleDatePicker_deSelectAll;
  240. CMultipleDatePicker.prototype.insert = CMultipleDatePicker_insert;
  241. CMultipleDatePicker.prototype.remove = CMultipleDatePicker_remove;
  242. CMultipleDatePicker.prototype.preProcess = CMultipleDatePicker_preProcess;
  243. CMultipleDatePicker.prototype.checkData = CMultipleDatePicker_checkData;
  244. CMultipleDatePicker.prototype.resizeList = CMultipleDatePicker_resizeList;
  245. CMultipleDatePicker.prototype.checkInsertRemove = CMultipleDatePicker_checkInsertRemove;
  246. CMultipleDatePicker.prototype.add = CMultipleDatePicker_add;
  247. CMultipleDatePicker.prototype.addNoUpdate = CMultipleDatePicker_addNoUpdate;
  248. CMultipleDatePicker.prototype.update = CMultipleDatePicker_update;