CMultipleDateTimePicker.js 7.2 KB

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