Allow to switch search time.
authorJan Schneider <jan@horde.org>
Wed, 17 Mar 2010 22:08:35 +0000 (22:08 +0000)
committerJan Schneider <jan@horde.org>
Thu, 18 Mar 2010 15:42:33 +0000 (16:42 +0100)
kronolith/js/kronolith.js
kronolith/lib/Ajax/Application.php
kronolith/lib/Driver/Sql.php
kronolith/templates/index/agenda.inc

index ecb144b..8fa92e3 100644 (file)
@@ -34,6 +34,7 @@ KronolithCore = {
     mapMarker: null,
     map: null,
     mapInitialized: false,
+    search: 'future',
 
     doActionOpts: {
         onException: function(parentfunc, r, e)
@@ -353,8 +354,18 @@ KronolithCore = {
             break;
 
         case 'search':
-            var cals = [], term = locParts[0],
+            var cals = [], time = locParts[0], term = locParts[1],
                 query = Object.toJSON({ title: term });
+
+            if (!($w('all past future').include(time))) {
+                return;
+            }
+
+            this.search = time;
+            $w('All Past Future').each(function(time) {
+                $('kronolithSearch' + time).up().removeClassName('activeTab');
+            });
+            $('kronolithSearch' + this.search.capitalize()).up().addClassName('activeTab');
             this.closeView('agenda');
             this.updateView(null, 'search', term);
             $H(Kronolith.conf.calendars).each(function(type) {
@@ -366,7 +377,7 @@ KronolithCore = {
             });
             this.startLoading('search', query);
             this.doAction('searchEvents',
-                          { cals: cals.toJSON(), query: query },
+                          { cals: cals.toJSON(), query: query, time: this.search },
                           function(r) {
                               // Hide spinner.
                               this.loading--;
@@ -592,9 +603,13 @@ KronolithCore = {
                     day = dates[0].clone();
                 $('kronolithAgendaDate')
                     .update(this.setTitle(Kronolith.text.agenda + ' ' + dates[0].toString('d') + ' - ' + dates[1].toString('d')));
+                $('kronolithAgendaNavigation').show();
+                $('kronolithSearchNavigation').hide();
             } else {
                 $('kronolithAgendaDate')
                     .update(this.setTitle(Kronolith.text.searching.interpolate({ term: data })));
+                $('kronolithAgendaNavigation').hide();
+                $('kronolithSearchNavigation').show();
             }
 
             // Remove old rows. Maybe we should only rebuild the calendars if
@@ -3147,7 +3162,7 @@ KronolithCore = {
                     break;
 
                 case 'kronolithSearchForm':
-                    this.go('search:' + $F('kronolithSearchTerm'))
+                    this.go('search:' + this.search + ':' + $F('kronolithSearchTerm'))
                     e.stop();
                     break;
 
@@ -3510,7 +3525,28 @@ KronolithCore = {
                 return;
 
             case 'kronolithSearchButton':
-                this.go('search:' + $F('kronolithSearchTerm'))
+                this.go('search:' + this.search + ':' + $F('kronolithSearchTerm'));
+                e.stop();
+                break;
+
+            case 'kronolithSearchFuture':
+                if (this.search != 'future') {
+                    this.go('search:future:' + $F('kronolithSearchTerm'));
+                }
+                e.stop();
+                break;
+
+            case 'kronolithSearchPast':
+                if (this.search != 'past') {
+                    this.go('search:past:' + $F('kronolithSearchTerm'));
+                }
+                e.stop();
+                break;
+
+            case 'kronolithSearchAll':
+                if (this.search != 'all') {
+                    this.go('search:all:' + $F('kronolithSearchTerm'));
+                }
                 e.stop();
                 break;
 
index 5c63c29..bbf16ee 100644 (file)
@@ -252,6 +252,20 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
         if (!isset($query->end)) {
             $query->end = null;
         }
+        switch ($this->_vars->time) {
+        case 'all':
+            $query->start = null;
+            $query->end = null;
+            break;
+        case 'future':
+            $query->start = new Horde_Date($_SERVER['REQUEST_TIME']);
+            $query->end = null;
+            break;
+        case 'past':
+            $query->start = null;
+            $query->end = new Horde_Date($_SERVER['REQUEST_TIME']);
+            break;
+        }
 
         $cals = Horde_Serialize::unserialize($this->_vars->cals, Horde_Serialize::JSON);
         $events = array();
index 9df2e58..845337b 100644 (file)
@@ -181,19 +181,24 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
             $event = $this->getEvent($eventId);
             $showRecurrence = true;
             if ($event->recurs()) {
-                if (empty($query->end)) {
-                    $eventEnd = $event->recurrence->nextRecurrence($now);
-                    if (!$eventEnd) {
-                        continue;
-                    }
-                } else {
-                    $eventEnd = $query->end;
-                }
-                if (empty($query->start)) {
+                if (empty($query->start) && empty($query->end)) {
                     $eventStart = $event->start;
-                    $showRecurrence = false;
+                    $eventEnd = $event->end;
                 } else {
-                    $eventStart = $query->start;
+                    if (empty($query->end)) {
+                        $eventEnd = $event->recurrence->nextRecurrence($now);
+                        if (!$eventEnd) {
+                            continue;
+                        }
+                    } else {
+                        $eventEnd = $query->end;
+                    }
+                    if (empty($query->start)) {
+                        $eventStart = $event->start;
+                        $showRecurrence = false;
+                    } else {
+                        $eventStart = $query->start;
+                    }
                 }
             } else {
                 $eventStart = $event->start;
index 5a45e3c..771d501 100644 (file)
@@ -1,12 +1,19 @@
 <div id="kronolithViewAgenda" style="display:none">
 <table class="kronolithView">
-  <caption>
+  <caption class="tabset">
     <span id="kronolithLoadingagenda" class="kronolithLoading"></span>
     <span id="kronolithAgendaDate"></span>
     <span class="kronolithNavigation">
-      <a title="<?php echo _("Previous") ?>" class="kronolithPrev">&lt;</a>
-      <a class="kronolithGotoToday"><?php echo Horde::highlightAccessKey(_("_Today"), $todayAccessKey) ?></a>
-      <a title="<?php echo _("Next") ?>" class="kronolithNext">&gt;</a>
+      <span id="kronolithAgendaNavigation">
+        <a title="<?php echo _("Previous") ?>" class="kronolithPrev">&lt;</a>
+        <a class="kronolithGotoToday"><?php echo Horde::highlightAccessKey(_("_Today"), $todayAccessKey) ?></a>
+        <a title="<?php echo _("Next") ?>" class="kronolithNext">&gt;</a>
+      </span>
+      <ul id="kronolithSearchNavigation" style="display:none">
+        <li><a id="kronolithSearchAll"><?php echo _("All") ?></a></li>
+        <li><a id="kronolithSearchPast"><?php echo _("Past") ?></a></li>
+        <li class="activeTab"><a id="kronolithSearchFuture"><?php echo _("Future") ?></a></li>
+      </ul>
       <a class="kronolithPrint" onclick="print()" title="<?php echo _("Print") ?>"><span><?php echo _("Print") ?></span></a>
     </span>
   </caption>