544 lines
19 KiB
JavaScript
544 lines
19 KiB
JavaScript
var FacilitiesCommon = function ($) {
|
|
$.ajaxSetup({ cache: false })
|
|
var facilitiesCommon = this;
|
|
var objDate;
|
|
var startTime;
|
|
var endTime;
|
|
var startDateAMPM;
|
|
var endDateAMPM;
|
|
var startIndex;
|
|
var endIndex;
|
|
var startValue;
|
|
var endValue;
|
|
|
|
//Create array to hold day of week values
|
|
facilitiesCommon.weekday = new Array(7);
|
|
weekday[0] = "Sunday";
|
|
weekday[1] = "Monday";
|
|
weekday[2] = "Tuesday";
|
|
weekday[3] = "Wednesday";
|
|
weekday[4] = "Thursday";
|
|
weekday[5] = "Friday";
|
|
weekday[6] = "Saturday";
|
|
|
|
facilitiesCommon.bothRequired = function (firstID, secondID, firstName, secondName, errorMessageFirst, errorMessageSecond) {
|
|
if (!($(firstID).val() == '' && $(secondID).val() == '')) {
|
|
if ($(firstID).val() == '') {
|
|
alert(firstName + ' ' + errorMessageFirst);
|
|
return false;
|
|
}
|
|
if ($(secondID).val() == '') {
|
|
alert(secondName + ' ' + errorMessageSecond);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.validateDateTimeWithBothOptional = function (startDateID, endDateID, startTimeID, endTimeID, allowEqualDates, allowEqualTimes,
|
|
allowDatesInThePast, allowTimesWithoutDates, startDateName, endDateName, startTimeName, endTimeName, wrongTimeFormatMessage, unknownErrorMessage,
|
|
dateInPastErrorMessage, wrongTimeOrderErrorMessage, bothDatesRequiredErrorMessage, bothTimesRequiredErrorMessageFirst,
|
|
bothTimesRequiredErrorMessageSecond, datesRequiredIfTimesSuppliedErrorMessage) {
|
|
|
|
if (!facilitiesCommon.bothRequired(startDateID, endDateID, startDateName, endDateName, bothDatesRequiredErrorMessage, bothDatesRequiredErrorMessage)) {
|
|
return false;
|
|
}
|
|
|
|
if (!facilitiesCommon.bothRequired(startTimeID, endTimeID, startTimeName, endTimeName, bothTimesRequiredErrorMessageFirst, bothTimesRequiredErrorMessageSecond)) {
|
|
return false;
|
|
}
|
|
|
|
if (!allowTimesWithoutDates) {
|
|
if (!($(startTimeID).val() == '' && $(endTimeID).val() == '')
|
|
&& (getDateFromInput(startDateID) == '' || getDateFromInput(endDateID) == '')) {
|
|
alert(datesRequiredIfTimesSuppliedErrorMessage);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return facilitiesCommon.validateDateTime(startDateID, endDateID, startTimeID, endTimeID, allowEqualDates, allowEqualTimes, false, false, true, allowDatesInThePast, false, false, false, startDateName, endDateName, startTimeName, endTimeName, wrongTimeFormatMessage, unknownErrorMessage, dateInPastErrorMessage, wrongTimeOrderErrorMessage);
|
|
};
|
|
|
|
facilitiesCommon.validateDateTime = function (startDateID, endDateID, startTimeID, endTimeID, allowEqualDates, allowEqualTimes, startDateRequired, endDateRequired, startRequiredIfEndSpecified, allowDatesInThePast, startTimeRequired, endTimeRequired, allowWrongTimeOrderIfDatesNotSame, startDateName, endDateName, startTimeName, endTimeName, wrongTimeFormatMessage, unknownErrorMessage, dateInPastErrorMessage, wrongTimeOrderErrorMessage) {
|
|
//step 1: declare
|
|
objDate = new dateValidator();
|
|
objDate.ysnEndDateRequired = endDateRequired;
|
|
|
|
//step 2: setup everything but actual time values
|
|
facilitiesCommon.initialSetup(startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified, allowEqualTimes, startTimeRequired, endTimeRequired, startTimeID, endTimeID, startDateName, endDateName, startTimeName, endTimeName);
|
|
|
|
//step 3: validate dates
|
|
if (!facilitiesCommon.validateDates(unknownErrorMessage, dateInPastErrorMessage, startDateID, endDateID, startDateName, endDateName, allowDatesInThePast)) {
|
|
return false;
|
|
}
|
|
|
|
//step 4: check time format
|
|
if (!facilitiesCommon.checkTimesForAMPM(startTimeName, endTimeName, wrongTimeFormatMessage)) {
|
|
return false;
|
|
}
|
|
|
|
//step 5: separate time values and am/pm
|
|
facilitiesCommon.extractAndSetupTimeVars();
|
|
|
|
//step 6: check for empty time values
|
|
if (!facilitiesCommon.checkEmptyTimes(startTimeName, endTimeName, startTimeRequired, endTimeRequired)) {
|
|
return false;
|
|
}
|
|
|
|
//step 6: setup time values
|
|
facilitiesCommon.postSetupTimes();
|
|
|
|
//step 7: validate times
|
|
|
|
// If either the end or start time is required, then we assume that times are required. This logic is odd, but since
|
|
// the start time and end time should either both be required, or both be optional, this will work.
|
|
|
|
var timesRequired = startTimeRequired || endTimeRequired;
|
|
var shouldCheckStartTimeInPast = facilitiesCommon.shouldCheckTimeInPast(startDateID, allowDatesInThePast, timesRequired);
|
|
var shouldCheckEndTimeInPast = facilitiesCommon.shouldCheckTimeInPast(endDateID, allowDatesInThePast, timesRequired);
|
|
|
|
if (!facilitiesCommon.validateTimes(unknownErrorMessage, allowWrongTimeOrderIfDatesNotSame, wrongTimeOrderErrorMessage, allowEqualTimes, startTimeName, endTimeName, shouldCheckStartTimeInPast, shouldCheckEndTimeInPast, dateInPastErrorMessage)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
// Returns true if the validation functions should check that the supplied times are in the past.
|
|
facilitiesCommon.shouldCheckTimeInPast = function (dateID, allowTimesInPast, timesRequired) {
|
|
|
|
if (!timesRequired)
|
|
return false;
|
|
|
|
var datesAreSame = function (date1Value, date2Value) {
|
|
return (date1Value.getFullYear() == date2Value.getFullYear()
|
|
&& date1Value.getMonth() == date2Value.getMonth()
|
|
&& date1Value.getDate() == date2Value.getDate());
|
|
};
|
|
|
|
var date = new Date($(dateID).val());
|
|
|
|
var today = new Date();
|
|
|
|
if (allowTimesInPast) {
|
|
return false;
|
|
} else {
|
|
if (datesAreSame(date, today))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
facilitiesCommon.validateTimeOnly = function (startTimeID, endTimeID, allowEqualTimes, startTimeRequired, endTimeRequired, startTimeName, endTimeName,
|
|
wrongTimeFormatMessage, unknownErrorMessage, wrongTimeOrderErrorMessage) {
|
|
|
|
//step 1: declare
|
|
objDate = new dateValidator();
|
|
|
|
facilitiesCommon.setupTimeParameters(allowEqualTimes, startTimeRequired, endTimeRequired);
|
|
startValue =$(startTimeID).val().toLowerCase();
|
|
endValue = $(endTimeID).val().toLowerCase();
|
|
|
|
//step 1: check time format
|
|
if (!facilitiesCommon.checkTimesForAMPM(startTimeName, endTimeName, wrongTimeFormatMessage, true)) {
|
|
return false;
|
|
}
|
|
|
|
//step 2: separate time values and am/pm
|
|
facilitiesCommon.extractAndSetupTimeVars();
|
|
|
|
//step 3: check for empty time values
|
|
if (!facilitiesCommon.checkEmptyTimes(startTimeName, endTimeName, startTimeRequired, endTimeRequired)) {
|
|
return false;
|
|
}
|
|
|
|
//step 4: setup time values
|
|
facilitiesCommon.postSetupTimes();
|
|
|
|
//step 5: validate times
|
|
if (!facilitiesCommon.validateTimeOrderNoDates(wrongTimeOrderErrorMessage, allowEqualTimes, startTimeName, endTimeName)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.validateDateOnly = function(unknownErrorMessage, dateInPastErrorMessage, startDateID, endDateID, startDateName, endDateName, allowDatesInThePast,
|
|
allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified, EndRequiredIfStartSpecified) {
|
|
|
|
//step 1: declare
|
|
objDate = new dateValidator();
|
|
|
|
//step 2: initialzie variables
|
|
facilitiesCommon.setupDates(startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified, startDateID, endDateID);
|
|
facilitiesCommon.setupNames(startDateName, endDateName, null, null);
|
|
|
|
//step 3: validate dates
|
|
if (!facilitiesCommon.validateDates(unknownErrorMessage, dateInPastErrorMessage, startDateID, endDateID, startDateName, endDateName, allowDatesInThePast)) {
|
|
return false;
|
|
}
|
|
|
|
var endDateVal = getDateFromInput(endDateID);
|
|
|
|
if (EndRequiredIfStartSpecified && getDateFromInput(startDateID) != null && (endDateVal == null || TrimString(endDateVal)) == "") {
|
|
alert("A " + endDateName + " must be specified if a " + startDateName + " was entered.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.initialSetup = function (startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified, allowEqualTimes, startTimeRequired, endTimeRequired, startTimeID, endTimeID, startDateName, endDateName, startTimeName, endTimeName) {
|
|
facilitiesCommon.setupDates(startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified);
|
|
facilitiesCommon.initialSetupTimes(allowEqualTimes, startTimeRequired, endTimeRequired, startTimeID, endTimeID);
|
|
facilitiesCommon.setupNames(startDateName, endDateName, startTimeName, endTimeName);
|
|
};
|
|
|
|
facilitiesCommon.setupNames = function (startDateName, endDateName, startTimeName, endTimeName) {
|
|
objDate.strStartDateID = startDateName;
|
|
objDate.strEndDateID = endDateName;
|
|
objDate.strStartTimeID = startTimeName;
|
|
objDate.strEndTimeID = endTimeName;
|
|
};
|
|
|
|
facilitiesCommon.setupDates = function (startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified) {
|
|
facilitiesCommon.setupDateParameters(startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified);
|
|
facilitiesCommon.setupDateValues(startDateID, endDateID);
|
|
};
|
|
|
|
facilitiesCommon.setupDateParameters = function (startDateID, endDateID, allowEqualDates, startDateRequired, endDateRequired, startRequiredIfEndSpecified) {
|
|
objDate.ysnAllowEqualDates = allowEqualDates;
|
|
objDate.ysnStartDateRequired = startDateRequired;
|
|
objDate.ysnEndDateRequired = endDateRequired;
|
|
objDate.ysnRequireStartDateIfEndSpecified = startRequiredIfEndSpecified;
|
|
};
|
|
|
|
facilitiesCommon.setupDateValues = function (startDateID, endDateID) {
|
|
objDate.setStartDate(getDateFromInput(startDateID));
|
|
objDate.setEndDate(getDateFromInput(endDateID));
|
|
};
|
|
|
|
facilitiesCommon.initialSetupTimes = function (allowEqualTimes, startTimeRequired, endTimeRequired, startTimeID, endTimeID) {
|
|
facilitiesCommon.setupTimeParameters(allowEqualTimes, startTimeRequired, endTimeRequired);
|
|
facilitiesCommon.setupTimeValues(startTimeID, endTimeID);
|
|
};
|
|
|
|
facilitiesCommon.setupTimeParameters = function (allowEqualTimes, startTimeRequired, endTimeRequired) {
|
|
objDate.ysnAllowEqualTimes = allowEqualTimes;
|
|
objDate.ysnStartTimeRequired = startTimeRequired;
|
|
objDate.ysnEndTimeRequired = endTimeRequired;
|
|
};
|
|
|
|
facilitiesCommon.setupTimeValues = function (startTimeID, endTimeID) {
|
|
startValue = $(startTimeID).val().toLowerCase();
|
|
endValue = $(endTimeID).val().toLowerCase();
|
|
};
|
|
|
|
facilitiesCommon.checkEmptyTimes = function (startTimeName, endTimeName, startTimeRequired, endTimeRequired) {
|
|
if (startTimeRequired && startValue == '') {
|
|
alert(startTimeName + ' cannot be blank.');
|
|
return false;
|
|
}
|
|
if (endTimeRequired && endValue == '') {
|
|
alert(endTimeName + ' cannot be blank.');
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.checkTimesForAMPM = function (startTimeName, endTimeName, wrongTimeFormatMessage, nameAfter) {
|
|
if (!facilitiesCommon.checkAMPMFormat(startValue, startTimeName, wrongTimeFormatMessage, nameAfter)) {
|
|
return false;
|
|
}
|
|
if (!facilitiesCommon.checkAMPMFormat(endValue, endTimeName, wrongTimeFormatMessage, nameAfter)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.checkAMPMFormat = function (timeValue, timeName, wrongTimeFormatMessage, nameAfter) {
|
|
if (timeValue != '') {
|
|
if (timeValue.indexOf(' am') == -1 && timeValue.indexOf(' pm') == -1) {
|
|
|
|
var errMSG = timeName + ' ' + wrongTimeFormatMessage + '.';
|
|
|
|
if (nameAfter) {
|
|
errMSG = wrongTimeFormatMessage + ' ' + timeName + '.';
|
|
}
|
|
|
|
alert(errMSG);
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.extractAndSetupTimeVars = function () {
|
|
if (startValue.indexOf('am') != -1) {
|
|
startDateAMPM = 'am';
|
|
startIndex = startValue.indexOf('am');
|
|
startTime = startValue.substring(0, startIndex - 1);
|
|
}
|
|
else {
|
|
startDateAMPM = 'pm';
|
|
startIndex = startValue.indexOf('pm');
|
|
startTime = startValue.substring(0, startIndex - 1);
|
|
}
|
|
if (endValue.indexOf('am') != -1) {
|
|
endDateAMPM = 'am';
|
|
endIndex = endValue.indexOf('am');
|
|
endTime = endValue.substring(0, endIndex - 1);
|
|
}
|
|
else {
|
|
endDateAMPM = 'pm';
|
|
endIndex = endValue.indexOf('pm');
|
|
endTime = endValue.substring(0, endIndex - 1);
|
|
}
|
|
};
|
|
|
|
facilitiesCommon.postSetupTimes = function () {
|
|
objDate.dtiStartTime = startTime;
|
|
objDate.dtiEndTime = endTime;
|
|
objDate.strStartAMPM = startDateAMPM;
|
|
objDate.strEndAMPM = endDateAMPM;
|
|
};
|
|
|
|
facilitiesCommon.checkDatesInPast = function (startDateID, endDateID, dateInPastErrorMessage, startDateName, endDateName) {
|
|
var today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
if (new Date(getDateFromInput(startDateID)) < today) {
|
|
alert(startDateName + ' ' + dateInPastErrorMessage);
|
|
return false;
|
|
}
|
|
|
|
// Do not validate the end date if we are allowing it to be null or empty.
|
|
if (facilitiesCommon.allowNullEndDate) {
|
|
return true;
|
|
}
|
|
|
|
if (new Date(getDateFromInput(endDateID)) < today) {
|
|
alert(endDateName + ' ' + dateInPastErrorMessage);
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.validateDates = function (unknownErrorMessage, dateInPastErrorMessage, startDateID, endDateID, startDateName, endDateName, allowDatesInThePast) {
|
|
if (!objDate.dateOrderValidate()) {
|
|
alert(objDate.error ? objDate.error
|
|
: unknownErrorMessage);
|
|
return false;
|
|
}
|
|
if (!allowDatesInThePast && !facilitiesCommon.checkDatesInPast(startDateID, endDateID, dateInPastErrorMessage, startDateName, endDateName)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.validateTimeOrderNoDates = function (wrongTimeOrderErrorMessage, allowEqualTimes, startTimeName, endTimeName) {
|
|
if (startTime == '' || endTime == '') {
|
|
return true;
|
|
}
|
|
var stime = objDate.convertTo24Hour(startTime, startDateAMPM, '01/01/2000');
|
|
var etime = objDate.convertTo24Hour(endTime, endDateAMPM, '01/01/2000');
|
|
if (allowEqualTimes) {
|
|
if (stime > etime) {
|
|
alert('The ' + endTimeName + ' ' + wrongTimeOrderErrorMessage + ' ' + startTimeName + '.');
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
if (stime >= etime) {
|
|
alert('The ' + endTimeName + ' ' + wrongTimeOrderErrorMessage + ' ' + startTimeName + '.');
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.validateTimes = function (unknownErrorMessage, allowWrongTimeOrderIfDatesNotSame, wrongTimeOrderErrorMessage, allowEqualTimes, startTimeName, endTimeName, shouldCheckStartTimeInPast, shouldCheckEndTimeInPast, timeInPastErrorMessage) {
|
|
if (shouldCheckStartTimeInPast && !checkTimeInPast(startTimeName, endTimeName, timeInPastErrorMessage, 'startTime')) {
|
|
return false;
|
|
}
|
|
if (shouldCheckEndTimeInPast && !checkTimeInPast(startTimeName, endTimeName, timeInPastErrorMessage, 'endTime')) {
|
|
return false;
|
|
}
|
|
if (!allowWrongTimeOrderIfDatesNotSame) {
|
|
return facilitiesCommon.validateTimeOrderNoDates(wrongTimeOrderErrorMessage, allowEqualTimes, startTimeName, endTimeName);
|
|
}
|
|
if (startTime != '' && !objDate.timeOrderValidate()) {
|
|
alert(objDate.error ? objDate.error : unknownErrorMessage);
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
// Ensures the start and end times occure at some point in the future.
|
|
facilitiesCommon.checkTimeInPast = function (startTimeName, endTimeName, timeInPastErrorMessage, whichTime) {
|
|
var today = new Date();
|
|
today.setFullYear(2000);
|
|
today.setMonth(0);
|
|
today.setDate(1);
|
|
var currentTime = today.getTime();
|
|
|
|
var stime = objDate.convertTo24Hour(startTime, startDateAMPM, '01/01/2000');
|
|
var etime = objDate.convertTo24Hour(endTime, endDateAMPM, '01/01/2000');
|
|
|
|
if (whichTime == 'startTime' && stime < today) {
|
|
alert(startTimeName + ' ' + timeInPastErrorMessage);
|
|
return false;
|
|
}else if (whichTime == 'endTime' && etime < today) {
|
|
alert(endTimeName + ' ' + timeInPastErrorMessage);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
|
|
facilitiesCommon.validateMoneyRange = function (lowMoneyID, highMoneyID, lowMoneyName, highMoneyName, isLowMoneyRequired, isHighMoneyRequired, wrongMoneyFormatMessage, wrongRangeErrorMessage) {
|
|
if (!facilitiesCommon.validateMoney(lowMoneyID, lowMoneyName, wrongMoneyFormatMessage, isLowMoneyRequired)) {
|
|
return false;
|
|
}
|
|
if (!facilitiesCommon.validateMoney(highMoneyID, highMoneyName, wrongMoneyFormatMessage, isHighMoneyRequired)) {
|
|
return false;
|
|
}
|
|
if (!facilitiesCommon.validateMoneyOrder(lowMoneyID, highMoneyID, lowMoneyName, highMoneyName, wrongRangeErrorMessage)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.validateMoneyOrder = function (lowMoneyID, highMoneyID, lowMoneyName, highMoneyName, wrongRangeErrorMessage) {
|
|
if ((facilitiesCommon.extractMoneyValue(highMoneyID) != '')
|
|
&& (facilitiesCommon.extractMoneyValue(lowMoneyID) != '')
|
|
&& (parseFloat(facilitiesCommon.extractMoneyValue(highMoneyID))
|
|
< parseFloat(facilitiesCommon.extractMoneyValue(lowMoneyID)))) {
|
|
alert(lowMoneyName + ' ' + wrongRangeErrorMessage + ' ' + highMoneyName + '.');
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.extractMoneyValue = function (id) {
|
|
var v = $(id).val();
|
|
if (v && v != '') {
|
|
if (v.startsWith('$')) {
|
|
return v.substring(1).replace(',', '');
|
|
}
|
|
}
|
|
return v;
|
|
};
|
|
|
|
facilitiesCommon.validateMoney = function (id, moneyName, wrongMoneyFormatMessage, isRequired) {
|
|
if ((!isRequired) && ($(id).val() == '')) {
|
|
return true;
|
|
}
|
|
if (!facilitiesCommon.isValidMoney($(id).val())) {
|
|
alert(wrongMoneyFormatMessage + ' ' + moneyName);
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
facilitiesCommon.isValidMoney = function (value) {
|
|
var isValid = false;
|
|
if (value && value != '')
|
|
isValid = /^\$?\s*\d+(,\d{3})*(\.\d{1,2})?$/.test(value);
|
|
return isValid;
|
|
};
|
|
|
|
facilitiesCommon.AJAX = function (url, type, json, callBack, showLoadingMessage) {
|
|
if (showLoadingMessage == null) {
|
|
showLoadingMessage = true;
|
|
}
|
|
$.ajax({
|
|
url: url,
|
|
type: type,
|
|
data: json,
|
|
success: function (response) {
|
|
if (response.ErrorMessage)
|
|
alert(response.ErrorMessage);
|
|
else if (response.RedirectURL)
|
|
window.location.href = response.RedirectURL;
|
|
else if (callBack)
|
|
callBack(response);
|
|
},
|
|
beforeSend: function () {
|
|
if (showLoadingMessage) {
|
|
ajaxPostBackStart('Loading');
|
|
}
|
|
},
|
|
complete: function () {
|
|
if (showLoadingMessage) {
|
|
ajaxPostBackEnd();
|
|
}
|
|
},
|
|
error: function (xhr, textStatus, exception) {
|
|
alert('Error: ' + xhr.statusText + '\nStatus: ' + xhr.status);
|
|
}
|
|
});
|
|
};
|
|
|
|
facilitiesCommon.formatAMPM = function (date, hour) {
|
|
var hours;
|
|
if (hour != undefined && hour !== '')
|
|
hours = hour;
|
|
else
|
|
hours = date.getHours();
|
|
var minutes = date.getMinutes();
|
|
var ampm = hours >= 12 ? 'PM' : 'AM';
|
|
var hours = hours % 12;
|
|
hours = hours ? hours : 12; // the hour '0' should be '12'
|
|
minutes = minutes < 10 ? '0' + minutes : minutes;
|
|
strTime = hours + ':' + minutes + ' ' + ampm;
|
|
return strTime;
|
|
};
|
|
|
|
facilitiesCommon.bindControl = function (id, action, returnFalse, bindKeyPress, bindClick) {
|
|
if (bindKeyPress) {
|
|
$(id).keypress(function () {
|
|
$(this).click();
|
|
});
|
|
}
|
|
|
|
if (bindClick) {
|
|
$(id).click(function () {
|
|
action();
|
|
if (returnFalse) {
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
facilitiesCommon.bindChangeEvent = function (id, action, returnFalse) {
|
|
$(id).bind('change', function () {
|
|
action();
|
|
if (returnFalse) {
|
|
return false;
|
|
}
|
|
});
|
|
};
|
|
|
|
facilitiesCommon.unbindChangeEvent = function (id) {
|
|
$(id).unbind('change');
|
|
};
|
|
|
|
facilitiesCommon.unbindClickEvent = function (id) {
|
|
$(id).unbind('click');
|
|
};
|
|
|
|
facilitiesCommon.unbindKeyPressEvent = function (id) {
|
|
$(id).unbind('keypress');
|
|
};
|
|
|
|
facilitiesCommon.getDateFromJSONDate = function (jsonDate) {
|
|
return new Date(parseInt(jsonDate.substr(6)));
|
|
};
|
|
|
|
return this;
|
|
} (jQuery);
|
|
|