CIntervalPicker.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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. CIntervalPickerIE5.js
  14. This script is used to provide interactivity for the selectTime prompt control
  15. */
  16. //Constructor to create a selectTime component
  17. // oSubmit: the field used to submit values to the server
  18. // oForm: the field used to store processed user input
  19. // oDays: hours form control
  20. // oHours: hours form control
  21. // oMinutes: minutes form control
  22. // oSeconds: seconds form control, null if not shown
  23. // oMilliseconds: milliseconds form control, null if not shown
  24. // oImgTest: error feedback image object
  25. // sRef: the name of this object
  26. // sDefaultValue: the initial value for the control
  27. // bRequired: boolean, specify if user input is required
  28. // sSubmitType: 'default' will submit as a standard form
  29. // 'XML' will convert the submission to XML and submit
  30. // bShowSeconds: true/false, determine whether to show seconds edit box
  31. // bShowMilliseconds: true/false, determine whether to show Milliseconds edit box
  32. // bAllowNegative: true/false, some intervals cannot be negative
  33. function CIntervalPicker(oSubmit, oForm, oDays, oHours, oMinutes, oSeconds, oMilliseconds, oImgTest, sRef, sDefaultValue, bRequired, sSubmitType, bShowSeconds, bShowMilliseconds, bAllowNegative, sCVId)
  34. {
  35. this.setCVId(sCVId);
  36. //get references to form controls
  37. this.m_oSubmit = oSubmit;
  38. this.m_oForm = oForm;
  39. this.m_oDays = oDays;
  40. this.m_oHours = oHours;
  41. this.m_oMinutes = oMinutes;
  42. this.m_bShowSeconds = bShowSeconds;
  43. this.m_bShowMilliseconds = bShowMilliseconds;
  44. //handle negative values
  45. this.m_bNegative = false;
  46. //create regular expressions for parsing with current locale
  47. initIntervalRegularExpressions();
  48. //bShowSeconds
  49. if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
  50. {
  51. this.m_oSeconds = oSeconds;
  52. }
  53. else
  54. {
  55. this.m_oSeconds = null;
  56. }
  57. //bShowMilliseconds
  58. if (this.m_bShowMilliseconds == true)
  59. {
  60. this.m_oMilliseconds = oMilliseconds;
  61. }
  62. else
  63. {
  64. this.m_oMilliseconds = null;
  65. }
  66. //specify whether the user must enter a date or not
  67. this.m_bRequired = bRequired;
  68. this.m_bDisabled = false;
  69. //indicate whether the control has valid data
  70. this.m_bValid = false;
  71. //submit as XML or as a standard html form
  72. this.m_sSubmitType = sSubmitType;
  73. //can the user type a negative interval?
  74. this.m_bAllowNegative = bAllowNegative ? bAllowNegative : false;
  75. //define default interval
  76. var sDefaultTime = sDefaultValue ? sDefaultValue : K_PRMT_sEMPTY;
  77. //check to see if this is an XML schema duration data type
  78. if (sDefaultTime.indexOf ('P') != -1)
  79. {
  80. this.parseXSDIntervalValue(sDefaultTime);
  81. }
  82. //check to see if this is a UDA format interval
  83. else
  84. {
  85. //search for a negative value
  86. var z = sDefaultTime.search(rMinusSign);
  87. if (z == -1)
  88. {
  89. this.m_bNegative = false;
  90. }
  91. else
  92. {
  93. this.m_bNegative = true;
  94. //strip of the minus sign
  95. sDefaultTime = sDefaultTime.replace(rMinusSign, K_PRMT_sEMPTY);
  96. }
  97. var arDefaultTime = sDefaultTime.split(/[:.\s]/g);
  98. //do we have a valid date?
  99. switch (arDefaultTime.length)
  100. {
  101. case 5:
  102. //set default
  103. this.m_iDays = arDefaultTime[0];
  104. this.m_iHours = arDefaultTime[1];
  105. this.m_iMinutes = arDefaultTime[2];
  106. this.m_iSeconds = arDefaultTime[3];
  107. this.m_iMilliseconds = arDefaultTime[4];
  108. break;
  109. default:
  110. //no valid default set
  111. if (this.m_bRequired == true)
  112. {
  113. this.m_iDays = 0;
  114. this.m_iHours = 0;
  115. this.m_iMinutes = 0;
  116. this.m_iSeconds = 0;
  117. this.m_iMilliseconds = 0;
  118. }
  119. else
  120. {
  121. this.m_iDays = null;
  122. this.m_iHours = null;
  123. this.m_iMinutes = null;
  124. this.m_iSeconds = null;
  125. this.m_iMilliseconds = null;
  126. }
  127. }
  128. }
  129. //skin folder
  130. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  131. //images for handling errors
  132. this.m_oImgCheckDate = oImgTest;
  133. if (this.m_oImgCheckDate != null)
  134. {
  135. this.m_oImgErrorFalse= new Image();
  136. this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  137. this.m_oImgErrorTrue = new Image();
  138. this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  139. }
  140. //create a pointer to this function
  141. this.m_sRef = sRef;
  142. this.draw();
  143. this.updateFormField();
  144. this.checkInterval();
  145. }
  146. CIntervalPicker.prototype = new CPromptControl();
  147. function CIntervalPicker_draw()
  148. {
  149. var sDayVal = (this.m_iDays != null) ? this.m_iDays : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
  150. if (this.m_bNegative == true)
  151. {
  152. this.m_oDays.value = "-" + sDayVal;
  153. }
  154. else
  155. {
  156. this.m_oDays.value = sDayVal;
  157. }
  158. this.m_oHours.value = (this.m_iHours != null) ? this.m_iHours : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
  159. this.m_oMinutes.value = (this.m_iMinutes != null) ? this.m_iMinutes : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
  160. if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
  161. {
  162. this.m_oSeconds.value = (this.m_iSeconds != null) ? this.m_iSeconds : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
  163. }
  164. if (this.m_bShowMilliseconds == true)
  165. {
  166. this.m_oMilliseconds.value = (this.m_iMilliseconds != null) ? this.m_iMilliseconds : (this.m_bRequired == true) ? "0" : K_PRMT_sEMPTY;
  167. }
  168. }
  169. function CIntervalPicker_updateFormField()
  170. {
  171. //return a valid interval data type
  172. //DDD HH:MT:SS.PPP, e.g. 2 10:20:30.888
  173. //hours
  174. var iDaysPart = 0;
  175. var iHoursPart = 0;
  176. var iMinutesPart = 0;
  177. var sDays = K_PRMT_sEMPTY;
  178. var sHours = K_PRMT_sEMPTY;
  179. var sMinutes = K_PRMT_sEMPTY;
  180. var sSeconds = K_PRMT_sEMPTY;
  181. var sMilliseconds = K_PRMT_sEMPTY;
  182. var sNegative = K_PRMT_sEMPTY;
  183. if (this.m_bNegative == true)
  184. {
  185. sNegative = '-';
  186. }
  187. if (this.m_iSeconds != null)
  188. {
  189. if (parseInt(this.m_iSeconds,10) >= 60)
  190. {
  191. iMinutesPart = 1;
  192. //Note the UI prevents this value from being > 2 characters
  193. sSeconds = (parseInt(this.m_iSeconds,10) - 60).toString();
  194. }
  195. else {
  196. sSeconds = this.m_iSeconds.toString();
  197. }
  198. if (sSeconds.length == 1)
  199. {
  200. sSeconds = '0' + sSeconds;
  201. }
  202. }
  203. if (this.m_iMinutes != null)
  204. {
  205. if (parseInt(this.m_iMinutes,10) >= 60)
  206. {
  207. iHoursPart = 1;
  208. //Note the UI prevents this value from being > 2 characters
  209. sMinutes = (parseInt(this.m_iMinutes,10) + iMinutesPart) - 60;
  210. }
  211. else {
  212. sMinutes = this.m_iMinutes.toString();
  213. }
  214. if (sMinutes.length == 1)
  215. {
  216. sMinutes = '0' + sMinutes;
  217. }
  218. }
  219. if (this.m_iHours > 24)
  220. {
  221. iDaysPart = (parseInt(this.m_iHours,10) + iHoursPart) / 24;
  222. iDaysPart = parseInt(iDaysPart, 10);
  223. iHoursPart += parseInt(this.m_iHours,10) % 24;
  224. if (this.m_iDays != null) {
  225. sDays = (parseInt(this.m_iDays,10) + iDaysPart).toString();
  226. }
  227. else {
  228. sDays = iDaysPart.toString();
  229. }
  230. sHours = iHoursPart.toString();
  231. }
  232. else
  233. {
  234. if (this.m_iDays != null)
  235. {
  236. sDays = this.m_iDays.toString();
  237. }
  238. else
  239. {
  240. sDays = '00';
  241. }
  242. if (this.m_iHours != null)
  243. {
  244. sHours = (parseInt(this.m_iHours,10) + iHoursPart).toString();
  245. }
  246. else if (iHoursPart > 0)
  247. {
  248. sHours = iHoursPart.toString();
  249. }
  250. else
  251. {
  252. sHours = '00';
  253. }
  254. }
  255. //days
  256. if (sDays.length == 2)
  257. {
  258. sDays = '0' + sDays;
  259. }
  260. else if (sDays.length == 1)
  261. {
  262. sDays = '00' + sDays;
  263. }
  264. //hours
  265. if (sHours.length == 1)
  266. {
  267. sHours = '0' + sHours;
  268. }
  269. //minutes
  270. if (iMinutesPart > 0)
  271. {
  272. sMinutes = iMinutesPart.toString();
  273. if (sMinutes.length == 1) {
  274. sMinutes = '0' + sMinutes;
  275. }
  276. }
  277. else if (sMinutes == K_PRMT_sEMPTY)
  278. {
  279. sMinutes = '00';
  280. }
  281. //seconds
  282. if (sSeconds == K_PRMT_sEMPTY)
  283. {
  284. sSeconds = '00';
  285. }
  286. //milliseconds
  287. if (this.m_iMilliseconds != null)
  288. {
  289. sMilliseconds = this.m_iMilliseconds.toString();
  290. if (sMilliseconds.length == 2)
  291. {
  292. sMilliseconds = '0' + sMilliseconds;
  293. }
  294. else if (sMilliseconds.length == 1)
  295. {
  296. sMilliseconds = '00' + sMilliseconds;
  297. }
  298. }
  299. else
  300. {
  301. sMilliseconds = '000';
  302. }
  303. this.m_oForm.value = sNegative + sDays + K_PRMT_sSP +sHours + K_PRMT_sCOLON + sMinutes + K_PRMT_sCOLON + sSeconds + K_PRMT_sDOT + sMilliseconds;
  304. }
  305. //catch the backspace key
  306. //some browsers (IE5.5 don't capture this event)
  307. function CIntervalPicker_keyPress(sKeyCode,sObj)
  308. {
  309. if (sKeyCode=='8')
  310. {
  311. switch (sObj)
  312. {
  313. case 'checkDay':
  314. this.checkDay();
  315. break;
  316. case 'checkHour':
  317. this.checkHour();
  318. break;
  319. case 'checkMinute':
  320. this.checkMinute();
  321. break;
  322. case 'checkSecond':
  323. this.checkSecond();
  324. break;
  325. case 'checkMillisecond':
  326. this.checkMillisecond();
  327. break;
  328. default:
  329. this.checkInterval();
  330. }
  331. }
  332. return true;
  333. }
  334. //check for a valid interval
  335. function CIntervalPicker_checkInterval()
  336. {
  337. var bCheckFlag = false;
  338. var bCheckNegative = false;
  339. if (this.m_bRequired == true)
  340. {
  341. var bIntervalExists = true;
  342. if ((this.m_bShowMilliseconds == true) && (this.m_oMilliseconds.value == K_PRMT_sEMPTY))
  343. {
  344. bIntervalExists = false;
  345. }
  346. if ((bIntervalExists == true) && ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true)) && (this.m_oSeconds.value == K_PRMT_sEMPTY))
  347. {
  348. bIntervalExists = false;
  349. }
  350. if (bIntervalExists == true)
  351. {
  352. if ((this.m_oDays.value == K_PRMT_sEMPTY) || (this.m_oHours.value == K_PRMT_sEMPTY) || (this.m_oMinutes.value == K_PRMT_sEMPTY))
  353. {
  354. bIntervalExists = false;
  355. }
  356. }
  357. //if no values have been entered and this is a required prompt
  358. //then return an error
  359. if (bIntervalExists == false)
  360. {
  361. //show error animation
  362. this.checkIntervalFail();
  363. return;
  364. }
  365. }
  366. //are any of the controls negative
  367. //check days, hours and minutes
  368. if (this.bIsNegative(this.m_oDays.value)|| this.bIsNegative(this.m_oHours.value) || this.bIsNegative(this.m_oMinutes.value))
  369. {
  370. bCheckNegative = true;
  371. }
  372. //check seconds if seconds and milliseconds are enabled
  373. if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
  374. {
  375. if (this.bIsNegative(this.m_oSeconds.value) == true)
  376. {
  377. bCheckNegative = true;
  378. }
  379. }
  380. //check milliseconds if milliseconds are enabled
  381. if (this.m_bShowMilliseconds == true)
  382. {
  383. if (this.bIsNegative(this.m_oMilliseconds.value) == true)
  384. {
  385. bCheckNegative = true;
  386. }
  387. }
  388. //check days, hours and minutes to see if they are correct
  389. if (this.bcheckNumber(this.m_oDays.value) && this.bcheckNumber(this.m_oHours.value) && this.bcheckNumber(this.m_oMinutes.value))
  390. {
  391. bCheckFlag = true;
  392. }
  393. //check seconds if seconds and milliseconds are enabled
  394. if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
  395. {
  396. if (this.bcheckNumber(this.m_oSeconds.value) != true)
  397. {
  398. bCheckFlag = false;
  399. }
  400. }
  401. //check milliseconds if milliseconds are enabled
  402. if (this.m_bShowMilliseconds == true)
  403. {
  404. if (this.bcheckNumber(this.m_oMilliseconds.value) != true)
  405. {
  406. bCheckFlag = false;
  407. }
  408. }
  409. //handle negative values
  410. if (bCheckNegative == true)
  411. {
  412. this.m_bNegative = true;
  413. if (this.m_bAllowNegative==false)
  414. {
  415. bCheckFlag = false;
  416. }
  417. }
  418. else
  419. {
  420. this.m_bNegative = false;
  421. }
  422. //determine pass/fail
  423. if (bCheckFlag == true)
  424. {
  425. this.updateFormField();
  426. this.checkIntervalPass();
  427. this.m_bValid = true;
  428. }
  429. else
  430. {
  431. //show error animation
  432. this.checkIntervalFail();
  433. this.m_bValid = false;
  434. }
  435. }
  436. //render control in validated state
  437. function CIntervalPicker_checkIntervalPass()
  438. {
  439. if ((this.m_oImgCheckDate != null) && (this.m_oImgCheckDate.src != this.m_oImgErrorFalse.src))
  440. {
  441. this.m_oImgCheckDate.src = this.m_oImgErrorFalse.src;
  442. }
  443. this.m_bValid = true;
  444. this.notify(gPASS, this);
  445. }
  446. //render control in error state
  447. function CIntervalPicker_checkIntervalFail()
  448. {
  449. if (this.m_oImgCheckDate != null)
  450. {
  451. this.m_oImgCheckDate.src = this.m_oImgErrorTrue.src + '?' + Math.random();
  452. }
  453. this.m_bValid = false;
  454. this.notify(gFAIL, this);
  455. }
  456. function CIntervalPicker_checkDay()
  457. {
  458. if (this.m_oDays.value != K_PRMT_sEMPTY)
  459. {
  460. var sDays = this.m_oDays.value;
  461. //check for a negative interval
  462. if (this.bcheckNumber(sDays) == true)
  463. {
  464. //update the variable
  465. sDays = this.sStripNegative(sDays);
  466. this.m_iDays = (sDays != K_PRMT_sEMPTY) ? sDays : null;
  467. this.m_oDays.className = "clsIntervalWidget";
  468. }
  469. else
  470. {
  471. //show error state
  472. this.m_iDays = null;
  473. this.m_oDays.className = "clsIntervalWidgetParseError";
  474. }
  475. }
  476. else
  477. {
  478. //no value, reset the variable
  479. this.m_iDays = null;
  480. if (this.m_bRequired == true)
  481. {
  482. this.m_oDays.className = "clsIntervalWidgetParseError";
  483. }
  484. else
  485. {
  486. this.m_oDays.className = "clsIntervalWidget";
  487. }
  488. }
  489. //update the form control
  490. this.checkInterval();
  491. }
  492. function CIntervalPicker_checkHour()
  493. {
  494. if (this.m_oHours.value != K_PRMT_sEMPTY)
  495. {
  496. var sHours = this.m_oHours.value;
  497. if (this.bcheckNumber(sHours) == true)
  498. {
  499. //update the variable
  500. sHours = this.sStripNegative(sHours);
  501. this.m_iHours = (sHours != K_PRMT_sEMPTY) ? sHours : null;
  502. this.m_oHours.className = "clsIntervalWidget";
  503. }
  504. else
  505. {
  506. this.m_iHours = null;
  507. //show error state
  508. this.m_oHours.className = "clsIntervalWidgetParseError";
  509. }
  510. }
  511. else
  512. {
  513. //no value, reset the variable
  514. this.m_iHours = null;
  515. if (this.m_bRequired == true)
  516. {
  517. this.m_oHours.className = "clsIntervalWidgetParseError";
  518. }
  519. else
  520. {
  521. this.m_oHours.className = "clsIntervalWidget";
  522. }
  523. }
  524. //update the form control
  525. this.checkInterval();
  526. }
  527. function CIntervalPicker_checkMinute()
  528. {
  529. if (this.m_oMinutes.value != K_PRMT_sEMPTY)
  530. {
  531. var sMinutes = this.m_oMinutes.value;
  532. if (this.bcheckNumber(this.m_oMinutes.value) == true)
  533. {
  534. //update the variable
  535. sMinutes = this.sStripNegative(sMinutes);
  536. this.m_iMinutes = (sMinutes != K_PRMT_sEMPTY) ? sMinutes : null;
  537. this.m_oMinutes.className = "clsIntervalWidget";
  538. }
  539. else
  540. {
  541. this.m_iMinutes = null;
  542. //show error state
  543. this.m_oMinutes.className = "clsIntervalWidgetParseError";
  544. }
  545. }
  546. else
  547. {
  548. //no value, reset the variable
  549. this.m_iMinutes = null;
  550. if (this.m_bRequired == true)
  551. {
  552. this.m_oMinutes.className = "clsIntervalWidgetParseError";
  553. }
  554. else
  555. {
  556. this.m_oMinutes.className = "clsIntervalWidget";
  557. }
  558. }
  559. //update the form control
  560. this.checkInterval();
  561. }
  562. function CIntervalPicker_checkSecond()
  563. {
  564. if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
  565. {
  566. if (this.m_oSeconds.value != K_PRMT_sEMPTY)
  567. {
  568. var sSeconds = this.m_oSeconds.value;
  569. if (this.bcheckNumber(sSeconds) == true)
  570. {
  571. //update the variable
  572. sSeconds = this.sStripNegative(sSeconds);
  573. this.m_iSeconds = (sSeconds != K_PRMT_sEMPTY) ? sSeconds : null;
  574. this.m_oSeconds.className = "clsIntervalWidget";
  575. }
  576. else
  577. {
  578. this.m_iSeconds = null;
  579. //show error state
  580. this.m_oSeconds.className = "clsIntervalWidgetParseError";
  581. }
  582. }
  583. else
  584. {
  585. //no value, reset the variable
  586. this.m_iSeconds = null;
  587. if (this.m_bRequired == true)
  588. {
  589. this.m_oSeconds.className = "clsIntervalWidgetParseError";
  590. }
  591. else
  592. {
  593. this.m_oSeconds.className = "clsIntervalWidget";
  594. }
  595. }
  596. //update the form control
  597. this.checkInterval();
  598. }
  599. }
  600. function CIntervalPicker_checkMillisecond()
  601. {
  602. if (this.m_bShowMilliseconds == true)
  603. {
  604. if (this.m_oMilliseconds.value != K_PRMT_sEMPTY)
  605. {
  606. var sMilliseconds = this.m_oMilliseconds.value;
  607. if (this.bcheckNumber(sMilliseconds) == true)
  608. {
  609. //update the variable
  610. sMilliseconds = this.sStripNegative(sMilliseconds);
  611. this.m_iMilliseconds = (sMilliseconds != K_PRMT_sEMPTY) ? sMilliseconds : null;
  612. this.m_oMilliseconds.className = "clsIntervalWidget";
  613. }
  614. else
  615. {
  616. this.m_iMilliseconds = null;
  617. //show error state
  618. this.m_oMilliseconds.className = "clsIntervalWidgetParseError";
  619. }
  620. }
  621. else
  622. {
  623. //no value, reset the variable
  624. this.m_iMilliseconds = null;
  625. if (this.m_bRequired == true)
  626. {
  627. this.m_oMilliseconds.className = "clsIntervalWidgetParseError";
  628. }
  629. else
  630. {
  631. this.m_oMilliseconds.className = "clsIntervalWidget";
  632. }
  633. }
  634. //update the form control
  635. this.checkInterval();
  636. }
  637. }
  638. //set an interval in which the control will check for changed/valid data
  639. function CIntervalPicker_startCheckDataInterval(field, interval)
  640. {
  641. var functionString = this.m_sRef + ".checkValueChange('" + field + "')";
  642. if (field == "day")
  643. {
  644. this.m_sDaysCurrentValue = this.m_oDays.value;
  645. this.m_intervalIdDays = setInterval(functionString, interval);
  646. }
  647. else if (field == "hour")
  648. {
  649. this.m_sHoursCurrentValue = this.m_oHours.value;
  650. this.m_intervalIdHours = setInterval(functionString, interval);
  651. }
  652. else if (field == "minute")
  653. {
  654. this.m_sMinutesCurrentValue = this.m_oMinutes.value;
  655. this.m_intervalIdMinutes = setInterval(functionString, interval);
  656. }
  657. else if (field == "second" && this.m_oSeconds != null)
  658. {
  659. this.m_sSecondsCurrentValue = this.m_oSeconds.value;
  660. this.m_intervalIdSeconds = setInterval(functionString, interval);
  661. }
  662. else if (field == "millisecond" && this.m_oMilliseconds != null)
  663. {
  664. this.m_sMillisecondsCurrentValue = this.m_oMilliseconds.value;
  665. this.m_intervalIdMilliseconds = setInterval(functionString, interval);
  666. }
  667. }
  668. //stop the control from checking for changed/valid data
  669. function CIntervalPicker_endCheckDataInterval(intervalId)
  670. {
  671. if (typeof intervalId != K_PRMT_sUNDEFINED && intervalId !== K_PRMT_sEMPTY)
  672. {
  673. clearInterval(intervalId);
  674. }
  675. }
  676. //check if value has changed
  677. function CIntervalPicker_checkValueChange(field)
  678. {
  679. if (field == "day" && typeof this.m_sDaysCurrentValue != K_PRMT_sUNDEFINED)
  680. {
  681. if (this.m_oDays.value != this.m_sDaysCurrentValue)
  682. {
  683. this.endCheckDataInterval(this.m_intervalIdDays);
  684. this.checkDay();
  685. }
  686. }
  687. else if (field == "hour" && typeof this.m_sHoursCurrentValue != K_PRMT_sUNDEFINED)
  688. {
  689. if (this.m_oHours.value != this.m_sHoursCurrentValue)
  690. {
  691. this.endCheckDataInterval(this.m_intervalIdHours);
  692. this.checkHour();
  693. }
  694. }
  695. else if (field == "minute" && typeof this.m_sMinutesCurrentValue != K_PRMT_sUNDEFINED)
  696. {
  697. if (this.m_oMinutes.value != this.m_sMinutesCurrentValue)
  698. {
  699. this.endCheckDataInterval(this.m_intervalIdMinutes);
  700. this.checkMinute();
  701. }
  702. }
  703. else if (field == "second" && this.m_oSeconds != null && typeof this.m_sSecondsCurrentValue != K_PRMT_sUNDEFINED)
  704. {
  705. if (this.m_oSeconds.value != this.m_sSecondsCurrentValue)
  706. {
  707. this.endCheckDataInterval(this.m_intervalIdSeconds);
  708. this.checkSecond();
  709. }
  710. }
  711. else if (field == "millisecond" && this.m_oMilliseconds != null && typeof this.m_sMillisecondsCurrentValue != K_PRMT_sUNDEFINED)
  712. {
  713. if (this.m_oMilliseconds.value != this.m_sMillisecondsCurrentValue)
  714. {
  715. this.endCheckDataInterval(this.m_intervalIdMilliseconds);
  716. this.checkMillisecond();
  717. }
  718. }
  719. }
  720. //test to see if the value is an integer
  721. function CIntervalPicker_bcheckNumber(sTestString)
  722. {
  723. //strip out the negative sign if it exists
  724. sTestString = sTestString.replace('-', K_PRMT_sEMPTY);
  725. //check for non-numeric characters
  726. var z = sTestString.search(/[^0-9]/);
  727. if (z == -1)
  728. {
  729. return true;
  730. }
  731. else
  732. {
  733. return false;
  734. }
  735. }
  736. //return the time in SQL format
  737. function CIntervalPicker_sGetInterval()
  738. {
  739. this.updateFormField();
  740. var sValue = K_PRMT_sEMPTY;
  741. sValue = this.m_oForm.value;
  742. return sValue;
  743. }
  744. //return the time in SQL format
  745. function CIntervalPicker_sGetFormatInterval()
  746. {
  747. var sValue = K_PRMT_sEMPTY;
  748. if (this.m_bNegative == true)
  749. {
  750. sValue += g_minusSign;
  751. }
  752. var sDays = "0";
  753. if (this.m_iDays != null)
  754. {
  755. sDays = this.m_iDays.toString();
  756. }
  757. var sHours = "0";
  758. if (this.m_iHours != null)
  759. {
  760. sHours = this.m_iHours.toString();
  761. }
  762. var sMinutes = "00";
  763. if (this.m_iMinutes != null)
  764. {
  765. sMinutes = this.m_iMinutes.toString();
  766. if (sMinutes.length == 1)
  767. {
  768. sMinutes = '0' + sMinutes;
  769. }
  770. }
  771. sValue += sDays + K_PRMT_sSP + sHours + K_PRMT_sCOLON + sMinutes;
  772. if ((this.m_bShowSeconds == true) || (this.m_bShowMilliseconds == true))
  773. {
  774. var sSeconds = '00';
  775. if (this.m_iSeconds != null)
  776. {
  777. sSeconds = this.m_iSeconds.toString();
  778. if (sSeconds.length == 1)
  779. {
  780. sSeconds = '0' + sSeconds;
  781. }
  782. }
  783. sValue += K_PRMT_sCOLON + sSeconds;
  784. }
  785. if (this.m_bShowMilliseconds == true)
  786. {
  787. var sMilliseconds = '000';
  788. if (this.m_iMilliseconds != null)
  789. {
  790. sMilliseconds = this.m_iMilliseconds.toString();
  791. if (sMilliseconds.length == 2)
  792. {
  793. sMilliseconds = '0' + sMilliseconds;
  794. }
  795. else if (sMilliseconds.length == 1)
  796. {
  797. sMilliseconds = '00' + sMilliseconds;
  798. }
  799. }
  800. sValue += K_PRMT_sDOT + sMilliseconds;
  801. }
  802. return sValue;
  803. }
  804. //validate the input into the control
  805. function CIntervalPicker_checkData()
  806. {
  807. this.checkInterval();
  808. if ((this.m_bRequired == true) && (this.m_oForm.value==K_PRMT_sEMPTY))
  809. {
  810. this.m_bValid = false;
  811. this.checkIntervalFail();
  812. return false;
  813. }
  814. else
  815. {
  816. this.m_bValid = true;
  817. this.checkIntervalPass();
  818. return true;
  819. }
  820. }
  821. //perform any special processing for the server.
  822. function CIntervalPicker_preProcess()
  823. {
  824. if (this.m_sSubmitType == K_PRMT_sXML)
  825. {
  826. var sURLValues = K_PRMT_sEMPTY;
  827. if (this.hasValue() == true)
  828. {
  829. if ((this.m_oForm.value != K_PRMT_sEMPTY) && (this.m_bDisabled!=true))
  830. {
  831. sURLValues += '<selectOption';
  832. sURLValues += ' displayValue="' + this.sGetFormatInterval() +'"';
  833. sURLValues += ' useValue="' + this.sGetXSDValue() +'"';
  834. sURLValues += ' selected="true" />';
  835. }
  836. }
  837. addSelectChoices(this.m_oSubmit, sURLValues);
  838. }
  839. else
  840. {
  841. if (this.m_bDisabled != true)
  842. {
  843. this.m_oSubmit.value = this.sGetInterval();
  844. }
  845. else
  846. {
  847. //this control is disabled
  848. this.m_oSubmit.value = K_PRMT_sEMPTY;
  849. }
  850. }
  851. }
  852. //return interval data type
  853. function CIntervalPicker_sGetValue()
  854. {
  855. if (this.m_sSubmitType == K_PRMT_sXML)
  856. {
  857. return this.sGetXSDValue();
  858. }
  859. else
  860. {
  861. return this.sGetInterval();
  862. }
  863. }
  864. //return locale formatted value
  865. function CIntervalPicker_sGetFormatValue()
  866. {
  867. return this.sGetFormatInterval();
  868. }
  869. //return XML schema formatted value
  870. //The value space of duration is a six-dimensional space where the coordinates designate the
  871. //Gregorian year, month, day, hour, minute, and second components
  872. //PnYnMnDTnHnMnS
  873. //If the number of years, months, days, hours, minutes, or seconds in any expression equals zero,
  874. //the number and its corresponding designator may be omitted.
  875. //However, at least one number and its designator must be present.
  876. //The seconds part ·may· have a decimal fraction.
  877. //The designator 'T' shall be absent if all of the time items are absent.
  878. //The designator 'P' must always be present.
  879. //An optional preceding minus sign ('-') is allowed, to indicate a negative duration.
  880. //If the sign is omitted a positive duration is indicated.
  881. function CIntervalPicker_sGetXSDValue()
  882. {
  883. var sPeriod = K_PRMT_sEMPTY;
  884. //determine the number Days
  885. if (this.m_iDays != null)
  886. {
  887. sPeriod += this.sStripNegative(this.m_iDays.toString()) + "D";
  888. }
  889. //add the time designator
  890. if ((this.m_iHours != null) || (this.m_iMinutes != null) || (this.m_iSeconds != null) || (this.m_iMilliseconds != null))
  891. {
  892. sPeriod += "T";
  893. if (this.m_iHours != null)
  894. {
  895. sPeriod += this.sStripNegative(this.m_iHours.toString()) + "H";
  896. }
  897. if (this.m_iMinutes != null)
  898. {
  899. sPeriod += this.sStripNegative(this.m_iMinutes.toString()) + "M";
  900. }
  901. if (this.m_iSeconds != null)
  902. {
  903. sPeriod += this.sStripNegative(this.m_iSeconds.toString());
  904. }
  905. if (this.m_iMilliseconds != null)
  906. {
  907. sPeriod += K_PRMT_sDOT + this.sStripNegative(this.m_iMilliseconds.toString()) + "S";
  908. }
  909. }
  910. //has the user specified an interval?
  911. if (sPeriod != K_PRMT_sEMPTY)
  912. {
  913. sPeriod = "P" + sPeriod;
  914. //if the interval is negative, prepend with the minus sign
  915. if (this.m_bNegative == true)
  916. {
  917. sPeriod = g_minusSign + sPeriod;
  918. }
  919. }
  920. return sPeriod;
  921. }
  922. function CIntervalPicker_parseXSDIntervalValue(s)
  923. {
  924. var parseString = s;
  925. var iYearVal = 0;
  926. var iMonthVal = 0;
  927. var iDayVal = 0;
  928. var iDays = 0;
  929. var iHourVal = 0;
  930. var iMinuteVal = 0;
  931. var iSecondVal = 0;
  932. var iMillisecondVal = 0;
  933. //is the negative symbol there?
  934. //search for a negative value
  935. var z = parseString.search(rMinusSign);
  936. if (z == -1)
  937. {
  938. this.m_bNegative = false;
  939. }
  940. else
  941. {
  942. this.m_bNegative = true;
  943. //strip of the minus sign
  944. parseString = parseString.replace(rMinusSign, K_PRMT_sEMPTY);
  945. }
  946. //is the prefix P there?
  947. var iPeriodSymbolPosition = parseString.indexOf('P');
  948. if (iPeriodSymbolPosition != -1)
  949. {
  950. //remove the P and a minus if necessary
  951. parseString = parseString.substring(iPeriodSymbolPosition + 1);
  952. var iTimeSymbolPosition = parseString.indexOf('T');
  953. //split into date and time portions
  954. var parseArray = parseString.split ('T');
  955. if (((parseArray.length > 0) && (iTimeSymbolPosition > 0)) || (iTimeSymbolPosition == -1))
  956. {
  957. //Deal with date
  958. //nYnMnD
  959. //convert years to days
  960. var iYearPos = parseArray[0].indexOf('Y');
  961. if (iYearPos != -1)
  962. {
  963. iYearVal = parseInt(parseArray[0].substring(currentPos, iYearPos),10);
  964. parseArray[0] = parseArray[0].substring(iYearPos+1);
  965. }
  966. //convert months to days
  967. var iMonthPos = parseArray[0].indexOf('M');
  968. if (iMonthPos != -1)
  969. {
  970. iMonthVal = parseInt(parseArray[0].substring(0, iMonthPos),10);
  971. parseArray[0] = parseArray[0].substring(iMonthPos+1);
  972. }
  973. //add days
  974. var iDayPos = parseArray[0].indexOf('D');
  975. if (iDayPos != -1)
  976. {
  977. iDayVal = parseInt(parseArray[0].substring(0, iDayPos),10);
  978. }
  979. //ToDo: get the correct conversion
  980. iDays = (iYearVal * 365) + (iMonthVal * 30) + iDayVal;
  981. }
  982. else
  983. {
  984. //set date to zero
  985. iDays = 0;
  986. }
  987. //Deal with time
  988. if ((parseArray.length == 2) || (iTimeSymbolPosition != -1))
  989. {
  990. var iArrayObj = parseArray.length - 1;
  991. //TnHnMnS
  992. //get hours
  993. //convert years to days
  994. var iHourPos = parseArray[iArrayObj].indexOf('H');
  995. if (iHourPos != -1)
  996. {
  997. iHourVal = parseInt(parseArray[iArrayObj].substring(0, iHourPos),10);
  998. parseArray[iArrayObj] = parseArray[iArrayObj].substring(iHourPos + 1);
  999. }
  1000. //get minutes
  1001. var iMinutePos = parseArray[iArrayObj].indexOf('M');
  1002. if (iMinutePos != -1)
  1003. {
  1004. iMinuteVal = parseInt(parseArray[iArrayObj].substring(0, iMinutePos),10);
  1005. parseArray[iArrayObj] = parseArray[iArrayObj].substring(iMinutePos +1);
  1006. }
  1007. //get seconds
  1008. //get Milliseconds
  1009. var iSecondPos = parseArray[iArrayObj].indexOf('S');
  1010. if (iSecondPos != -1)
  1011. {
  1012. //split on . to separate seconds and milliseconds
  1013. var decimalPosition = parseArray[iArrayObj].indexOf(K_PRMT_sDOT);
  1014. var secondArray = parseArray[iArrayObj].substring(0, iSecondPos).split(K_PRMT_sDOT);
  1015. if ((secondArray.length == 2) || (decimalPosition == -1))
  1016. {
  1017. iSecondVal = parseInt(secondArray[0],10);
  1018. }
  1019. if ((secondArray.length == 2) || (decimalPosition != -1))
  1020. {
  1021. iMillisecondVal = parseInt(secondArray[secondArray.length - 1],10);
  1022. }
  1023. }
  1024. }
  1025. //create the interval
  1026. this.m_iDays = iDays;
  1027. this.m_iHours = iHourVal;
  1028. this.m_iMinutes = iMinuteVal;
  1029. this.m_iSeconds = iSecondVal;
  1030. this.m_iMilliseconds = iMillisecondVal;
  1031. }
  1032. }
  1033. function CIntervalPicker_iConvertMonthToDays()
  1034. {
  1035. //not entirely accurate, but without the month and year
  1036. //it's impossible to tell
  1037. return 30;
  1038. }
  1039. function CIntervalPicker_hasValue()
  1040. {
  1041. if ((this.m_iDays != null) || (this.m_iHours != null) ||
  1042. (this.m_iMinutes != null) || (this.m_iSeconds != null) ||
  1043. (this.m_iMilliseconds != null))
  1044. {
  1045. return true;
  1046. }
  1047. return false;
  1048. }
  1049. //test to see if a string contains a negative
  1050. function CIntervalPicker_bIsNegative(s)
  1051. {
  1052. if (s == null)
  1053. {
  1054. return false;
  1055. }
  1056. //search for a negative value
  1057. var z = s.toString().search(rMinusSign);
  1058. if (z == -1)
  1059. {
  1060. return false;
  1061. }
  1062. return true;
  1063. }
  1064. //return a string with the minus sign removed
  1065. function CIntervalPicker_sStripNegative(s)
  1066. {
  1067. if (s != null)
  1068. {
  1069. return s.toString().replace(rMinusSign, K_PRMT_sEMPTY);
  1070. }
  1071. return K_PRMT_sEMPTY;
  1072. }
  1073. //user has left a field in the interval control
  1074. function CIntervalPicker_lostFocus()
  1075. {
  1076. }
  1077. //Prototypes to assign methods to new instances of the object
  1078. CIntervalPicker.prototype.draw = CIntervalPicker_draw;
  1079. CIntervalPicker.prototype.updateFormField = CIntervalPicker_updateFormField;
  1080. CIntervalPicker.prototype.keyPress = CIntervalPicker_keyPress;
  1081. CIntervalPicker.prototype.checkInterval = CIntervalPicker_checkInterval;
  1082. CIntervalPicker.prototype.checkDay = CIntervalPicker_checkDay;
  1083. CIntervalPicker.prototype.checkHour = CIntervalPicker_checkHour;
  1084. CIntervalPicker.prototype.checkMinute = CIntervalPicker_checkMinute;
  1085. CIntervalPicker.prototype.checkSecond = CIntervalPicker_checkSecond;
  1086. CIntervalPicker.prototype.checkMillisecond = CIntervalPicker_checkMillisecond;
  1087. CIntervalPicker.prototype.bcheckNumber = CIntervalPicker_bcheckNumber;
  1088. CIntervalPicker.prototype.checkIntervalPass = CIntervalPicker_checkIntervalPass;
  1089. CIntervalPicker.prototype.checkIntervalFail = CIntervalPicker_checkIntervalFail;
  1090. CIntervalPicker.prototype.sGetInterval = CIntervalPicker_sGetInterval;
  1091. CIntervalPicker.prototype.sGetFormatInterval = CIntervalPicker_sGetFormatInterval;
  1092. CIntervalPicker.prototype.checkData= CIntervalPicker_checkData;
  1093. CIntervalPicker.prototype.preProcess = CIntervalPicker_preProcess;
  1094. CIntervalPicker.prototype.sGetFormatValue = CIntervalPicker_sGetFormatValue;
  1095. CIntervalPicker.prototype.sGetValue = CIntervalPicker_sGetValue;
  1096. CIntervalPicker.prototype.sGetXSDValue = CIntervalPicker_sGetXSDValue;
  1097. CIntervalPicker.prototype.parseXSDIntervalValue = CIntervalPicker_parseXSDIntervalValue;
  1098. CIntervalPicker.prototype.iConvertMonthToDays = CIntervalPicker_iConvertMonthToDays;
  1099. CIntervalPicker.prototype.hasValue = CIntervalPicker_hasValue;
  1100. CIntervalPicker.prototype.bIsNegative = CIntervalPicker_bIsNegative;
  1101. CIntervalPicker.prototype.sStripNegative = CIntervalPicker_sStripNegative;
  1102. CIntervalPicker.prototype.lostFocus = CIntervalPicker_lostFocus;
  1103. CIntervalPicker.prototype.startCheckDataInterval = CIntervalPicker_startCheckDataInterval;
  1104. CIntervalPicker.prototype.endCheckDataInterval = CIntervalPicker_endCheckDataInterval;
  1105. CIntervalPicker.prototype.checkValueChange = CIntervalPicker_checkValueChange;
  1106. //create regular expressions for parsing with current locale
  1107. function initIntervalRegularExpressions()
  1108. {
  1109. rMinusSign = new RegExp(sEscapeRegularExpression(g_minusSign), K_PRMT_sG);
  1110. }
  1111. var g_minusSign = "-";
  1112. var rMinusSign = new RegExp(g_minusSign, K_PRMT_sG);