]> err.no Git - scalable-opengroupware.org/blobdiff - UI/WebServerResources/UIxAppointmentEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1294 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxAppointmentEditor.js
index 91c58ecab281b99540fd399809a84c20c4c342ef..12a3fe2818a7c15052d81e977a7430c12612f1a0 100644 (file)
@@ -1,37 +1,34 @@
 /*
- Copyright (C) 2005 SKYRIX Software AG
 Copyright (C) 2005 SKYRIX Software AG
  
- This file is part of OpenGroupware.org.
 This file is part of OpenGroupware.org.
  
- OGo is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the
- Free Software Foundation; either version 2, or (at your option) any
- later version.
 OGo is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the
 Free Software Foundation; either version 2, or (at your option) any
 later version.
  
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- License for more details.
 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
 WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 License for more details.
  
- You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING.  If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
 You should have received a copy of the GNU Lesser General Public
 License along with OGo; see the file COPYING.  If not, write to the
 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 02111-1307, USA.
 */
 
 var contactSelectorAction = 'calendars-contacts';
 
 function uixEarlierDate(date1, date2) {
   // can this be done in a sane way?
-//   cuicui = 'year';
   if (date1.getYear()  < date2.getYear()) return date1;
   if (date1.getYear()  > date2.getYear()) return date2;
   // same year
-//   cuicui += '/month';
   if (date1.getMonth() < date2.getMonth()) return date1;
   if (date1.getMonth() > date2.getMonth()) return date2;
-//   // same month
-//   cuicui += '/date';
+  //   // same month
   if (date1.getDate() < date2.getDate()) return date1;
   if (date1.getDate() > date2.getDate()) return date2;
   // same day
@@ -43,36 +40,34 @@ function validateAptEditor() {
 
   e = $('summary');
   if (e.value.length == 0) {
-    if (!confirm(labels.validate_notitle.decodeEntities()))
+    if (!confirm(labels.validate_notitle))
       return false;
   }
 
   e = $('startTime_date');
   if (e.value.length != 10) {
-    alert(labels.validate_invalid_startdate.decodeEntities());
+    alert(labels.validate_invalid_startdate);
     return false;
   }
   startdate = e.calendar.prs_date(e.value);
   if (startdate == null) {
-    alert(labels.validate_invalid_startdate.decodeEntities());
+    alert(labels.validate_invalid_startdate);
     return false;
   }
       
   e = $('endTime_date');
   if (e.value.length != 10) {
-    alert(labels.validate_invalid_enddate.decodeEntities());
+    alert(labels.validate_invalid_enddate);
     return false;
   }
   enddate = e.calendar.prs_date(e.value);
   if (enddate == null) {
-    alert(labels.validate_invalid_enddate.decodeEntities());
+    alert(labels.validate_invalid_enddate);
     return false;
   }
-//   cuicui = '';
   tmpdate = uixEarlierDate(startdate, enddate);
   if (tmpdate == enddate) {
-//     window.alert(cuicui);
-    alert(labels.validate_endbeforestart.decodeEntities());
+    alert(labels.validate_endbeforestart);
     return false;
   }
   else if (tmpdate == null /* means: same date */) {
@@ -83,14 +78,14 @@ function validateAptEditor() {
     end = parseInt(document.forms[0]['endTime_time_hour'].value);
 
     if (start > end) {
-      alert(labels.validate_endbeforestart.decodeEntities());
+      alert(labels.validate_endbeforestart);
       return false;
     }
     else if (start == end) {
       start = parseInt(document.forms[0]['startTime_time_minute'].value);
       end = parseInt(document.forms[0]['endTime_time_minute'].value);
       if (start > end) {
-       alert(labels.validate_endbeforestart.decodeEntities());
+       alert(labels.validate_endbeforestart);
        return false;
       }
     }
@@ -139,15 +134,13 @@ function toggleCycleVisibility(node, nodeName, hiddenValue) {
 
 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
   var uids = $('uixselector-participants-uidList');
-  log ("contactId: " + contactId);
+
   if (contactId)
     {
       var re = new RegExp("(^|,)" + contactId + "($|,)");
 
-      log ("uids: " + uids);
       if (!re.test(uids.value))
         {
-          log ("no match... realling adding");
           if (uids.value.length > 0)
             uids.value += ',' + contactId;
           else
@@ -159,8 +152,6 @@ function addContact(tag, fullContactName, contactId, contactName, contactEmail)
                               + ResourcesURL + '/abcard.gif" />'
                               + contactName + '</li>');
         }
-      else
-        log ("match... ignoring contact");
     }
 
   return false;
@@ -195,7 +186,6 @@ function _getShadowDate(which) {
   date.setHours(intValue);
   intValue = parseInt(window.timeWidgets[which]['minute'].getAttribute("shadow-value"));
   date.setMinutes(intValue);
-//   window.alert("shadow: " + date);
 
   return date;
 }
@@ -230,54 +220,88 @@ function setStartDate(newStartDate) {
 }
 
 function setEndDate(newEndDate) {
-//   window.alert(newEndDate);
   this._setDate('end', newEndDate);
 }
 
-function onAdjustEndTime(event) {
-  var dateDelta = (window.getStartDate().valueOf()
-                   - window.getShadowStartDate().valueOf());
-//   window.alert(window.getEndDate().valueOf() + '  ' + dateDelta);
-  var newEndDate = new Date(window.getEndDate().valueOf() + dateDelta);
-  window.setEndDate(newEndDate);
-  window.timeWidgets['start']['date'].updateShadowValue();
-  window.timeWidgets['start']['hour'].updateShadowValue();
-  window.timeWidgets['start']['minute'].updateShadowValue();
+function onAdjustTime(event) {
+  var endDate = window.getEndDate();
+  var startDate = window.getStartDate();
+  
+  if ($(this).readAttribute("id").startsWith("start")) {
+    // Start date was changed
+    var delta = window.getShadowStartDate().valueOf() -
+      startDate.valueOf();
+    var newEndDate = new Date(endDate.valueOf() - delta);
+    window.setEndDate(newEndDate);
+    
+    window.timeWidgets['end']['date'].updateShadowValue();
+    window.timeWidgets['end']['hour'].updateShadowValue();
+    window.timeWidgets['end']['minute'].updateShadowValue();
+    window.timeWidgets['start']['date'].updateShadowValue();
+    window.timeWidgets['start']['hour'].updateShadowValue();
+    window.timeWidgets['start']['minute'].updateShadowValue();
+  }
+  else {
+    // End date was changed
+    var delta = endDate.valueOf() - startDate.valueOf();  
+    if (delta < 0) {
+      alert(labels.validate_endbeforestart);
+      var oldEndDate = window.getShadowEndDate();
+      window.setEndDate(oldEndDate);
+
+      window.timeWidgets['end']['date'].updateShadowValue();
+      window.timeWidgets['end']['hour'].updateShadowValue();
+      window.timeWidgets['end']['minute'].updateShadowValue();
+    }
+  }
 }
 
 function onAllDayChanged(event) {
-   for (var type in window.timeWidgets) {
-      window.timeWidgets[type]['hour'].disabled = this.checked;
-      window.timeWidgets[type]['minute'].disabled = this.checked;
-   }
+  for (var type in window.timeWidgets) {
+    window.timeWidgets[type]['hour'].disabled = this.checked;
+    window.timeWidgets[type]['minute'].disabled = this.checked;
+  }
 }
 
 function initTimeWidgets(widgets) {
   this.timeWidgets = widgets;
 
-  Event.observe(widgets['start']['date'], "change", this.onAdjustEndTime, false);
-  Event.observe(widgets['start']['hour'], "change", this.onAdjustEndTime, false);
-  Event.observe(widgets['start']['minute'], "change", this.onAdjustEndTime, false);
+  Event.observe(widgets['start']['date'], "change",
+               this.onAdjustTime, false);
+  Event.observe(widgets['start']['hour'], "change",
+               this.onAdjustTime, false);
+  Event.observe(widgets['start']['minute'], "change",
+               this.onAdjustTime, false);
+
+  Event.observe(widgets['end']['date'], "change",
+               this.onAdjustTime, false);
+  Event.observe(widgets['end']['hour'], "change",
+               this.onAdjustTime, false);
+  Event.observe(widgets['end']['minute'], "change",
+               this.onAdjustTime, false);
 
   var allDayLabel = $("allDay");
   var input = $(allDayLabel).childNodesWithTag("input")[0];
   Event.observe(input, "change", onAllDayChanged.bindAsEventListener(input));
   if (input.checked) {
-     for (var type in widgets) {
-       widgets[type]['hour'].disabled = true;
-       widgets[type]['minute'].disabled = true;
-     }
+    for (var type in widgets) {
+      widgets[type]['hour'].disabled = true;
+      widgets[type]['minute'].disabled = true;
+    }
   }
 }
 
 function onAppointmentEditorLoad() {
-   var widgets = {'start': {'date': $("startTime_date"),
-                           'hour': $("startTime_time_hour"),
-                           'minute': $("startTime_time_minute")},
-                 'end': {'date': $("endTime_date"),
-                         'hour': $("endTime_time_hour"),
-                         'minute': $("endTime_time_minute")}};
-   initTimeWidgets(widgets);
+  assignCalendar('startTime_date');
+  assignCalendar('endTime_date');
+
+  var widgets = {'start': {'date': $("startTime_date"),
+                          'hour': $("startTime_time_hour"),
+                          'minute': $("startTime_time_minute")},
+                'end': {'date': $("endTime_date"),
+                        'hour': $("endTime_time_hour"),
+                        'minute': $("endTime_time_minute")}};
+  initTimeWidgets(widgets);
 }
 
-addEvent(window, 'load', onAppointmentEditorLoad);
+FastInit.addOnLoad(onAppointmentEditorLoad);