[dev] Patch for kronolith js

Jason Rust jrust at rustyparts.com
Tue May 27 16:32:05 PDT 2003


The attached patch cleans up the javascript for calculating the duration a bit
and fixes two bugs.  One bug occured when the duration of the
event was greater than 365 days, the other occured when the duration was
greater than the allowed end-date range.
-Jason

-- 
http://www.rustyparts.com/
ban the rustoleum!
-------------- next part --------------
Index: javascript.inc
===================================================================
RCS file: /repository/kronolith/templates/edit/javascript.inc,v
retrieving revision 1.19
diff -u -r1.19 javascript.inc
--- javascript.inc	11 Apr 2003 18:54:20 -0000	1.19
+++ javascript.inc	27 May 2003 23:09:01 -0000
@@ -124,6 +124,23 @@
     spanObj.innerHTML = '(' + wdays[date.getDay()] + ')';
 <?php endif; ?>
 }
+<?php if (!$prefs->getValue('twentyFour')): ?>
+
+// Converts a 12 hour based number to its 24 hour format
+function convertTo24Hour(in_hour, in_elementName) 
+{
+    var form = document.event;
+    if (form[in_elementName][1].checked) {
+        if (in_hour != 12) {
+            in_hour += 12;
+        }
+    } else if (in_hour == 12) {
+        in_hour = 0;
+    }
+
+    return in_hour;
+}
+<?php endif; ?>
 
 function updateDuration()
 {
@@ -133,21 +150,9 @@
     var endHour   = form.end_hour[form.end_hour.selectedIndex].value
 <?php else: ?>
     var startHour = parseInt(form.start_hour[form.start_hour.selectedIndex].value);
-    if (form.am_pm[1].checked) {
-        if (startHour != 12) {
-            startHour += 12;
-        }
-    } else if (startHour == 12) {
-        startHour = 0;
-    }
+    startHour = convertTo24Hour(startHour, 'am_pm');
     var endHour = parseInt(form.end_hour[form.end_hour.selectedIndex].value);
-    if (form.end_am_pm[1].checked) {
-        if (endHour != 12) {
-            endHour += 12;
-        }
-    } else if (endHour == 12) {
-        endHour = 0;
-    }
+    endHour = convertTo24Hour(endHour, 'end_am_pm');
 <?php endif; ?>
     var startDate = Date.UTC(form.start_year[form.start_year.selectedIndex].value,
                              form.start_month[form.start_month.selectedIndex].value - 1,
@@ -171,7 +176,12 @@
     var durHour = Math.floor(duration / 3600);
     duration %= 3600;
     var durMin = Math.floor(duration / 60 / 5);
-    form.dur_day.selectedIndex = durDay;
+    if (durDay < form.dur_day.options.length) {
+        form.dur_day.selectedIndex = durDay;
+    }
+    else {
+        form.dur_day.selectedIndex = form.dur_day.options.length - 1; 
+    }
     form.dur_hour.selectedIndex = durHour;
     form.dur_min.selectedIndex = durMin;
     form.whole_day.checked = false;
@@ -186,13 +196,7 @@
     var startHour = form.start_hour[form.start_hour.selectedIndex].value;
 <?php else: ?>
     var startHour = parseInt(form.start_hour[form.start_hour.selectedIndex].value);
-    if (form.am_pm[1].checked) {
-        if (startHour != 12) {
-            startHour += 12;
-        }
-    } else if (startHour == 12) {
-        startHour = 0;
-    }
+    startHour = convertTo24Hour(startHour, 'am_pm');
 <?php endif; ?>
     var startDate = new Date(form.start_year[form.start_year.selectedIndex].value,
                              form.start_month[form.start_month.selectedIndex].value - 1,
@@ -209,7 +213,14 @@
     if (endYear < 1900) {
         endYear += 1900;
     }
-    form.end_year.selectedIndex = endYear - yearDiff;
+    var yearIndex = endYear - yearDiff;
+    if (yearIndex < form.end_year.options.length) {
+        form.end_year.selectedIndex = yearIndex; 
+    }
+    else {
+        form.end_year.selectedIndex = form.end_year.length - 1;
+        updateDuration();
+    }
     form.end_month.selectedIndex = endDate.getMonth();
     form.end_day.selectedIndex = endDate.getDate() - 1;
     var endHour = endDate.getHours()


More information about the dev mailing list