From 9b54a943f474cdb02bacff5fc51e0ffbf46dc818 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 20 Jul 2005 09:55:59 +0000 Subject: [PATCH] implemented start < end validation (#1478) git-svn-id: http://svn.opengroupware.org/SOGo/trunk@836 d1b88da0-ebda-0310-925b-ed51d893ca5b --- .../English.lproj/Localizable.strings | 2 + SOGo/UI/WebServerResources/ChangeLog | 5 ++ .../UIxAppointmentEditor.js | 87 ++++++++++++++----- 3 files changed, 72 insertions(+), 22 deletions(-) diff --git a/SOGo/UI/Scheduler/English.lproj/Localizable.strings b/SOGo/UI/Scheduler/English.lproj/Localizable.strings index 12ee0507..ce93a876 100644 --- a/SOGo/UI/Scheduler/English.lproj/Localizable.strings +++ b/SOGo/UI/Scheduler/English.lproj/Localizable.strings @@ -216,3 +216,5 @@ validate_notitle = "No title is set, continue?"; validate_invalid_startdate = "Incorrect startdate field!"; validate_invalid_enddate = "Incorrect enddate field!"; +validate_endbeforestart = "Enddate is before startdate!"; + diff --git a/SOGo/UI/WebServerResources/ChangeLog b/SOGo/UI/WebServerResources/ChangeLog index 8bb43e21..5cc90a10 100644 --- a/SOGo/UI/WebServerResources/ChangeLog +++ b/SOGo/UI/WebServerResources/ChangeLog @@ -1,3 +1,8 @@ +2005-07-20 Helge Hess + + * UIxAppointmentEditor.js: properly validate startdate/enddate so that + startdate is always before the enddate (#1478) + 2005-07-18 Helge Hess * generic.js: added regex for email field checks diff --git a/SOGo/UI/WebServerResources/UIxAppointmentEditor.js b/SOGo/UI/WebServerResources/UIxAppointmentEditor.js index 0285a1bb..3277096d 100644 --- a/SOGo/UI/WebServerResources/UIxAppointmentEditor.js +++ b/SOGo/UI/WebServerResources/UIxAppointmentEditor.js @@ -19,32 +19,75 @@ 02111-1307, USA. */ +function uixEarlierDate(date1, date2) { + // can this be done in a sane way? + if (date1.getYear() < date2.getYear()) return date1; + if (date1.getYear() > date2.getYear()) return date2; + // same year + if (date1.getMonth() < date2.getMonth()) return date1; + if (date1.getMonth() > date2.getMonth()) return date2; + // same month + if (date1.getDay() < date2.getDay()) return date1; + if (date1.getDay() > date2.getDay()) return date2; + // same day + return null; +} + function validateAptEditor() { - var e; + var e, startdate, enddate, tmpdate; - e = document.getElementById('summary'); - if (e.value.length == 0) { - if (!confirm(labels.validate_notitle)) - return false; - } + e = document.getElementById('summary'); + if (e.value.length == 0) { + if (!confirm(labels.validate_notitle)) + return false; + } - e = document.getElementById('startTime_date'); - if (e.value.length != 10) { - alert(labels.validate_invalid_startdate); - return false; - } - if (calendar_startTime_date.prs_date(e.value) == null) - return false; + e = document.getElementById('startTime_date'); + if (e.value.length != 10) { + alert(labels.validate_invalid_startdate); + return false; + } + startdate = calendar_startTime_date.prs_date(e.value); + if (startdate == null) { + alert(labels.validate_invalid_startdate); + return false; + } - e = document.getElementById('endTime_date'); - if (e.value.length != 10) { - alert(labels.validate_invalid_enddate); - return false; - } - if (calendar_endTime_date.prs_date(e.value) == null) + e = document.getElementById('endTime_date'); + if (e.value.length != 10) { + alert(labels.validate_invalid_enddate); + return false; + } + enddate = calendar_endTime_date.prs_date(e.value); + if (enddate == null) { + alert(labels.validate_invalid_enddate); + return false; + } + + tmpdate = uixEarlierDate(startdate, enddate); + if (tmpdate == enddate) { + alert(labels.validate_endbeforestart); + return false; + } + else if (tmpdate == null /* means: same date */) { + // TODO: check time + var start, end; + + start = document.forms[0]['startTime_time_hour'].value; + end = document.forms[0]['endTime_time_hour'].value; + if (start > end) { + alert(labels.validate_endbeforestart); + return false; + } + else if (start == end) { + start = document.forms[0]['startTime_time_minute'].value; + end = document.forms[0]['endTime_time_minute'].value; + if (start > end) { + alert(labels.validate_endbeforestart); return false; + } + } + } - // TODO: parse start/enddate and ensure that start is before end - - return true; + return true; } -- 2.39.5