// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2014 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). function cogadmin_datetime(form) { this.m_dateFrom = null; this.m_timeFrom = null; this.m_dateTo = null; this.m_timeTo = null; this.m_form = form; this.m_isFromToDate = null; this.m_date = null; this.m_time = null; this.m_date1 = null; this.m_time1 = null; this.m_date2 = null; this.m_time2 = null; } cogadmin_datetime.prototype = { setGlobals: function(dateFrom, timeFrom, dateTo, timeTo) { this.m_dateFrom = dateFrom; this.m_timeFrom = timeFrom; this.m_dateTo = dateTo; this.m_timeTo = timeTo; this.m_isFromToDate = true; }, setGlobalsSimple: function() { this.m_date = date; this.m_time = time; this.m_isFromToDate = false; }, setHiddenInputs: function(date1, time1, date2, time2) { this.m_date1 = date1; this.m_time1 = time1; this.m_date2 = date2; this.m_time2 = time2; }, setDateTimeFromTo: function(periodDiv, divInner) { if (this.dateTimeValidateDateTimeFromTo()) { var dFrom = this.getDateFromFormatValue(); var tFrom = this.getTimeFromFormatValue(); var dTo = this.getDateToFormatValue(); var tTo = this.getTimeToFormatValue(); this.setHiddenDateTimeInterval(dFrom, this.getTimeFromValue(), dTo, this.getTimeToValue()); var toFrom = getFormattedSummary(dFrom, tFrom, dTo, tTo); var div = document.getElementById(divInner); div.innerHTML = toFrom; } }, getDateFromFormatValue: function() { if (this.m_dateFrom != null && this.m_dateFrom != '') { return window['pickerControl'+ this.m_dateFrom].sGetFormatValue(); } else { return ''; } }, getTimeFromFormatValue: function() { if (this.m_timeFrom != null && this.m_timeFrom != '') { return window['timePicker' + this.m_timeFrom].sGetFormatValue(); } else { return ''; } }, getDateToFormatValue: function() { if (this.m_dateTo != null && this.m_dateTo != '') { return window['pickerControl'+ this.m_dateTo].sGetFormatValue(); } else { return ''; } }, getTimeToFormatValue: function() { if (this.m_timeTo != null && this.m_timeTo != '') { return window['timePicker' + this.m_timeTo].sGetFormatValue(); } else { return ''; } }, getDateFromValue: function() { if (this.m_dateFrom != null && this.m_dateFrom != '') { return window['pickerControl'+ this.m_dateFrom].sGetValue(); } else { return ''; } }, getTimeFromValue: function() { if (this.m_timeFrom != null && this.m_timeFrom != '') { return window['timePicker' + this.m_timeFrom].sGetValue(); } else { return ''; } }, getDateToValue: function() { if (this.m_dateTo != null && this.m_dateTo != '') { return window['pickerControl'+ this.m_dateTo].sGetValue(); } else { return ''; } }, getTimeToValue: function() { if (this.m_timeTo != null && this.m_timeTo != '') { return window['timePicker' + this.m_timeTo].sGetValue(); } else { return ''; } }, getDateFormatValue: function() { if (this.m_date != null && this.m_date != '') { return window['pickerControl'+ this.m_date].sGetFormatValue(); } else { return ''; } }, getTimeFormatValue: function() { if (this.m_time != null && this.m_time != '') { return window['timePicker' + this.m_time].sGetFormatValue(); } else { return ''; } }, simpleValidate:function(){ if (this.m_isFromToDate != null) { if(this.m_isFromToDate) { if ( !this.isDateValid(this.m_dateFrom) ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_START_DATE']); return false; } if ( !this.isDateValid(this.m_dateTo) ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_END_DATE']); return false; } if ( !this.isTimeValid(this.m_timeFrom) ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_START_TIME']); return false; } if ( !this.isTimeValid(this.m_timeTo) ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_END_TIME']); return false; } } else { //we have just one date and/or one time. if (this.m_date != null && this.m_date != '') { if ( !this.isDateValid(this.m_date) ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_DATE']); return false; } } if (this.m_time != null && this.m_time != '') { if ( !this.isTimeValid(this.m_time) ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_TIME']); return false; } } } } return (true); }, // Whenever the value changes, call the necessary javascript function if one was provided isTimeValid: function(str) { var t = true; if ( str != '') { t = window['timePicker' + str].isValid(); } return t; }, isDateValid: function(str) { var t = true; if ( str != '') { t = window['pickerControl' + str].isValid(); } return t; }, dateTimeValidateDateTimeFromTo: function() { var iStartDay, iStartMonth, iStartYear, iStartHour, iStartMinute, iEndDay, iEndMonth, iEndYear, iEndHour, iEndMinute; if (!this.simpleValidate()) { return false; } // Check the Start Date Time. if (this.m_form[this.m_dateFrom].value == '' || this.m_form[this.m_timeFrom].value == '' ) { alert (m_datetime_msg_array['MSG_ERR_INVALID_START_DATE']); return false; } // Check the End Date Time. if (this.m_form[this.m_dateTo].value == '' || this.m_form[this.m_timeTo].value == '') { alert (m_datetime_msg_array['MSG_ERR_INVALID_END_DATE']); return false; } iStartYear = this.m_form[this.m_dateFrom].value.substring(0,4); iStartMonth = this.m_form[this.m_dateFrom].value.substring(5, 7); iStartDay = this.m_form[this.m_dateFrom].value.substring(8, 10); iStartHour = this.m_form[this.m_timeFrom].value.substring(0, 2); iStartMinute = this.m_form[this.m_timeFrom].value.substring(3, 5); iEndYear = this.m_form[this.m_dateTo].value.substring(0,4); iEndMonth = this.m_form[this.m_dateTo].value.substring(5, 7); iEndDay = this.m_form[this.m_dateTo].value.substring(8, 10); iEndHour = this.m_form[this.m_timeTo].value.substring(0, 2); iEndMinute = this.m_form[this.m_timeTo].value.substring(3, 5); // 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.validateDateTimeSequence(iStartDay, iStartMonth, iStartYear, iStartHour, iStartMinute, iEndDay, iEndMonth, iEndYear, iEndHour, iEndMinute))) { return false; } return(true); }, // .............................................................................. // Checks for end date being earlier than or the same as the start date. validateDateTimeSequence: function(iStartDay, iStartMonth, iStartYear, iStartHour, iStartMinute, iEndDay, iEndMonth, iEndYear, iEndHour, iEndMinute) { var bRetVal = true; if (iEndYear < iStartYear) bRetVal = false; else if (iEndYear == iStartYear) { if (iEndMonth < iStartMonth) bRetVal = false; else if (iEndMonth == iStartMonth) { if (iEndDay < iStartDay) bRetVal = false; else if (iEndDay == iStartDay) { if (iEndHour < iStartHour) bRetVal = false; else if (iEndHour == iStartHour) { if (iEndMinute < iStartMinute) bRetVal = false; else if (iEndMinute == iStartMinute) bRetVal = false; } } } } if (!bRetVal) { alert(m_datetime_msg_array['MSG_ERR_INCOMPATIBLE_DATES']); return false; } else return true; }, setHiddenDateTimeInterval: function (fromDate, fromTime, toDate, toTime) { document.getElementById(this.m_date1).value = fromDate; document.getElementById(this.m_time1).value = fromTime; document.getElementById(this.m_date2).value = toDate; document.getElementById(this.m_time2).value = toTime; }, cancelDateTimeInterval:function(control) { window['pickerControl'+ this.m_dateFrom].setValue(document.getElementById(this.m_date1).value); window['timePicker'+ this.m_timeFrom].setValue(document.getElementById(this.m_time1).value); window['pickerControl'+ this.m_dateTo].setValue(document.getElementById(this.m_date2).value); window['timePicker'+ this.m_timeTo].setValue(document.getElementById(this.m_time2).value); } } function setHiddenDateTime(dateFromId, timeFromId, dateToId, timeToId, dFrom, tFrom, dTo, tTo) { document.getElementById(dateFromId).value = dFrom; document.getElementById(timeFromId).value = tFrom; document.getElementById(dateToId).value = dTo; document.getElementById(timeToId).value = tTo; } function setDateValue(dateCtrl, dateVal) { if (dateCtrl != null && dateCtrl != '') { return window['pickerControl'+ dateCtrl].setValue(dateVal); } else { return ''; } } function setTimeValue(timeCtrl, timeVal) { if (timeCtrl != null && timeCtrl != '') { return window['timePicker'+ timeCtrl].setValue(timeVal); } else { return ''; } } function getDateFormatValue(dateCtrl) { if (dateCtrl != null && dateCtrl != '') { return window['pickerControl'+ dateCtrl].sGetFormatValue(); } else { return ''; } } function getTimeFormatValue(timeCtrl) { if (timeCtrl != null && timeCtrl != '') { return window['timePicker'+ timeCtrl].sGetFormatValue(); } else { return ''; } }