123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- /********************************************************************************************************************************
- * Licensed Materials - Property of IBM *
- * *
- * IBM Cognos Products: HTS *
- * *
- * (C) Copyright IBM Corp. 2005, 2010 *
- * *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
- *********************************************************************************************************************************/
- function hts_datetime(dateFrom,dateTo,msgs)
- {
- this.m_dateFrom = dateFrom;
- this.m_dateTo = dateTo;
- this.m_msgs = msgs;
- this.m_dateTimeUtil = new hts_dateTimeUtil();
- }
- hts_datetime.prototype = {
-
- checkDate: function(fromDate,newDate) {
- var dateIsTheSame=true;
- iYear = newDate.substring(0,4);
- iMonth = newDate.substring(5, 7);
- iDay = newDate.substring(8, 10);
-
- if (fromDate) {
- newDateFrom = this.getDateFromValue();
- iNewStartYear = newDateFrom.substring(0,4);
- iNewStartMonth = newDateFrom.substring(5, 7);
- iNewStartDay = newDateFrom.substring(8, 10);
- dateIsTheSame = iYear == iNewStartYear && iMonth == iNewStartMonth && iDay == iNewStartDay;
- }
- else {
- newDateTo = this.getDateToValue();
- iNewEndYear = newDateTo.substring(0,4);
- iNewEndMonth = newDateTo.substring(5, 7);
- iNewEndDay = newDateTo.substring(8, 10);
- dateIsTheSame = iYear == iNewEndYear && iMonth == iNewEndMonth && iDay == iNewEndDay;
- }
-
- return dateIsTheSame;
- },
- //check that a date is not the current date
- checkCurrentDate: function(newDate) {
-
- currentDate=this.getCurrentDateValue();
-
- iCurrentYear = currentDate.substring(0,4);
- iCurrentMonth = currentDate.substring(5, 7);
- iCurrentDay = currentDate.substring(8, 10);
- iNewYear = newDate.substring(0,4);
- iNewMonth = newDate.substring(5, 7);
- iNewDay = newDate.substring(8, 10);
-
- isTodaysDate = iCurrentYear == iNewYear && iCurrentMonth == iNewMonth && iCurrentDay == iNewDay;
-
- return isTodaysDate;
- },
- getCurrentDateValue: function() {
- return this.m_dateTimeUtil.getCurrentDateValue();
- },
- getDateFromFormatValue: function() {
- if (this.m_dateFrom != null && this.m_dateFrom != '')
- {
- return window['pickerControl'+ this.m_dateFrom].sGetFormatValue();
- } else
- {
- return '';
- }
- },
- getDateToFormatValue: function() {
- if (this.m_dateTo != null && this.m_dateTo != '')
- {
- return window['pickerControl'+ this.m_dateTo].sGetFormatValue();
- } else
- {
- return '';
- }
- },
- getDateFromValue: function() {
- if (this.m_dateFrom != null && this.m_dateFrom != '')
- {
- var picker = window['pickerControl'+ this.m_dateFrom];
- if (picker.isValid()) {
- return picker.sGetValue();
- }
- else {
- //if an invalid date has been entered sGetValue will return a boolean so in this instance we return an zeroed date string
- return "00000000";
- }
- } else
- {
- return '';
- }
- },
- getDateToValue: function() {
- if (this.m_dateTo != null && this.m_dateTo != '')
- {
- var picker = window['pickerControl'+ this.m_dateTo];
- if (picker.isValid()) {
- return picker.sGetValue();
- }
- else {
- //if an invalid date has been entered sGetValue will return a boolean so in this instance we return an zeroed date string
- return "00000000";
- }
- } else
- {
- return '';
- }
- },
- setDateFromValue: function (dateStr) {
- var picker = window['pickerControl'+ this.m_dateFrom];
- var ymd = this.convertDateToYMD(dateStr);
- picker.setValue(ymd);
- },
- setDateToValue: function (dateStr) {
- var picker = window['pickerControl'+ this.m_dateTo];
- var ymd = this.convertDateToYMD(dateStr);
- picker.setValue(ymd);
- },
- convertDateToYMD: function (dateStr) {
- var ymd="";
- if (dateStr!=='') {
- iYear = dateStr.substring(0,4);
- iMonth = dateStr.substring(5, 7);
- iDay = dateStr.substring(8, 10);
- ymd = iYear+'-'+iMonth+'-'+iDay;
- }
-
- return ymd;
- },
-
- simpleValidate:function(validateFrom){
- if (validateFrom) {
- if ( !this.isDateValid(this.m_dateFrom) )
- {
- alert (this.m_msgs['MSG_ERR_INVALID_START_DATE']);
- return false;
- }
- }
- else {
- if ( !this.isDateValid(this.m_dateTo) )
- {
- alert (this.m_msgs['MSG_ERR_INVALID_END_DATE']);
- return false;
- }
- }
- return (true);
- },
- isDateValid: function(str)
- {
- return this.m_dateTimeUtil.isDateValid(str);
- },
- validateFromDate: function () {
- if (!this.simpleValidate(true))
- {
- return false;
- }
- // Check the Start Date Time.
- if (this.getDateFromValue() == '')
- {
- alert (this.m_msgs['MSG_ERR_INVALID_START_DATE']);
- return false;
- }
-
- /*if (this.checkCurrentDate(this.getDateFromValue())) {
- var dateFrom = this.getDateFromValue();
- //set the hours and minutes to 23:59 if the start date is todays date
- var newDateFrom = dateFrom.replace("00:00.000","23:59.000");
- alert('The start date has been set to the current date. The deadline will expire at 23:59 today');
- this.setDateFromValue(newDateFrom);
- //alert (this.m_msgs['MSG_ERR_START_CANNOT_USE_CURRENT_DATE']);
- //return false;
- }*/
-
- if (this.getDateToValue()!='' && !(this.validateDateSequence()))
- {
- return false;
- }
-
- return (true);
- },
- validateToDate: function () {
- if (!this.simpleValidate(false))
- {
- return false;
- }
-
- // Check the End Date Time.
- if (this.getDateToValue() == '')
- {
- alert (this.m_msgs['MSG_ERR_INVALID_END_DATE']);
- return false;
- }
- if (this.checkCurrentDate(this.getDateToValue())) {
- alert (this.m_msgs['MSG_ERR_COMPLETE_CANNOT_USE_CURRENT_DATE']);
- return false;
- }
-
- if (this.getDateFromValue!='' && !(this.validateDateSequence())) {
- return false;
- }
- return (true);
- },
- validateDates: function()
- {
-
- if (!this.validateFromDate()) {
- return false;
- }
-
- if (!this.validateToDate()) {
- return false;
- }
-
- // We could create date objects and compare them but that involves too much work to format
- // our date values to JS acceptable format.
- if (!(this.validateDateSequence()))
- {
- return false;
- }
- return(true);
- },
- // ..............................................................................
- // Checks for end date being earlier than or the same as the start date.
- validateDateSequence: function()
- {
- iStartYear = this.getDateFromValue().substring(0,4);
- iStartMonth = this.getDateFromValue().substring(5, 7);
- iStartDay = this.getDateFromValue().substring(8, 10);
- iEndYear = this.getDateToValue().substring(0,4);
- iEndMonth = this.getDateToValue().substring(5, 7);
- iEndDay = this.getDateToValue().substring(8, 10);
-
- var errMsg = 'MSG_ERR_INCOMPATIBLE_DATES';
- var bRetVal = this.m_dateTimeUtil.getDateSequence(iStartDay, iStartMonth, iStartYear, iEndDay, iEndMonth, iEndYear);
-
- if(bRetVal == 0)
- {
- //end date equal to start date
- errMsg = 'MSG_ERR_EQUAL_DATES';
- }
-
- if(bRetVal != 1)
- {
- alert(this.m_msgs[errMsg]);
- return false
- }
- else
- {
- //end date later then start date
- return true;
- }
- }
- }
- /*
- Utility to validate a single date.
- The constructor expects the same id of the that is passed when
- creating the date picker i.e. the id of the field passed to the
- genSelectDateHTML(...) function.
- e.g.'_THIS_'+'taskOptions_dueDate'
- */
- function hts_datePickerUtil(dateTime)
- {
- this.dateTime = dateTime;
- this.m_dateTimeUtil = new hts_dateTimeUtil();
- }
- hts_datePickerUtil.prototype = {
- isDateValid: function()
- {
- return this.m_dateTimeUtil.isDateValid(this.dateTime);
- },
- isDateEmpty: function()
- {
- var isDateEmpty = false;
- if(this.getDateValue() == '')
- {
- isDateEmpty = true;
- }
- return isDateEmpty;
- },
- getDateValue: function()
- {
- var dateValue = '';
- if (this.dateTime != null && this.dateTime != '')
- {
- dateValue = window['pickerControl'+ this.dateTime].sGetValue();
- }
- return dateValue;
- },
- //NOTE: An empty value will also be compared, to check if a date is set or not
- // use isEmpty()
- isDateLaterThanCurrentDate: function()
- {
- var isDateLaterThanCurrentDate = false;
- //check if the date is valid
- if(this.isDateValid())
- {
- iDateYear = this.getDateValue().substring(0,4);
- iDateMonth = this.getDateValue().substring(5, 7);
- iDateDay = this.getDateValue().substring(8, 10);
- isDateLaterThanCurrentDate = this.m_dateTimeUtil.isDateLaterThanCurrentDate(iDateDay, iDateMonth, iDateYear);
- }
-
- return isDateLaterThanCurrentDate;
-
- },
- //NOTE: An empty value will also be compared, to check if a date is set or not
- // use isEmpty()
- isDateLaterThanOrEqualToCurrentDate: function()
- {
- var isDateLaterThanCurrentDate = false;
- //check if the date is valid
- if(this.isDateValid())
- {
- iDateYear = this.getDateValue().substring(0,4);
- iDateMonth = this.getDateValue().substring(5, 7);
- iDateDay = this.getDateValue().substring(8, 10);
- isDateLaterThanCurrentDate = this.m_dateTimeUtil.isDateLaterThanOrEqualToCurrentDate(iDateDay, iDateMonth, iDateYear);
- }
-
- return isDateLaterThanCurrentDate;
- }
- }
- /*
- Generic date time utilities. Each function should be a self
- contained function with each parameter passed explicitly.
- */
- function hts_dateTimeUtil()
- {
- }
- hts_dateTimeUtil.prototype = {
-
- isDateValid: function(str)
- {
- var t = true;
- if (str != '')
- {
- t = window['pickerControl' + str].isValid();
- }
- return t;
- },
- getCurrentDateValue: function()
- {
- //convert to something like this : "2009-04-22"
- currentDate = new Date();
- year = this.getYear(currentDate);
- month = this.getMonth(currentDate);
- day = this.getDay(currentDate);
-
- return year+"-"+month+"-"+day;
- },
- // ..............................................................................
- // Checks which of the end date or start date is earlier.
- // returns -1 if endate is earlier the start date
- // 0 if the end date and start date are equal
- // 1 if end date is later then the start date
- // NOTE: this function does not validate the dates, it just compares
- // the passed in year, month and day values assuming they are
- // a part of a valid Date. Use other validate functions to
- // validate if the date is valid or not.
- //...............................................................................
- getDateSequence: function(iStartDay, iStartMonth, iStartYear, iEndDay, iEndMonth, iEndYear)
- {
- var bRetVal = 1;
- if (iEndYear < iStartYear)
- {
- bRetVal = -1;
- }
- else if (iEndYear == iStartYear)
- {
- if (iEndMonth < iStartMonth)
- {
- bRetVal = -1;
- }
- else if (iEndMonth == iStartMonth)
- {
- if (iEndDay < iStartDay)
- {
- bRetVal = -1;
- }
- else if (iEndDay == iStartDay)
- {
- bRetVal = 0;
- }
- }
- }
- return bRetVal;
- },
- //NOTE: An empty value will also be compared, to check if a date is set or not
- // use isEmpty()
- isDateLaterThanCurrentDate: function(iDateDay, iDateMonth, iDateYear)
- {
- currentDate = new Date();
- var dateSequence = this.getDateSequence(this.getDay(currentDate), this.getMonth(currentDate), this.getYear(currentDate), iDateDay, iDateMonth, iDateYear);
-
- if(dateSequence == 1)
- {
- //the passed in date is later than the current date
- return true;
- }
- else
- {
- //the passed in date is earlier or equal to the current date
- return false;
- }
- },
- //NOTE: An empty value will also be compared, to check if a date is set or not
- // use isEmpty()
- isDateLaterThanOrEqualToCurrentDate: function(iDateDay, iDateMonth, iDateYear)
- {
- currentDate = new Date();
- var dateSequence = this.getDateSequence(this.getDay(currentDate), this.getMonth(currentDate), this.getYear(currentDate), iDateDay, iDateMonth, iDateYear);
-
- if(dateSequence != -1)
- {
- //the passed in date is later than or equal to the current date
- return true;
- }
- else
- {
- //the passed in date is earlier or equal to the current date
- return false;
- }
- },
- //pass in the javascript Date type
- getYear: function(dateValue)
- {
- //return the year from e.g. "2009-04-22"
- year = dateValue.getFullYear();
- return year + "";
- },
- getMonth: function(dateValue)
- {
- //return the month from e.g. "2009-04-22"
- month = (dateValue.getMonth()+1).toString();
-
- //prefix with zero
- if (month.length==1) {
- month = "0"+month;
- }
-
- return month + "";
- },
- getDay: function(dateValue)
- {
- //return the day from e.g. "2009-04-22"
- day = dateValue.getDate().toString();
-
- //prefix with zero
- if (day.length==1) {
- day = "0"+day;
- }
- return day + "";
- }
- }
- /*
- The following two functions add disable functionality to the datePickers.
- I considered going further, and intercepting the genSelectDateHTML function,
- to add enable/disable functions directly onto the enclosing div (more OO),
- but might be more awkward to follow.
- Here we simply manage the functions on the image (cache when disabled), and
- disable the textbox.
- */
- function hts_disableDatePicker(datePickerId) {
- //check first
- var dateInput= $('txtDate'+datePickerId);
- if(dateInput.disabled == true) {
- //already disabled
- return;
- }
-
- //disable the input
- dateInput.disabled=true;
-
- //disable the functions on the image (cache the functions)
- var dateImg= $(datePickerId+"imgPicker");
- dateImg.cacheOnClick = dateImg.onclick;
- dateImg.cacheOnMouseDown = dateImg.onmousedown;
- dateImg.cacheOnMouseOut = dateImg.onmouseout;
- dateImg.cacheOnMouseOver = dateImg.onmouseover;
- dateImg.cacheImgSrc = dateImg.src;
- //and remove
- dateImg.onclick = null;
- dateImg.onmousedown = null;
- dateImg.onmouseout = null;
- dateImg.onmouseover = null;
- dateImg.src = _F_Config.webContent + "/fragments/myinbox/images/icon_datepicker_disable.gif"
- }
- function hts_enableDatePicker(datePickerId) {
- //check first
- var dateInput= $('txtDate'+datePickerId);
- if(dateInput.disabled == false) {
- //already enabled
- return;
- }
- //enable the input
- dateInput.disabled=false;
-
- //enable the functions on the image - get from cache
- var dateImg= $(datePickerId+"imgPicker");
- dateImg.onclick = dateImg.cacheOnClick;
- dateImg.onmousedown = dateImg.cacheOnMouseDown;
- dateImg.onmouseout = dateImg.cacheOnMouseOut;
- dateImg.onmouseover = dateImg.cacheOnMouseOver;
- dateImg.src = dateImg.cacheImgSrc;
- //reset cache
- dateImg.cacheOnClick = null;
- dateImg.cacheOnMouseDown = null;
- dateImg.cacheOnMouseOut = null;
- dateImg.cacheOnMouseOver = null;
- dateImg.cacheImgSrc = null;
- }
|