/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| BI and PM: prmt *| (C) Copyright IBM Corp. 2002, 2020 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /* CDatePickerIE5.js This script provides interactivity for the date prompt control */ /* Constructor to create a new Date Picker Dialog / inline calendar oSubmit: the submit form control oForm: a hidden form control to store the date oEditBox: the edit box that the user interacts with oDialog: the date picker dialog sRef: string, the name of this object sDefaultDate: a date to start the control iInline: integer, 0= popup , 1= inline calendar iType: integer, 0= gregorian, 1= japanese imperial //sInputOrder: YMD, DMY, ... //iStartOfWeek: start day of the week. sunday = 0, monday = 1, ..., saturday = 6 iDateTimeType: 0 = datetime e.g. yyyy-mm-dd 00:00:00.000, 1 = date e.g. yyyy-mm-dd sFirstDate: the minimum acceptable date sLastDate: the maximum acceptable date bRequired: boolean, specify if user input is required sSubmitType: 'default' will submit as a standard form 'XML' will convert the submission to XML and submit */ function CDatePicker(oSubmit, oForm, oEditBox, oDialog, sRef, sDefaultDate, iInline, iType, sInputOrder, iStartOfWeek, iDateTimeType, sFirstDate, sLastDate, bRequired, sSubmitType, oImgCheck, sCVId, popupZIndex) { this.setCVId(sCVId); this.m_oSubmit = oSubmit; this.m_oForm = oForm; this.m_oEditBox = oEditBox; this.m_oDialog = oDialog; this.m_sRef = sRef; this.m_popupZIndex = popupZIndex; //check to see if a valid date was supplied this.m_sInputOrder = g_dateOrder; //restore a default value if (sDefaultDate) { //split off any time portions var sTestDate = sDefaultDate.split("T"); //default date is in SQL format, yyyy-mm-dd this.m_dDate = dParseDate(sTestDate[0], "YMD"); if ((this.m_dDate === false) || (!this.m_dDate)) { this.m_dDate = new Date(); } } else { this.m_dDate = new Date(); } //render the calendar inline //0 = no --use edit box and pop up picker dialog //1 = yes -- render inline on the page this.m_iInline = iInline; //sunday = 0, monday = 1, ..., saturday = 6 this.m_iStartOfWeek = g_startDayOfWeek; //Calendar Type: 0=gregorian, 1=emperor this.m_iType = iType; //what the control should return to the form field //0 = datetime e.g. yyyy-mm-dd 00:00:00.000 //1 = date e.g. yyyy-mm-dd this.m_iDateTimeType = iDateTimeType; //check to see if a valid first date was supplied if (sFirstDate) { this.m_dFirstDate = dParseDate(sFirstDate,"YMD"); if (this.m_dFirstDate > this.m_dDate) { //the date is less than the first date, //reset to the first date this.m_dDate = this.m_dFirstDate; } } //check to see if a valid last date was supplied if (sLastDate) { this.m_dLastDate = dParseDate(sLastDate,"YMD"); if (this.m_dLastDate < this.m_dDate) { //the date is greater than the last date, //reset to the last date this.m_dDate = this.m_dLastDate; } } //specify whether the user must enter a date or not this.m_bRequired = bRequired; this.m_bDisabled = false; //indicate whether the control has valid data this.m_bValid = false; //submit as XML or as a standard html form this.m_sSubmitType = sSubmitType; //determine browser for DHTML type this.m_isNS7 = browserIsNS7(); //skin folder this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN); //images for handling errors this.m_oImgCheckDate = oImgCheck; if (!this.m_oImgCheckDate) { this.m_oImgCheckDate = document.getElementById('imgTest'+sRef); } if (this.m_oImgCheckDate) { this.m_oImgErrorFalse= new Image(); this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif"; this.m_oImgErrorTrue = new Image(); this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif"; } this.updateFormVariable(this.m_oForm, this.m_dDate); this.drawDate(); //check to see if we have a valid default this.checkDate(this.m_oEditBox); if ( iInline === 0 ) { this.m_bIsBux = this.f_isBUX(); } //create the dialog object this.m_oDatePickerDialog = new CDatePickerDialog(this.m_oDialog, this, sRef, iInline, iType, this.m_iStartOfWeek, sCVId, this.m_popupZIndex); this.m_oDatePickerDialog.m_bIsBux = this.m_bIsBux; } CDatePicker.prototype = new CPromptControl(); //take the current date and update it function CDatePicker_updateFormVariable(oForm, dNewDate) { //Is there a date? if (dNewDate) { //convert to the new value and update the form //note that this value needs to be properly formatted //where dates need to be fully specified var sNewYear = dNewDate.getFullYear(); //add extra 0(s) if necessary sNewYear = "0000" + sNewYear; sNewYear = sNewYear.substring(sNewYear.length-4, sNewYear.length); var sNewMonth = (parseInt(dNewDate.getMonth(), 10) + 1).toString();//+need to add one; //add an extra 0 if necessary if (sNewMonth.length == 1) { sNewMonth = "0" + sNewMonth; } var sNewDay = (dNewDate.getDate()).toString(); //add an extra 0 if necessary if (sNewDay.length == 1) { sNewDay = "0" + sNewDay; } var sNewValue = sNewYear + "-" + sNewMonth + "-" + sNewDay; //note that this value needs to be properly formatted //where dates need to be fully specified if (this.m_iDateTimeType === 0) { sNewValue += "T00:00:00.000"; } //update the form this.m_oForm.value = sNewValue; } else { //remove the value from the form this.m_oForm.value = K_PRMT_sEMPTY; } this.notify(gUPDATE, this); } //render the date in the proper format function CDatePicker_drawDate() { var sFormatDate = K_PRMT_sEMPTY; if (this.m_dDate) { //update the edit box sFormatDate = getFormatDate (this.m_dDate, this.m_iType, this.m_sInputOrder); } if (this.m_iInline === 0) { this.m_oEditBox.value = sFormatDate; } } //show/hide the picker dialog function CDatePicker_toggleDialogDatePicker(oObj) { //set the current date on the picker dialog if (this.m_dDate) { this.m_oDatePickerDialog.refreshDate(this.m_dDate); } else { //there is no current date, use today's date var dToday = new Date(); this.m_dDate = dToday; //update the form control this.updateFormVariable(this.m_oForm, this.m_dDate); //draw the new date this.drawDate(); this.m_oDatePickerDialog.refreshDate(dToday); } if ( !oObj.m_bSetOnBody ) { document.body.appendChild( this.m_oDatePickerDialog.m_oDialog.parentNode.removeChild( this.m_oDatePickerDialog.m_oDialog ) ); oObj.m_bSetOnBody = true; } //set the position for the dialog based on the togglebutton if ( (!this.m_oDatePickerDialog.isVisible()) ) { this.positionDialog(oObj); } //reset the user day selection this.m_oDatePickerDialog.m_iUserDay = this.m_dDate.getDate(); //show/hide date picker this.m_oDatePickerDialog.toggleDatePicker(); } function CDatePicker_positionDialog(v_oObj) { var v_oDialog = this.m_oDatePickerDialog.m_oDialog; var v_sDisplayVal = v_oDialog.style.display; v_oDialog.style.display = "inline"; var v_elRVReport = document.documentElement.querySelector(".RVReport") || document.documentElement; var v_oPageOffset; if (window.edge === true){ v_oPageOffset = {x: v_elRVReport.scrollLeft, y: document.body.scrollTop}; } else{ v_oPageOffset = {x: v_elRVReport.scrollLeft, y: v_elRVReport.scrollTop}; } var v_oObjRect = v_oObj.getBoundingClientRect(); var v_oDialogRect = v_oDialog.getBoundingClientRect(); var v_oClientRect = v_elRVReport.getBoundingClientRect(); v_oDialog.style.display = v_sDisplayVal; var v_oPos = {x: v_oPageOffset.x, y: v_oPageOffset.y}; if (v_oObjRect.top > 0) { if (v_oObjRect.top + v_oDialogRect.height <= v_oClientRect.height) { v_oPos.y += v_oObjRect.top; } else if (v_oObjRect.top + v_oDialogRect.height - v_oClientRect.height < v_oObjRect.top) { v_oPos.y += v_oClientRect.height - v_oDialogRect.height; } } if (v_oObjRect.left > 0) { if (v_oObjRect.left + v_oDialogRect.width <= v_oClientRect.width) { v_oPos.x += v_oObjRect.left; } else if (v_oObjRect.left + v_oDialogRect.width - v_oClientRect.width < v_oObjRect.left) { v_oPos.x += v_oClientRect.width - v_oDialogRect.width; } } if (this.m_isNS7 === true || window.edge === true) { v_oDialog.style.left = v_oPos.x + "px"; v_oDialog.style.top = v_oPos.y + "px"; } else { v_oDialog.style.pixelLeft = v_oPos.x; v_oDialog.style.pixelTop = v_oPos.y; } } //render date test pass function CDatePicker_checkDatePass(oEditBox) { if (this.m_oImgCheckDate && (this.m_oImgCheckDate.src != this.m_oImgErrorFalse.src)) { this.m_oImgCheckDate.src = this.m_oImgErrorFalse.src; } if (oEditBox) { oEditBox.className = "clsSelectDateEditBox"; PRMTUtils.f_showARIAPass(oEditBox, this.m_sRef); } this.notify(gPASS, this); this.checkData(); } //render date test failure function CDatePicker_checkDateFail(oEditBox) { if (this.m_oImgCheckDate && (this.m_oImgCheckDate.src != this.m_oImgErrorTrue.src)) { this.m_oImgCheckDate.src = this.m_oImgErrorTrue.src; } if (oEditBox) { oEditBox.className = "clsSelectDateEditBoxParseError"; var v_emptyValue = sStripNonAlphanumerics(oEditBox.value) === K_PRMT_sEMPTY; var v_errorMsg = v_emptyValue ? PMT_UIM_MISSING_VALUE : PMT_UIM_INVALID_INPUT; PRMTUtils.f_showARIAFail(oEditBox, this.m_sRef, this.m_sSkin, v_errorMsg); } this.notify(gFAIL, this); this.checkData(); } //test the date function CDatePicker_checkDate(oEditBox) { var bTestResult = true; //remove any non alpha numeric data var sTestDateStrip = sStripNonAlphanumerics(oEditBox.value).f_trim(); //remove the time if it is part of the string if (this.m_iDateTimeType === 0) { // There are some months that have a T like July in Turkish -> 擳em? // Splits on 'T' when it's followed by digits: var arSplitValue = sTestDateStrip.split(/T(?=\d)/); sTestDateStrip = arSplitValue[0]; } //is the field required? If not, a value does not have to be specified if ( this.m_bRequired === false && sTestDateStrip === K_PRMT_sEMPTY) { this.m_dDate = null; this.updateFormVariable(this.m_oForm, this.m_dDate); this.m_bValid = true; this.checkDatePass(oEditBox); return; } var iTestDate = false; //Fix for bug# 482564 - If this object is used for Date/Time dialog, specifically use YMD as date format var tempInputOrder = this.m_sInputOrder; if(oEditBox == this.m_oForm) { tempInputOrder = "YMD"; } if (this.m_iType === 1) { iTestDate = dParseEra(sTestDateStrip, tempInputOrder); } else { iTestDate = dParseDate(sTestDateStrip,tempInputOrder); } //check to see if this is a valid date if (!iTestDate) //it is a number { bTestResult = false; } //see if an acceptable date was supplied if (bTestResult === false) { this.m_bValid = false; this.checkDateFail(oEditBox); return; } else { //var dTestDate = new Date(dTestDate); var dTestDate = iTestDate; //check to see if this date less than the first date //if so, then this is not a valid date if (this.m_dFirstDate) { if (dTestDate < this.m_dFirstDate) { this.m_bValid = false; this.checkDateFail(oEditBox); return; } } //check to see if this date is greater than the last date //if so, then this is not a valid date if (this.m_dLastDate) { if (dTestDate > this.m_dLastDate) { this.m_bValid = false; this.checkDateFail(oEditBox); return; } } this.m_dDate = dTestDate; this.m_bValid = true; this.updateFormVariable(this.m_oForm, this.m_dDate); this.checkDatePass(oEditBox); return; } } //catch the backspace key //some browsers (IE5.5 don't capture this event) function CDatePicker_keyPress(evt) { //trap the tab key and shift-tab evt = (evt) ? evt : ((event) ? event : null); if (evt) { var keyCode = (evt.keyCode) ? evt.keyCode : evt.which; if (keyCode=='8') { //check the data that has been typed in this.checkDate(this.m_oEditBox); } } return true; } //handle focus to the edit box function CDatePicker_gotFocus() { //hide the date picker control if it is showing this.m_oDatePickerDialog.hidePicker(); } //handle lost focus to the edit box function CDatePicker_lostFocus() { this.checkDate(this.m_oEditBox); //reformat the date in the manner specified //by the input order if (this.m_bValid === true) { this.drawDate(); } } //perform any special processing for the server. function CDatePicker_preProcess() { if (this.m_sSubmitType == K_PRMT_sXML) { var sURLValues = K_PRMT_sEMPTY; if ((this.m_oEditBox.value !== K_PRMT_sEMPTY) && (this.m_bDisabled!==true)) { sURLValues += '