CDateTime.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. CDateTime.js
  14. This script provides interactivity for the dateTime prompt control.
  15. The dateTime control is a combination of a date control and a time control
  16. */
  17. // Constructor to create a new DateTime prompt
  18. // oDate: the Date control hidden form field
  19. // oDateControl: the Date control javascript object
  20. // oTime: the time control hidden form field
  21. // oTimeControl: the Time control javascript object
  22. // oImgTest: the image object used for validation handling
  23. // oSubmit: the form control to send the value to the server
  24. // oForm: the hidden dateTime form control to satisfy the prompt
  25. // bRequired: a flag to determine whether input is required
  26. // sSubmitType: 'default' will submit as a standard form
  27. // 'XML' will convert the submission to XML and submit
  28. // sDefaultValue: a default value to initialize the controls
  29. // 'yyyy-mm-dd hh:mm:ss.ddd'(SQL) or 'yyyy-mm-ddThh:mm:ss.ddd' (XSD)
  30. // bXSDformat: [true]|[false] specify whether date times should be returned
  31. // in XSD format (true, default) or SQL format (false)
  32. function CDateTime(oDateControl, oTimeControl, oSubmit, oForm, bRequired, sSubmitType, sDefaultValue, bXSDformat, sCVId)
  33. {
  34. this.setCVId(sCVId);
  35. this.m_oDateControl = oDateControl;
  36. this.m_oTimeControl = oTimeControl;
  37. this.m_oForm = oForm;
  38. this.m_oSubmit = oSubmit;
  39. this.m_bRequired = bRequired;
  40. this.m_bDisabled = false;
  41. //set the date and time controls to required
  42. //so that they report errors properly
  43. if (this.m_bRequired === true)
  44. {
  45. this.m_oDateControl.m_bRequired = true;
  46. this.m_oTimeControl.m_bRequired = true;
  47. }
  48. var sDate = K_PRMT_sEMPTY;
  49. var sTime = K_PRMT_sEMPTY;
  50. if (sDefaultValue)
  51. {
  52. //split the string into a date and time
  53. var rSplit = /[T\s]/;
  54. var arDefaultValue = sDefaultValue.split(rSplit);
  55. if (arDefaultValue.length > 2)
  56. {
  57. sDate = K_PRMT_sEMPTY;
  58. var lastIndex = arDefaultValue.length - 1;
  59. sTime = arDefaultValue[lastIndex]; // the last value is going to be the time
  60. // all other parts of the array will become the date
  61. for (var i = 0; i < lastIndex; i++)
  62. {
  63. sDate += arDefaultValue[i];
  64. // add the space that has been removed earlier but don't add it to the end of the
  65. // string
  66. if (i < lastIndex - 1)
  67. {
  68. sDate += K_PRMT_sSP;
  69. }
  70. }
  71. this.m_oDateControl.setValue(sDate);
  72. this.m_oTimeControl.setValue(sTime);
  73. }
  74. else if (arDefaultValue.length == 2)
  75. {
  76. sDate = arDefaultValue[0];
  77. this.m_oDateControl.setValue(sDate);
  78. sTime = arDefaultValue[1];
  79. this.m_oTimeControl.setValue(sTime);
  80. }
  81. else if (arDefaultValue.length == 1)
  82. {
  83. sDate = arDefaultValue[0];
  84. this.m_oDateControl.setValue(sDate);
  85. }
  86. }
  87. if (bXSDformat === false)
  88. {
  89. this.m_bXSDformat = false;
  90. }
  91. else
  92. {
  93. this.m_bXSDformat = true;
  94. }
  95. this.m_bValid = false;
  96. this.m_sSubmitType = sSubmitType;
  97. //check the default value to see if it is valid
  98. this.checkData();
  99. }
  100. CDateTime.prototype = new CPromptControl();
  101. function CDateTime_updateFormValue()
  102. {
  103. this.m_oDateControl.m_bRequired = true;
  104. this.m_oTimeControl.m_bRequired = true;
  105. }
  106. //this function prepares the date for the server
  107. function CDateTime_preProcess()
  108. {
  109. var sURLValues = K_PRMT_sEMPTY;
  110. if (this.m_sSubmitType == K_PRMT_sXML)
  111. {
  112. if (this.m_bDisabled !== true)
  113. {
  114. sURLValues += '<selectOption';
  115. sURLValues += ' displayValue="' + this.sGetFormatValue() +'"';
  116. sURLValues += ' useValue="' + this.sGetXSDValue() +'"';
  117. sURLValues += ' selected="true" />';
  118. }
  119. addSelectChoices(this.m_oSubmit, sURLValues);
  120. }
  121. else
  122. {
  123. sURLValues = this.sGetSQLDateTime();
  124. this.m_oSubmit.value = sURLValues;
  125. }
  126. }
  127. //validate the input into the control
  128. function CDateTime_checkData()
  129. {
  130. if (this.m_bRequired === true)
  131. {
  132. if ((this.m_oDateControl.isValid() === true) && (this.m_oTimeControl.isValid() === true))
  133. {
  134. this.m_bValid = true;
  135. this.checkPass();
  136. return true;
  137. }
  138. else if (this.m_oDateControl.isValid() === false)
  139. {
  140. this.m_bValid = false;
  141. this.m_oDateControl.checkFail();
  142. return false;
  143. }
  144. else if (this.m_oTimeControl.isValid() === false)
  145. {
  146. this.m_bValid = false;
  147. this.m_oTimeControl.checkFail();
  148. return false;
  149. }
  150. else
  151. {
  152. this.m_bValid = false;
  153. return false;
  154. }
  155. }
  156. else
  157. {
  158. this.m_bValid = true;
  159. this.checkPass();
  160. return true;
  161. }
  162. }
  163. //get the validity without checking the data first
  164. function CDateTime_getValid()
  165. {
  166. if ((this.m_oDateControl.getValid() === true) && (this.m_oTimeControl.getValid() === true))
  167. {
  168. return true;
  169. }
  170. else
  171. {
  172. return false;
  173. }
  174. }
  175. // return the date time in SQL specified form
  176. function CDateTime_sGetSQLDateTime()
  177. {
  178. var dateVal = this.m_oDateControl.sGetValue();
  179. var timeVal = this.m_oTimeControl.sGetSQLTime();
  180. if ((dateVal === false) || (timeVal === false))
  181. {
  182. this.m_oForm.value = K_PRMT_sEMPTY;
  183. return false;
  184. }
  185. else
  186. {
  187. this.m_oForm.value = dateVal + K_PRMT_sSP + timeVal;
  188. return this.m_oForm.value;
  189. }
  190. }
  191. // return the date time in XSD specified form
  192. function CDateTime_sGetXSDValue()
  193. {
  194. var dateVal = this.m_oDateControl.sGetValue();
  195. var timeVal = this.m_oTimeControl.sGetSQLTime();
  196. if ((dateVal === false) || (timeVal === false))
  197. {
  198. return false;
  199. }
  200. else
  201. {
  202. var sXSDvalue = this.m_oDateControl.sGetValue() + "T" + this.m_oTimeControl.sGetSQLTime();
  203. return sXSDvalue;
  204. }
  205. }
  206. // Return date time as displayed
  207. function CDateTime_sGetFormatDateTime()
  208. {
  209. var iType = this.m_oDateControl.m_iType;
  210. var sInputOrder = this.m_oDateControl.m_sInputOrder;
  211. var dInsertDate = this.m_oDateControl.m_dDate;
  212. var sDisplayDateValue = getFormatDate (dInsertDate, iType, sInputOrder);
  213. var sDisplayTimeValue =this.m_oTimeControl.sGetFormatTime();
  214. var sDisplayDateTimeValue = sDisplayDateValue + K_PRMT_sSP + sDisplayTimeValue;
  215. return sDisplayDateTimeValue;
  216. }
  217. function CDateTime_enable()
  218. {
  219. if (this.m_bRequired === true)
  220. {
  221. this.m_oDateControl.m_bRequired = true;
  222. this.m_oTimeControl.m_bRequired = true;
  223. }
  224. this.m_oDateControl.enable();
  225. this.m_oTimeControl.enable();
  226. this.m_bDisabled = false;
  227. }
  228. function CDateTime_disable()
  229. {
  230. if (this.m_bRequired === true)
  231. {
  232. this.m_oDateControl.m_bRequired = false;
  233. this.m_oTimeControl.m_bRequired = false;
  234. }
  235. this.m_oDateControl.disable();
  236. this.m_oTimeControl.disable();
  237. this.m_bDisabled = true;
  238. }
  239. // return the date time in XSD specified form
  240. function CDateTime_sGetValue()
  241. {
  242. this.checkData();
  243. if ((this.m_bValid === true) && ((this.m_oDateControl.hasValue() === true) && (this.m_oTimeControl.hasValue() === true)))
  244. {
  245. if (this.m_bXSDformat === false)
  246. {
  247. return this.sGetSQLDateTime();
  248. }
  249. else
  250. {
  251. return this.sGetXSDValue();
  252. }
  253. }
  254. else
  255. {
  256. return false;
  257. }
  258. }
  259. // Return date time as displayed
  260. function CDateTime_sGetFormatValue()
  261. {
  262. this.checkData();
  263. if ((this.m_bValid === true) && ((this.m_oDateControl.hasValue() === true) && (this.m_oTimeControl.hasValue() === true)))
  264. {
  265. return this.sGetFormatDateTime();
  266. }
  267. else
  268. {
  269. return false;
  270. }
  271. }
  272. function CDateTime_hasValue()
  273. {
  274. if ((this.m_oDateControl.hasValue()) && (this.m_oTimeControl.hasValue()))
  275. {
  276. return true;
  277. }
  278. else
  279. {
  280. return false;
  281. }
  282. }
  283. function CDateTime_toggleDisable(bState)
  284. {
  285. if (this.isRequired() === false)
  286. {
  287. if (bState === false)
  288. {
  289. this.disable();
  290. }
  291. else
  292. {
  293. this.enable();
  294. }
  295. }
  296. this.checkData();
  297. }
  298. //Prototypes to assign methods to new instances of the object
  299. CDateTime.prototype.preProcess = CDateTime_preProcess;
  300. CDateTime.prototype.sGetSQLDateTime = CDateTime_sGetSQLDateTime;
  301. CDateTime.prototype.sGetFormatDateTime = CDateTime_sGetFormatDateTime;
  302. CDateTime.prototype.checkData = CDateTime_checkData;
  303. CDateTime.prototype.enable = CDateTime_enable;
  304. CDateTime.prototype.disable = CDateTime_disable;
  305. CDateTime.prototype.toggleDisable = CDateTime_toggleDisable;
  306. CDateTime.prototype.sGetValue = CDateTime_sGetValue;
  307. CDateTime.prototype.sGetFormatValue = CDateTime_sGetFormatValue;
  308. CDateTime.prototype.sGetXSDValue = CDateTime_sGetXSDValue;
  309. CDateTime.prototype.getValid = CDateTime_getValid;
  310. CDateTime.prototype.hasValue = CDateTime_hasValue;