123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| BI and PM: prmt
- *| (C) Copyright IBM Corp. 2002, 2013
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /*
- DateHelper.js
- This script provides interactivity for the date prompt control
- */
- /*
- Constructor to create a new Date Picker Dialog / inline calendar
- oForm: a hidden form control to store the date
- oEditBox: the edit box that the user interacts with
- sRef: string, the name of this object
- sDefaultDate: a date to start the control
- 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
- sCVId: string id
- */
- function PRMT_DateHelper( oForm, oEditBox, sRef, sDefaultDate, iType, sInputOrder, iStartOfWeek, iDateTimeType,
- sFirstDate, sLastDate, bRequired)
- {
- this.m_oForm = oForm;
- this.m_oEditBox = oEditBox;
- this.m_sRef = sRef;
- //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();
- }
- //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;
-
- };
- PRMT_DateHelper.prototype.getCurrentDate = function() { return this.m_dDate; };
- PRMT_DateHelper.prototype.f_checkDate = function(dateValue)
- {
- var bTestResult = true;
- //remove any non alpha numeric data
- var sTestDateStrip = sStripNonAlphanumerics(dateValue).f_trim();
- //remove the time if it is part of the string
- if (this.m_iDateTimeType === 0) {
- var rSplit = /[T]/;
- var arSplitValue = sTestDateStrip.split(rSplit);
- sTestDateStrip = arSplitValue[0];
- }
- var dTestDate = null;
- //is the field required? If not, a value does not have to be specified
- if ( !( this.m_bRequired === false && sTestDateStrip === K_PRMT_sEMPTY) ) {
- var iTestDate = false;
- //Fix for bug# 482564 - If this object is used for Date/Time dialog, specifically use YMD as date format
- var 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 ) {
- dTestDate = iTestDate;
-
- //check to see if this date less than the first date OR
- //check to see if this date is greater than the last date
- //if so, then this is not a valid date
- if ( (this.m_dFirstDate && (dTestDate < this.m_dFirstDate)) ||
- (this.m_dLastDate && (dTestDate > this.m_dLastDate)) ) {
- bTestResult = false;
- }
- }
- }
-
- this.m_dDate = dTestDate;
- this.m_bValid = bTestResult;
- return bTestResult;
- };
- /**
- * Return a date string in the yyyy-mm-dd format
- *
- * @param Date dateValue
- */
- PRMT_DateHelper.prototype.f_formatDateYMD = function(dateValue)
- {
- var result = null;
- if (dateValue) {
- var nMonth = dateValue.getMonth() + 1;
- var sMonth = (nMonth > 9 ? String(nMonth) : "0" + nMonth);
- var nDay = dateValue.getDate();
- var sDay = (nDay > 9 ? String(nDay) : "0" + nDay);
- result = dateValue.getFullYear() + "-" + sMonth + "-" + sDay;
- }
- return result;
- }
- //return the content locale formatted value
- PRMT_DateHelper.prototype.f_formatDateCurrentLocale = function(dateObj)
- {
- return getFormatDate (dateObj, this.m_iType, this.m_sInputOrder);
- }
- //take the current date and update it
- PRMT_DateHelper.prototype.f_formatSubmitDate = function(dNewDate)
- {
- var result;
- //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";
- }
- result = sNewValue;
- } else {
- //remove the value from the form
- result = K_PRMT_sEMPTY;
- }
- return result;
- }
|