CDatePickerDialogIE5.js 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2021
  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. CDatePickerDialogIE5.js
  14. This script defines the properties and methods available to a popup dialog picker
  15. for the Date prompt control.
  16. */
  17. //Constructor to create a new Date Picker Dialog / inline calendar
  18. // oDialog: the id of html container for the date picker
  19. // oParentControl: the Date Picker object
  20. // sRef: string, the name of the parent object
  21. // bInline: boolean, 0= popup , 1= inline calendar
  22. // iType: integer, 0= gregorian, 1= japanese imperial
  23. // iStartOfWeek: start day of the week. sunday = 1, monday = 2, ..., saturday = 7
  24. function CDatePickerDialog(oDialog, oParentControl, sRef, bInline, iType, iStartOfWeek, sCVId, popupZIndex)
  25. {
  26. this.setCVId(sCVId);
  27. if (popupZIndex == null){
  28. this.popupZIndex="115";
  29. } else {
  30. this.popupZIndex = popupZIndex;
  31. }
  32. //the html dialog
  33. this.m_oDialog = oDialog;
  34. //the iframe
  35. this.m_iFrame = (browserIsNS7() ? null : document.getElementById("pickerControl" + sRef +"iframe"));
  36. //the parent control
  37. this.m_oParentControl = oParentControl;
  38. this.m_sRef = sRef; // the unique id appended to the each object
  39. this.m_oYearWidget = document.getElementById("myYear" + this.m_sRef);
  40. //is the control to be: rendered on the page (inline=1)
  41. //or as a popup (inline=0)
  42. this.m_bInline = bInline;
  43. //determine browser for DHTML type
  44. this.m_isNS7 = browserIsNS7();
  45. //draw the localized months
  46. this.initMonths();
  47. //sunday = 1, monday = 2, ..., saturday = 7
  48. this.m_iStartOfWeek = iStartOfWeek;
  49. //draw the days of the week in the order specified
  50. this.initDays();
  51. //store the user selection, so that they can navigate through
  52. //months in a natural way, as months have different end days
  53. this.m_iUserDay = this.m_oParentControl.m_dDate.getDate();
  54. this.m_iType = iType;
  55. //will be used to store event listeners on the days.
  56. this.m_aHandles = [];
  57. if (!this.m_bInline)
  58. {
  59. this.m_oDialog.style.position = "absolute";
  60. this.m_oDialog.style.display = "none";
  61. this.m_oDialog.style.zIndex = this.popupZIndex;
  62. var v_divPicker = document.getElementById("dialogDatePicker" + this.m_sRef);
  63. if (v_divPicker)
  64. {
  65. PRMTUtils.f_addEvent( v_divPicker, "click",
  66. function(v_oEvent){
  67. PRMTUtils.F_StopEvent(v_oEvent);
  68. }
  69. );
  70. }
  71. if (document && document.body && (!document.body.oDatePickerHandler || document.body.oDatePickerHandler[sCVId]!== true))
  72. {
  73. if (!document.body.oDatePickerHandler) {
  74. document.body.oDatePickerHandler = [sCVId];
  75. }
  76. var aDatePickersObservers = this.getObserverArray('datePickerObserverArray');
  77. document.body.oDatePickerHandler[sCVId] = true;
  78. PRMTUtils.f_addEvent( document.body, "click",
  79. function(v_oEvent){
  80. v_oEvent = (v_oEvent ? v_oEvent : event);
  81. var v_oTarget = (v_oEvent.target ? v_oEvent.target : v_oEvent.srcElement);
  82. if ( !(v_oTarget && v_oTarget.tagName == "IMG" && v_oTarget.src && v_oTarget.src.match(/icon_datepicker.gif/i)) )
  83. {
  84. datePickerObserverNotify(aDatePickersObservers);
  85. }
  86. }
  87. );
  88. }
  89. }
  90. else
  91. {
  92. //refresh the date
  93. this.refreshDate(this.m_oParentControl.m_dDate);
  94. this.m_oDialog.style.visibility = "inherit";
  95. }
  96. }
  97. CDatePickerDialog.prototype = new CPromptControl();
  98. //show and hide the dialog
  99. function CDatePickerDialog_toggleDatePicker()
  100. {
  101. //an iframe is used to prevent HTML controls from bleeding through the dialogs (IE only).
  102. var v_elIFrame = this.m_iFrame;
  103. //show the dialog if not already visible
  104. if ( this.isVisible() )
  105. {
  106. this.m_oDialog.style.display = "none";
  107. this.m_oDialog.style.zIndex = "1";
  108. if ( v_elIFrame !== null )
  109. {
  110. v_elIFrame.style.display = "none";
  111. }
  112. }
  113. else
  114. {
  115. //notify any date pickers that may already be open
  116. datePickerObserverNotify();
  117. //show the dialog
  118. this.m_oDialog.style.display = "inline";
  119. this.m_oDialog.style.zIndex = this.popupZIndex;
  120. var sId = "btnYearDown" + this.m_sRef;
  121. var focusEl = document.getElementById(sId);
  122. if (focusEl != null){
  123. window.setTimeout("document.getElementById('" + sId + "').focus();", 500);
  124. }
  125. //IE 5.0 has opaque iframes, for IE5.5 and above,
  126. //the iframe can be used to mask components that
  127. //bleed through a div element
  128. if (v_elIFrame !== null && typeof v_elIFrame.allowTransparency != K_PRMT_sUNDEFINED)
  129. {
  130. //move the iframe
  131. this.resizeIframe(v_elIFrame, this.m_oDialog);
  132. v_elIFrame.style.zIndex = "1";
  133. v_elIFrame.style.display = "inline";
  134. }
  135. }
  136. }
  137. //hide the dialog
  138. function CDatePickerDialog_hidePicker()
  139. {
  140. var v_iframe = this.m_iFrame;
  141. this.m_oDialog.style.display = "none";
  142. //an iframe is used to prevent HTML controls from bleeding through the dialogs
  143. if ( v_iframe !== null && v_iframe.style )
  144. {
  145. v_iframe.style.display = "none";
  146. }
  147. }
  148. function CDatePickerDialog_isVisible()
  149. {
  150. return ( this.m_oDialog.style.display == "inline" );
  151. }
  152. //render the control with a new date
  153. function CDatePickerDialog_refreshDate(dNewDate)
  154. {
  155. if (!dNewDate)
  156. {
  157. //if there is no date, default to today date
  158. var d = new Date();
  159. dNewDate = d;
  160. this.m_oParentControl.m_dDate = d;
  161. }
  162. //calculate the number of days in the month and see
  163. //if the user selection is valid
  164. var iMaxDays = intGetDays(dNewDate.getMonth(), dNewDate.getFullYear());
  165. this.m_iUserDay = dNewDate.getDate();
  166. if (this.m_iUserDay > iMaxDays)
  167. {
  168. dNewDate.setDate(iMaxDays);
  169. }
  170. else
  171. {
  172. dNewDate.setDate(this.m_iUserDay);
  173. }
  174. // 0 = standard ; 1 = japaneseEmperor
  175. if (this.m_iType == 1)
  176. {
  177. this.drawEmperorYear(dNewDate);
  178. }
  179. else
  180. {
  181. this.drawYear(dNewDate);
  182. }
  183. this.refreshPickerLayout(dNewDate);
  184. }
  185. function CDatePickerDialog_refreshPickerLayout(dNewDate)
  186. {
  187. //update the form control
  188. this.m_oParentControl.updateFormVariable(this.m_oParentControl.m_oForm, dNewDate);
  189. this.clearMonths();
  190. this.clearDays();
  191. this.drawMonth(dNewDate.getMonth());
  192. this.drawDays(dNewDate);
  193. this.refreshPickerIFrame();
  194. }
  195. function CDatePickerDialog_refreshPickerIFrame()
  196. {
  197. if (this.m_iFrame !== null)
  198. {
  199. //an iframe is used to prevent HTML controls from bleeding through the dialogs
  200. this.resizeIframe(this.m_iFrame, this.m_oDialog);
  201. }
  202. }
  203. //increment the year by 1
  204. function CDatePickerDialog_yearUp()
  205. {
  206. var dNewDate = new Date ();
  207. dNewDate.setDate(1);
  208. dNewDate.setMonth(this.m_oParentControl.m_dDate.getMonth());
  209. var sCurYear = this.m_oParentControl.m_dDate.getFullYear();
  210. dNewDate.setFullYear(sCurYear +1);
  211. //check the number of days in the month
  212. var iMaxDays = intGetDays(dNewDate.getMonth(), dNewDate.getFullYear());
  213. if (this.m_iUserDay > iMaxDays)
  214. {
  215. dNewDate.setDate(iMaxDays);
  216. }
  217. else
  218. {
  219. dNewDate.setDate(this.m_iUserDay);
  220. }
  221. //enforce first and last dates
  222. //check to see if this date less than the first date
  223. //if so, then this is not a valid date
  224. if (this.m_oParentControl.m_dFirstDate)
  225. {
  226. if (bIsDateEarlier(dNewDate, this.m_oParentControl.m_dFirstDate) === true)
  227. {
  228. return;
  229. }
  230. }
  231. //check to see if this date is greater than the last date
  232. //if so, then this is not a valid date
  233. if (this.m_oParentControl.m_dLastDate)
  234. {
  235. if (bIsDateLater(dNewDate, this.m_oParentControl.m_dLastDate) === true)
  236. {
  237. //if the years are the same then see if a new month and day should be picked
  238. if (dNewDate.getYear() == this.m_oParentControl.m_dLastDate.getYear())
  239. {
  240. dNewDate.setMonth(this.m_oParentControl.m_dLastDate.getMonth());
  241. dNewDate.setDate(this.m_oParentControl.m_dLastDate.getDate());
  242. }
  243. else
  244. {
  245. return;
  246. }
  247. }
  248. }
  249. //update the date
  250. this.m_oParentControl.m_dDate = dNewDate;
  251. //redraw the dialog
  252. this.refreshDate(this.m_oParentControl.m_dDate);
  253. //repaint date control
  254. this.m_oParentControl.drawDate();
  255. //update the parent control and check the date
  256. this.m_oParentControl.checkDate(this.m_oParentControl.m_oEditBox);
  257. }
  258. //increment the year down by 1
  259. function CDatePickerDialog_yearDown()
  260. {
  261. var dNewDate = new Date ();
  262. dNewDate.setDate(1);
  263. dNewDate.setMonth(this.m_oParentControl.m_dDate.getMonth());
  264. var sCurYear = this.m_oParentControl.m_dDate.getFullYear();
  265. //Do not do decrease the year by 1 if it's already 0.
  266. if (parseInt(sCurYear, 10) <= 0)
  267. {
  268. return;
  269. }
  270. dNewDate.setFullYear(sCurYear -1);
  271. var iMaxDays = intGetDays(dNewDate.getMonth(), dNewDate.getFullYear());
  272. if (this.m_iUserDay > iMaxDays)
  273. {
  274. dNewDate.setDate(iMaxDays);
  275. }
  276. else
  277. {
  278. dNewDate.setDate(this.m_iUserDay);
  279. }
  280. //enforce first and last dates
  281. //check to see if this date less than the first date
  282. //if so, then this is not a valid date
  283. if (this.m_oParentControl.m_dFirstDate)
  284. {
  285. if (bIsDateEarlier(dNewDate, this.m_oParentControl.m_dFirstDate) === true)
  286. {
  287. if (bIsDateEarlier(dNewDate, this.m_oParentControl.m_dFirstDate) === true)
  288. {
  289. //if the years are the same then see if a new month and day should be picked
  290. if (dNewDate.getYear() == this.m_oParentControl.m_dFirstDate.getYear())
  291. {
  292. dNewDate.setMonth(this.m_oParentControl.m_dFirstDate.getMonth());
  293. dNewDate.setDate(this.m_oParentControl.m_dFirstDate.getDate());
  294. }
  295. else
  296. {
  297. return;
  298. }
  299. }
  300. }
  301. }
  302. //check to see if this date is greater than the last date
  303. //if so, then this is not a valid date
  304. if (this.m_oParentControl.m_dLastDate)
  305. {
  306. if (bIsDateLater(dNewDate, this.m_oParentControl.m_dLastDate) === true)
  307. {
  308. return;
  309. }
  310. }
  311. //update the date
  312. this.m_oParentControl.m_dDate = dNewDate;
  313. //redraw the dialog
  314. this.refreshDate(this.m_oParentControl.m_dDate);
  315. //repaint date control
  316. this.m_oParentControl.drawDate();
  317. //update the parent control and check the date
  318. this.m_oParentControl.checkDate(this.m_oParentControl.m_oEditBox);
  319. }
  320. //initialize the months
  321. function CDatePickerDialog_initMonths()
  322. {
  323. for(var i=0;i<12;i++)
  324. {
  325. var idMonthWidget = this.m_sRef+"m"+i;
  326. var oMonthWidget = document.getElementById(idMonthWidget);
  327. oMonthWidget.innerHTML = sGetMonth(i);
  328. }
  329. }
  330. //initialize the days
  331. function CDatePickerDialog_initDays()
  332. {
  333. //there are 7 spots for the days
  334. //start from the startDayOffset, then wrap to finish the beginning
  335. //convert to the start from zero to properly access the array.
  336. var iDayOfWeek = this.m_iStartOfWeek -1;
  337. var idDayWidget = null;
  338. var oDayWidget = null;
  339. for(var i=0;i + iDayOfWeek < 7 ;i++)
  340. {
  341. var iDayOffset = i + iDayOfWeek;
  342. idDayWidget = this.m_sRef+"d"+i;
  343. oDayWidget = document.getElementById(idDayWidget);
  344. oDayWidget.innerHTML = sGetDay(iDayOffset);
  345. }
  346. for (i=0; i < iDayOfWeek; i++)
  347. {
  348. idDayWidget = this.m_sRef+"d"+(7 - iDayOfWeek + i);
  349. oDayWidget = document.getElementById(idDayWidget);
  350. oDayWidget.innerHTML = sGetDay(i);
  351. }
  352. }
  353. //Draw the year in the standard way
  354. function CDatePickerDialog_drawYear(dNewDate)
  355. {
  356. var sYear = dNewDate.getFullYear();
  357. sYear = "0000" + sYear;
  358. sYear = sYear.substring(sYear.length-4, sYear.length);
  359. this.m_oYearWidget.value = sYear;
  360. }
  361. //draw the year in Japanese Emperor Time
  362. function CDatePickerDialog_drawEmperorYear(dNewDate)
  363. {
  364. var sEmperorYear = getJapaneseEra (dNewDate);
  365. this.m_oYearWidget.value = sEmperorYear;
  366. }
  367. //change the month
  368. function CDatePickerDialog_newMonth(iMonth)
  369. {
  370. //check the number of days in the month
  371. var iMaxDays = intGetDays(iMonth, this.m_oParentControl.m_dDate.getFullYear());
  372. var useDay;
  373. if (this.m_iUserDay > iMaxDays)
  374. {
  375. useDay = iMaxDays;
  376. }
  377. else
  378. {
  379. useDay = this.m_iUserDay;
  380. }
  381. //set the day and month after the day is taken care of
  382. var dNewDate = new Date (this.m_oParentControl.m_dDate.getFullYear(), iMonth, useDay);
  383. //set the year using the function "setFullYear" to completely make sure correct year is set for dNewDate
  384. dNewDate.setFullYear(this.m_oParentControl.m_dDate.getFullYear());
  385. //enforce first and last dates
  386. //check to see if this date less than the first date
  387. //if so, then this is not a valid date
  388. if (this.m_oParentControl.m_dFirstDate)
  389. {
  390. if (bIsDateEarlier(dNewDate, this.m_oParentControl.m_dFirstDate) === true)
  391. {
  392. //if the months are the same then see if a new day should be picked
  393. if (dNewDate.getMonth() == this.m_oParentControl.m_dFirstDate.getMonth())
  394. {
  395. var testDay = this.m_oParentControl.m_dFirstDate.getDate();
  396. if ((useDay < testDay) && (testDay <= iMaxDays))
  397. {
  398. dNewDate.setDate(testDay);
  399. }
  400. }
  401. else
  402. {
  403. return;
  404. }
  405. }
  406. }
  407. //check to see if this date is greater than the last date
  408. //if so, then this is not a valid date
  409. if (this.m_oParentControl.m_dLastDate)
  410. {
  411. if (bIsDateLater(dNewDate, this.m_oParentControl.m_dLastDate) === true)
  412. {
  413. //if the months are the same then see if a new day should be picked
  414. if (dNewDate.getMonth() == this.m_oParentControl.m_dLastDate.getMonth())
  415. {
  416. var testDay = this.m_oParentControl.m_dLastDate.getDate();
  417. if ((useDay > testDay) && (testDay <= iMaxDays))
  418. {
  419. dNewDate.setDate(testDay);
  420. }
  421. }
  422. else
  423. {
  424. return;
  425. }
  426. }
  427. }
  428. this.m_oParentControl.m_dDate = dNewDate;
  429. //redraw the control
  430. this.refreshDate(this.m_oParentControl.m_dDate);
  431. //update the parent control
  432. this.m_oParentControl.drawDate();
  433. //update the parent control and check the date
  434. this.m_oParentControl.checkDate(this.m_oParentControl.m_oEditBox);
  435. }
  436. //clear the months
  437. function CDatePickerDialog_clearMonths()
  438. {
  439. var iCurMonth=0;
  440. for (iCurMonth=0; iCurMonth <12; iCurMonth++)
  441. {
  442. var idCurMonthWidget = this.m_sRef+"m"+iCurMonth;
  443. //reset element
  444. document.getElementById(idCurMonthWidget).className = "clsSelectDateMonths pm";
  445. }
  446. }
  447. //render the selected month
  448. function CDatePickerDialog_drawMonth(iMonth)
  449. {
  450. //are there days in this month that might be
  451. //too early or too late
  452. var bValuesEarlier = false;
  453. var bValuesLater = false;
  454. var currentYear = this.m_oParentControl.m_dDate.getFullYear();
  455. if (this.m_oParentControl.m_dFirstDate)
  456. {
  457. if (currentYear <= this.m_oParentControl.m_dFirstDate.getFullYear())
  458. {
  459. bValuesEarlier = true;
  460. }
  461. }
  462. if (this.m_oParentControl.m_dLastDate)
  463. {
  464. if (currentYear >= this.m_oParentControl.m_dLastDate.getFullYear())
  465. {
  466. bValuesLater = true;
  467. }
  468. }
  469. //loop through the table
  470. for (var c = 0; c < 12; c++)
  471. {
  472. var iMonthWidget = this.m_sRef+"m"+c;
  473. // make bold if this is the current month
  474. if (iMonth == c)
  475. {
  476. document.getElementById(iMonthWidget).className = "clsSelectDateMonthsSelected pms";
  477. document.getElementById(iMonthWidget).setAttribute("aria-selected","true");
  478. document.getElementById(iMonthWidget).setAttribute("tabindex","0");
  479. document.getElementById(iMonthWidget).setAttribute("role","option");
  480. }
  481. //if the current year is less than or equal to the first year
  482. //then we have to worry about some months that may not be valid
  483. //get the number of days for each month and compare with the first date
  484. else if ((bValuesEarlier === true) && ( bIsDateEarlier(new Date(currentYear, c, intGetDays(c, currentYear)), this.m_oParentControl.m_dFirstDate) === true ))
  485. {
  486. document.getElementById(iMonthWidget).className = "clsSelectDateMonthsDisabled pmd";
  487. document.getElementById(iMonthWidget).setAttribute("aria-selected","false");
  488. document.getElementById(iMonthWidget).setAttribute("tabindex","0");
  489. document.getElementById(iMonthWidget).setAttribute("role","option");
  490. }
  491. else if ((bValuesLater === true) && (bIsDateLater(new Date(currentYear, c, 1), this.m_oParentControl.m_dLastDate) === true ))
  492. {
  493. document.getElementById(iMonthWidget).className = "clsSelectDateMonthsDisabled pmd";
  494. document.getElementById(iMonthWidget).setAttribute("aria-selected","false");
  495. document.getElementById(iMonthWidget).setAttribute("tabindex","0");
  496. document.getElementById(iMonthWidget).setAttribute("role","option");
  497. }
  498. else
  499. {
  500. document.getElementById(iMonthWidget).className = "clsSelectDateMonths pm";
  501. document.getElementById(iMonthWidget).setAttribute("aria-selected","false");
  502. document.getElementById(iMonthWidget).setAttribute("tabindex","0");
  503. document.getElementById(iMonthWidget).setAttribute("role","option");
  504. }
  505. }
  506. }
  507. //change the day
  508. function CDatePickerDialog_newDay(oDayObj)
  509. {
  510. var iNewDay = parseInt(oDayObj.innerHTML,10);
  511. //check to see if this is a valid day
  512. if (!isNaN(iNewDay))
  513. {
  514. //update the user selection
  515. this.m_iUserDay = iNewDay;
  516. var dNewDate = new Date ();
  517. dNewDate.setDate(1);
  518. dNewDate.setMonth(this.m_oParentControl.m_dDate.getMonth());
  519. dNewDate.setFullYear(this.m_oParentControl.m_dDate.getFullYear());
  520. dNewDate.setDate(iNewDay);
  521. //enforce first and last dates
  522. //check to see if this date less than the first date
  523. //if so, then this is not a valid date
  524. if (this.m_oParentControl.m_dFirstDate)
  525. {
  526. if (bIsDateEarlier(dNewDate, this.m_oParentControl.m_dFirstDate) === true)
  527. {
  528. return;
  529. }
  530. }
  531. //check to see if this date is greater than the last date
  532. //if so, then this is not a valid date
  533. if (this.m_oParentControl.m_dLastDate)
  534. {
  535. if (bIsDateLater(dNewDate, this.m_oParentControl.m_dLastDate) === true)
  536. {
  537. return;
  538. }
  539. }
  540. //update the date
  541. this.m_oParentControl.m_dDate = dNewDate;
  542. this.refreshDate(this.m_oParentControl.m_dDate);
  543. //update the parent control
  544. this.m_oParentControl.drawDate();
  545. //toggle the picker control if it is a popup control
  546. if (!this.m_bInline)
  547. {
  548. this.hidePicker();
  549. window.setTimeout("document.getElementById('txtDate" + this.m_sRef +"').focus();",500);
  550. }
  551. }
  552. //update the parent control and check the date
  553. this.m_oParentControl.checkDate(this.m_oParentControl.m_oEditBox);
  554. }
  555. function CDatePickerDialog_drawDays(dCurDate)
  556. {
  557. //clear the days before drawing new days
  558. this.clearDays();
  559. //determine the day of the week the month starts on
  560. var dBeginDay = new Date (dCurDate.getFullYear(),dCurDate.getMonth(),1);
  561. //Sunday is 0, Monday is 1, Saturday is 6
  562. var iBeginDayDate = dBeginDay.getDay();
  563. //calculate the number of days in the month
  564. var iCountDay = intGetDays(dCurDate.getMonth(), dCurDate.getFullYear());
  565. var iTestDay = dCurDate.getDate();
  566. //define counters
  567. var i=0;
  568. var j=0;
  569. //figure out what slot to start the month in
  570. var iStartCell = iBeginDayDate - this.m_iStartOfWeek + 1;
  571. if ( iStartCell > 0 )
  572. {
  573. i = iStartCell;
  574. }
  575. else if ( iStartCell === 0)
  576. {
  577. i = 0;
  578. }
  579. else
  580. {
  581. i = 7 + iStartCell;
  582. }
  583. //are there days in this month that might be
  584. //too early or too late
  585. var bValuesEarlier = false;
  586. var bValuesLater = false;
  587. if (this.m_oParentControl.m_dFirstDate)
  588. {
  589. if (bIsDateEarlier(dBeginDay, this.m_oParentControl.m_dFirstDate) === true)
  590. {
  591. bValuesEarlier = true;
  592. }
  593. }
  594. var dEndDay = new Date (dCurDate.getFullYear(),dCurDate.getMonth(),iCountDay);
  595. //check to see if this date is greater than the last date
  596. //if so, then this is not a valid date
  597. if (this.m_oParentControl.m_dLastDate)
  598. {
  599. if (bIsDateLater(dEndDay, this.m_oParentControl.m_dLastDate) === true)
  600. {
  601. bValuesLater = true;
  602. }
  603. }
  604. //loop through the table
  605. var oColumnName;
  606. var idCurDayWidget;
  607. var firstStart = true;
  608. for (var c=1;c < iCountDay +1;c++)
  609. {
  610. //determine the correct column
  611. if ( this.m_isNS7 )
  612. {
  613. idCurDayWidget = this.m_sRef+"r"+j+"c"+i;
  614. oColumnName = document.getElementById(idCurDayWidget);
  615. }
  616. else
  617. {
  618. if ( i === 0 || firstStart )
  619. {
  620. idCurDayWidget = this.m_sRef+"r"+j+"c"+i;
  621. oColumnName = document.getElementById(idCurDayWidget);
  622. }
  623. else
  624. {
  625. oColumnName = oColumnName.nextSibling;
  626. }
  627. firstStart = false;
  628. }
  629. oColumnName.innerHTML = c;
  630. oColumnName.setAttribute("role","option");
  631. oColumnName.setAttribute("aria-describedby",this.m_sRef + "d" + i);
  632. this.addEventListenerForDay(oColumnName, "mousedown", this.newDay.bind(this, oColumnName));
  633. var calendarComp=this;
  634. if (c == iCountDay) {
  635. this.addEventListenerForDay( oColumnName, "keydown",function (e) {if ((e.keyCode == 9)&&(!e.shiftKey)){if (calendarComp.checkTabFocus(this)){PRMTUtils.F_StopEvent(e);}} else if ((e.keyCode == 13) || (e.keyCode == 32)) {calendarComp.newDay(this);}});
  636. } else {
  637. this.addEventListenerForDay( oColumnName, "keydown",function (e) {if ((e.keyCode == 13) || (e.keyCode == 32)) {calendarComp.newDay(this);}});
  638. }
  639. oColumnName.setAttribute("tabindex","0");
  640. //shade the selected color
  641. if (c == iTestDay)
  642. {
  643. oColumnName.className = "clsSelectDateDaysSelected pds";
  644. oColumnName.setAttribute("aria-selected", "true");
  645. }
  646. //check to see if the day is in the valid range
  647. else if ((bValuesEarlier === true) && (c < this.m_oParentControl.m_dFirstDate.getDate()))
  648. {
  649. oColumnName.className = "clsSelectDateDaysDisabled pdd";
  650. oColumnName.setAttribute("aria-selected", "false");
  651. oColumnName.setAttribute("tabindex", "0");
  652. oColumnName.setAttribute("role", "option");
  653. }
  654. else if ((bValuesLater === true) && (c > this.m_oParentControl.m_dLastDate.getDate()))
  655. {
  656. oColumnName.className = "clsSelectDateDaysDisabled pdd";
  657. oColumnName.setAttribute("aria-selected", "false");
  658. oColumnName.setAttribute("tabindex", "0");
  659. oColumnName.setAttribute("role", "option");
  660. }
  661. else
  662. {
  663. oColumnName.className = "clsSelectDateDays pd";
  664. oColumnName.setAttribute("aria-selected", "false");
  665. oColumnName.setAttribute("tabindex", "0");
  666. oColumnName.setAttribute("role", "option");
  667. }
  668. //increment the day counter
  669. i++;
  670. //check to see if finished the row
  671. if (i==7){i=0;j++;}
  672. }
  673. }
  674. //remove the days from the calendar picker
  675. function CDatePickerDialog_clearDays()
  676. {
  677. var idCurDayWidget;
  678. var oColumnName;
  679. var curWeek;
  680. if ( !this.m_isNS7 )
  681. {
  682. idCurDayWidget = this.m_sRef+"r"+0+"c"+0;
  683. oColumnName = document.getElementById(idCurDayWidget);
  684. curWeek = oColumnName.parentElement;
  685. }
  686. // RTC Story 373917 [Web a11y] Make the Date prompt accessible
  687. // Must remove the event handlers so that they do not get regisered multiple times
  688. this.removeEventListenersFromDays();
  689. var i = 0;
  690. for(var j=0;j<6;j++)
  691. {
  692. if ( this.m_isNS7 )
  693. {
  694. for(i=0;i<7;i++)
  695. {
  696. idCurDayWidget = this.m_sRef+"r"+j+"c"+i;
  697. oColumnName = document.getElementById(idCurDayWidget);
  698. oColumnName.removeAttribute("tabindex");
  699. oColumnName.removeAttribute("role");
  700. oColumnName.removeAttribute("aria-selected");
  701. oColumnName.innerHTML = K_PRMT_sEMPTY;
  702. oColumnName.className = "clsSelectDate";
  703. }
  704. }
  705. else
  706. {
  707. var aDay = curWeek.firstChild;
  708. for(i=0;i<7;i++)
  709. {
  710. aDay.innerHTML = K_PRMT_sEMPTY;
  711. aDay.className = "clsSelectDate";
  712. aDay = aDay.nextSibling;
  713. }
  714. curWeek = curWeek.nextSibling;
  715. }
  716. }
  717. }
  718. function CDatePickerDialog_addEventListenerForDay(v_oElement, v_sEvent, v_fnListener)
  719. {
  720. if ( v_oElement )
  721. {
  722. if ( v_oElement.addEventListener )
  723. {
  724. v_oElement.addEventListener( v_sEvent, v_fnListener, false );
  725. this.m_aHandles.push({remove: function() { v_oElement.removeEventListener(v_sEvent, v_fnListener, false); }});
  726. }
  727. else
  728. {
  729. v_oElement.attachEvent( 'on' + v_sEvent, v_fnListener );
  730. this.m_aHandles.push({remove: function() { v_oElement.detachEvent('on' + v_sEvent, v_fnListener); }});
  731. }
  732. }
  733. }
  734. function CDatePickerDialog_removeEventListenersFromDays()
  735. {
  736. while (this.m_aHandles.length > 0)
  737. {
  738. var v_oHandle = this.m_aHandles.pop();
  739. v_oHandle.remove();
  740. }
  741. }
  742. //render the check date pass state
  743. function CDatePickerDialog_checkDatePass(oEditBox)
  744. {
  745. oEditBox.className = "clsSelectDateYearEditBox";
  746. this.m_oParentControl.checkDatePass(null);
  747. this.notify(gPASS, this);
  748. }
  749. //render the check date failure state
  750. function CDatePickerDialog_checkDateFail(oEditBox)
  751. {
  752. oEditBox.className = "clsSelectDateYearEditBoxParseError";
  753. this.m_oParentControl.checkDateFail(null);
  754. this.notify(gFAIL, this);
  755. }
  756. function CDatePickerDialog_getYearFromEditBox(oEditBox)
  757. {
  758. //check to see if this is a valid date
  759. var sTestYear = oEditBox.value;
  760. var iYear = false;
  761. if ( this.m_iType == 1 )
  762. {
  763. iYear = iTestEra(sTestYear);
  764. }
  765. else if ( boolTestYear(sTestYear) )
  766. {
  767. iYear = sTestYear;
  768. if (iYear.length == 2)
  769. {
  770. iYear = sShortToFullYearConversion(iYear);
  771. }
  772. }
  773. return iYear;
  774. }
  775. //test the year
  776. function CDatePickerDialog_checkYear(oEditBox)
  777. {
  778. //check to see if this is a valid date
  779. var iYear = this.getYearFromEditBox(oEditBox);
  780. if ( iYear === false )
  781. {
  782. this.checkDateFail(oEditBox);
  783. }
  784. else
  785. {
  786. this.checkDatePass(oEditBox);
  787. var v_oParentControl = this.m_oParentControl;
  788. var v_oParentControlDate = v_oParentControl.m_dDate;
  789. v_oParentControlDate.setFullYear(iYear);
  790. if (this.m_iType == 1)
  791. {
  792. // using emperor time
  793. // refreshDate() will call refreshPickerLayout()
  794. this.refreshDate(v_oParentControlDate);
  795. }
  796. else
  797. {
  798. this.refreshPickerLayout(v_oParentControlDate);
  799. }
  800. //draw months and days
  801. v_oParentControl.drawDate();
  802. v_oParentControl.checkDate(v_oParentControl.m_oEditBox);
  803. }
  804. }
  805. //catch the backspace key
  806. //some browsers (IE5.5 don't capture this event)
  807. function CDatePickerDialog_keyPress(sKeyCode)
  808. {
  809. if (sKeyCode=='8')
  810. {
  811. //check the data that has been typed in
  812. this.checkYear(this.m_oYearWidget);
  813. }
  814. return true;
  815. }
  816. //handle lost focus for the control
  817. function CDatePickerDialog_lostFocus()
  818. {
  819. //redraw the date
  820. this.refreshDate(this.m_oParentControl.m_dDate);
  821. this.m_oParentControl.drawDate();
  822. this.checkDatePass(this.m_oYearWidget);
  823. }
  824. //handle reset focus to popup button if necessary to keep the focus inside the popup
  825. function CDatePickerDialog_checkTabFocus()
  826. {
  827. if (!this.m_bInline)
  828. {
  829. var btnYearDownButton = document.getElementById("btnYearDown" + this.m_sRef);
  830. if (btnYearDownButton != null){
  831. btnYearDownButton.focus();
  832. return true;
  833. }
  834. } else {
  835. var pickerButton = document.getElementById(this.m_sRef + "imgPicker");
  836. if (pickerButton != null){
  837. pickerButton.focus();
  838. return true;
  839. }
  840. }
  841. return false;
  842. }
  843. //IE specific, draw an iframe behind the date picker to
  844. //prevent bleed through of controls
  845. function CDatePickerDialog_resizeIframe(iframe, oDialog)
  846. {
  847. var v_oParent = iframe;
  848. while ( v_oParent = v_oParent.parentNode )
  849. {
  850. // Using CSS class "cogstyle-filter-body" to identify Cognos Admin filter pages.
  851. if ( v_oParent.className == "cogstyle-filter-body" )
  852. {
  853. // Bug 553594.1 - Date controls in the filter pane in CC aren't positioning themself correctly.
  854. // It conflicts with how the page is rendered by CC (other elements in the page are using position:relative)
  855. // which interfere with the pop-up calendar (or any element set with position:absolute).
  856. // Solution here is to leave the calendar under the input field rather than moving it under the icon that triggers
  857. // the pop-up dialog.
  858. return;
  859. }
  860. }
  861. if ( iframe.parentNode != oDialog.parentNode )
  862. {
  863. iframe.parentNode.removeChild(iframe);
  864. oDialog.parentNode.insertBefore(iframe, oDialog);
  865. }
  866. if (this.m_isNS7 === true)
  867. {
  868. iframe.style.left = oDialog.style.left;
  869. iframe.style.top = oDialog.style.top;
  870. iframe.style.width = oDialog.width;
  871. iframe.style.height = oDialog.height;
  872. }
  873. else
  874. {
  875. iframe.style.pixelLeft = oDialog.style.pixelLeft;
  876. iframe.style.pixelTop = oDialog.style.pixelTop;
  877. iframe.style.pixelWidth = oDialog.offsetWidth;
  878. iframe.style.pixelHeight = oDialog.offsetHeight;
  879. }
  880. }
  881. //Prototypes to assign methods to new instances of the object
  882. CDatePickerDialog.prototype.toggleDatePicker = CDatePickerDialog_toggleDatePicker;
  883. CDatePickerDialog.prototype.refreshDate = CDatePickerDialog_refreshDate;
  884. CDatePickerDialog.prototype.yearUp = CDatePickerDialog_yearUp;
  885. CDatePickerDialog.prototype.yearDown = CDatePickerDialog_yearDown;
  886. CDatePickerDialog.prototype.drawYear = CDatePickerDialog_drawYear;
  887. CDatePickerDialog.prototype.newMonth = CDatePickerDialog_newMonth;
  888. CDatePickerDialog.prototype.drawMonth = CDatePickerDialog_drawMonth;
  889. CDatePickerDialog.prototype.clearMonths = CDatePickerDialog_clearMonths;
  890. CDatePickerDialog.prototype.newDay = CDatePickerDialog_newDay;
  891. CDatePickerDialog.prototype.drawDays = CDatePickerDialog_drawDays;
  892. CDatePickerDialog.prototype.clearDays = CDatePickerDialog_clearDays;
  893. CDatePickerDialog.prototype.drawEmperorYear = CDatePickerDialog_drawEmperorYear;
  894. CDatePickerDialog.prototype.hidePicker = CDatePickerDialog_hidePicker;
  895. CDatePickerDialog.prototype.isVisible = CDatePickerDialog_isVisible;
  896. CDatePickerDialog.prototype.checkYear = CDatePickerDialog_checkYear;
  897. CDatePickerDialog.prototype.lostFocus = CDatePickerDialog_lostFocus;
  898. CDatePickerDialog.prototype.initMonths = CDatePickerDialog_initMonths;
  899. CDatePickerDialog.prototype.initDays = CDatePickerDialog_initDays;
  900. CDatePickerDialog.prototype.checkDateFail = CDatePickerDialog_checkDateFail;
  901. CDatePickerDialog.prototype.checkDatePass = CDatePickerDialog_checkDatePass;
  902. CDatePickerDialog.prototype.keyPress = CDatePickerDialog_keyPress;
  903. CDatePickerDialog.prototype.resizeIframe = CDatePickerDialog_resizeIframe;
  904. CDatePickerDialog.prototype.getYearFromEditBox = CDatePickerDialog_getYearFromEditBox;
  905. CDatePickerDialog.prototype.refreshPickerIFrame = CDatePickerDialog_refreshPickerIFrame;
  906. CDatePickerDialog.prototype.refreshPickerLayout = CDatePickerDialog_refreshPickerLayout;
  907. CDatePickerDialog.prototype.checkTabFocus = CDatePickerDialog_checkTabFocus;
  908. CDatePickerDialog.prototype.removeEventListenersFromDays = CDatePickerDialog_removeEventListenersFromDays;
  909. CDatePickerDialog.prototype.addEventListenerForDay = CDatePickerDialog_addEventListenerForDay;