Sort new agenda day into the table. Necessary for searches where events don't
authorJan Schneider <jan@horde.org>
Sun, 7 Jun 2009 15:48:36 +0000 (17:48 +0200)
committerJan Schneider <jan@horde.org>
Sun, 7 Jun 2009 15:48:36 +0000 (17:48 +0200)
arrive in chronological order.

kronolith/js/src/kronolith.js

index 52d6f08..03de7e2 100644 (file)
@@ -498,11 +498,23 @@ KronolithCore = {
         row.addClassName('kronolithRow' + (body.select('tr').length % 2 == 1 ? 'Odd' : 'Even'))
             .down()
             .setText(this.parseDate(date).toString('D'))
+            .writeAttribute('date', date)
             .next()
             .writeAttribute('id', 'kronolithAgendaDay' + date);
 
         // Insert row.
-        body.insert(row.show());
+        var nextRow;
+        body.childElements().each(function(elm) {
+            if (elm.down().readAttribute('date') > date) {
+                nextRow = elm;
+                return;
+            }
+        });
+        if (nextRow) {
+            nextRow.insert({ 'before': row.show() });
+        } else {
+            body.insert(row.show());
+        }
 
         return row;
     },