123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693 |
- /*
- *+------------------------------------------------------------------------+
- *| 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 += '<selectOption';
- sURLValues += ' displayValue="' + sXmlEncode(this.sGetFormatValue()) +'"';
- sURLValues += ' useValue="' + sXmlEncode(this.sGetValue()) +'"';
- sURLValues += ' selected="true" />';
- }
- addSelectChoices(this.m_oSubmit, sURLValues);
- }
- else
- {
- if (this.m_bDisabled !== true)
- {
- this.m_oSubmit.value = this.m_oForm.value;
- }
- else
- {
- //this control is disabled
- this.m_oSubmit.value = K_PRMT_sEMPTY;
- }
- }
- }
- //return a valid value
- function CDatePicker_sGetValue()
- {
- this.checkDate(this.m_oEditBox);
- if (this.m_bValid === true)
- {
- return this.m_oForm.value;
- }
- else
- {
- return false;
- }
- }
- function CDatePicker_enable()
- {
- this.m_bDisabled = false;
- this.m_oDialog.style.filter = "none";
- this.m_oEditBox.style.filter = "none";
- PRMTUtils.f_removeClass( this.m_oDialog, "clsClockDisabled" );
- PRMTUtils.f_removeClass( this.m_oEditBox, "clsClockDisabled" );
- }
- function CDatePicker_disable()
- {
- this.m_bDisabled = true;
- this.m_oDialog.style.filter = "alpha(opacity=75)";
- this.m_oEditBox.style.filter = "alpha(opacity=75)";
- PRMTUtils.f_addClass( this.m_oDialog, "clsClockDisabled" );
- PRMTUtils.f_addClass( this.m_oEditBox, "clsClockDisabled" );
- }
- function CDatePicker_toggleDisable(bState)
- {
- if (this.isRequired() === false)
- {
- if (bState === false)
- {
- this.disable();
- }
- else
- {
- this.enable();
- }
- }
- }
- //call this method to redraw the position of the
- //calendar dialog if the page is resized
- function CDatePicker_handleResize()
- {
- var o = document.getElementById(this.m_sRef + "imgPicker");
- if (o)
- {
- this.positionDialog(o);
- }
- }
- //return the content locale formatted value
- function CDatePicker_sGetFormatValue()
- {
- if (this.isValid() === true)
- {
- return getFormatDate (this.m_dDate, this.m_iType, this.m_sInputOrder);
- }
- else
- {
- return false;
- }
- }
- //set the value of the control
- function CDatePicker_setValue(s)
- {
- //parse the date
- this.m_dDate = dParseDate(s, "YMD");
- //update the calendar
- this.m_oDatePickerDialog.refreshDate(this.m_dDate);
- //update the edit box if there is one
- this.drawDate();
- this.checkDate(this.m_oEditBox);
- }
- function CDatePicker_hasValue()
- {
- if (this.m_oForm.value === K_PRMT_sEMPTY)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- //used to clean up date picker dialogs
- function CDatePicker_handleNotify()
- {
- //hide if this is an edit box date picker
- if (this.m_iInline === 0)
- {
- this.m_oDatePickerDialog.hidePicker();
- }
- }
- function CDatePicker_checkFail()
- {
- this.checkDateFail(this.m_oEditBox);
- }
- //Prototypes to assign methods to new instances of the object
- CDatePicker.prototype.drawDate = CDatePicker_drawDate;
- CDatePicker.prototype.toggleDialogDatePicker= CDatePicker_toggleDialogDatePicker;
- CDatePicker.prototype.updateFormVariable = CDatePicker_updateFormVariable;
- CDatePicker.prototype.checkDate = CDatePicker_checkDate;
- CDatePicker.prototype.checkDateFail = CDatePicker_checkDateFail;
- CDatePicker.prototype.checkDatePass = CDatePicker_checkDatePass;
- CDatePicker.prototype.keyPress = CDatePicker_keyPress;
- CDatePicker.prototype.gotFocus = CDatePicker_gotFocus;
- CDatePicker.prototype.lostFocus = CDatePicker_lostFocus;
- CDatePicker.prototype.preProcess = CDatePicker_preProcess;
- CDatePicker.prototype.sGetValue = CDatePicker_sGetValue;
- CDatePicker.prototype.enable = CDatePicker_enable;
- CDatePicker.prototype.disable = CDatePicker_disable;
- CDatePicker.prototype.toggleDisable = CDatePicker_toggleDisable;
- CDatePicker.prototype.positionDialog = CDatePicker_positionDialog;
- CDatePicker.prototype.handleResize = CDatePicker_handleResize;
- CDatePicker.prototype.sGetFormatValue = CDatePicker_sGetFormatValue;
- CDatePicker.prototype.setValue = CDatePicker_setValue;
- CDatePicker.prototype.hasValue = CDatePicker_hasValue;
- CDatePicker.prototype.handleNotify = CDatePicker_handleNotify;
- CDatePicker.prototype.checkFail = CDatePicker_checkFail;
- CDatePicker.prototype.checkData = function()
- {
- if (this.m_oParent && !this.m_oParent.m_bisGetValuesCall) {
- this.m_oParent.checkData();
- }
- };
- CDatePicker.prototype.f_getPosY = function(v_oObj, v_bCC_offset)
- {
- var iYpos = 0;
- if (this.m_isNS7 && !v_bCC_offset)
- {
- iYpos = v_oObj.y;
- // adds relative elements offsets
- var oParent = v_oObj;
- while (oParent = oParent.offsetParent)
- {
- if (oParent.style && oParent.style.position == "relative")
- {
- iYpos += oParent.offsetTop;
- }
- }
- if (!iYpos) {
- iYpos = iOffsetFromBodyY(v_oObj);
- }
- }
- else
- {
- iYpos = iOffsetFromBodyY(v_oObj);
- }
- return iYpos;
- };
|