Handle tasks separately from other timeobjects.
authorJan Schneider <jan@horde.org>
Thu, 12 Nov 2009 22:18:25 +0000 (23:18 +0100)
committerJan Schneider <jan@horde.org>
Thu, 12 Nov 2009 23:16:10 +0000 (00:16 +0100)
Fix toggling calendars.

kronolith/ajax.php
kronolith/js/kronolith.js
kronolith/lib/Kronolith.php
kronolith/templates/index/index.inc

index 67c2605..646a010 100644 (file)
@@ -26,6 +26,7 @@ function getDriver($cal)
         $driver = '';
         break;
     case 'external':
+    case 'tasklists':
         $driver = 'Horde';
         break;
     case 'remote':
index c47ac69..e544c1f 100644 (file)
@@ -755,6 +755,35 @@ KronolithCore = {
             $('kronolithSharedCalendars').hide();
         }
 
+        my = 0;
+        shared = 0;
+        $H(Kronolith.conf.calendars.tasklists).each(function(cal) {
+            if (cal.value.owner) {
+                my++;
+                div = $('kronolithMyTasklists');
+                div.insert(new Element('SPAN', { 'class': 'kronolithCalEdit' })
+                           .insert('&rsaquo;'));
+            } else {
+                shared++;
+                div = $('kronolithSharedTasklists');
+            }
+            div.insert(new Element('DIV', { 'class': cal.value.show ? 'kronolithCalOn' : 'kronolithCalOff' })
+                       .store('calendar', cal.key)
+                       .store('calendarclass', 'tasklists')
+                       .setStyle({ backgroundColor: cal.value.bg, color: cal.value.fg })
+                       .update(cal.value.name.escapeHTML()));
+        });
+        if (my) {
+            $('kronolithMyTasklists').show();
+        } else {
+            $('kronolithMyTasklists').hide();
+        }
+        if (shared) {
+            $('kronolithSharedTasklists').show();
+        } else {
+            $('kronolithSharedTasklists').hide();
+        }
+
         $H(Kronolith.conf.calendars.external).each(function(cal) {
             var parts = cal.key.split('/'), api = parts.shift();
             if (!ext.get(api)) {
@@ -1438,11 +1467,10 @@ KronolithCore = {
     {
         if (Object.isUndefined(taskLists)) {
             taskLists = [];
-            // FIXME: Temporary hack to get the tasklists
-            $H(Kronolith.conf.calendars.external).each(function(cal) {
-                if (cal.key.startsWith('tasks') && cal.value.show)
+            $H(Kronolith.conf.calendars.tasklists).each(function(tasklist) {
+                if (tasklist.value.show)
                 {
-                    taskLists.push(cal.key.substring(6));
+                    taskLists.push(tasklist.key.substring(6));
                 }
             });
         }
@@ -2241,17 +2269,21 @@ KronolithCore = {
                 }
                 elt.toggleClassName('kronolithCalOn');
                 elt.toggleClassName('kronolithCalOff');
-                if (calClass == 'remote' || calClass == 'external') {
-                    if (calClass == 'external' && calendar.startsWith('tasks/')) {
-                        var taskList = calendar.substr(6);
-                        if (Object.isUndefined(this.tcache.get(taskList)) &&
-                            this.view == 'tasks') {
-                            this._loadTasks(this.taskType,[taskList]);
-                        } else {
-                            $('kronolithViewTasksBody').select('tr').findAll(function(el) { return el.retrieve('taskList') == taskList; }).invoke('toggle');
-                        }
+                switch (calClass) {
+                case 'tasklists':
+                    var taskList = calendar.substr(6);
+                    if (Object.isUndefined(this.tcache.get(taskList)) &&
+                        this.view == 'tasks') {
+                        this._loadTasks(this.taskType,[taskList]);
+                    } else {
+                        $('kronolithViewTasksBody').select('tr').findAll(function(el) { return el.retrieve('taskList') == taskList; }).invoke('toggle');
                     }
+                    // Fall through.
+                case 'remote':
+                case 'external':
+                case 'holiday':
                     calendar = calClass + '_' + calendar;
+                    break;
                 }
                 this.doAction('SaveCalPref', { toggle_calendar: calendar });
             }
index 92979ea..80aeae0 100644 (file)
@@ -150,6 +150,9 @@ class Kronolith
             // Turn debugging on?
             'debug' => !empty($conf['js']['debug']),
         );
+
+        // Calendars
+        $has_tasks = $GLOBALS['registry']->hasInterface('tasks');
         foreach (array(true, false) as $my) {
             foreach ($GLOBALS['all_calendars'] as $id => $calendar) {
                 $owner = $calendar->get('owner') == Horde_Auth::getAuth();
@@ -161,12 +164,35 @@ class Kronolith
                         'fg' => self::foregroundColor($calendar),
                         'bg' => self::backgroundColor($calendar),
                         'show' => in_array($id, $GLOBALS['display_calendars']),
-                        'edit' => $calendar->hasPermission(Horde_Auth::getAuth(), PERMS_READ));
+                        'edit' => $calendar->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT));
+                }
+            }
+
+            // Tasklists
+            if (!$has_tasks) {
+                continue;
+            }
+            foreach ($GLOBALS['registry']->tasks->listTasklists($my, PERMS_SHOW) as $id => $tasklist) {
+                $owner = $tasklist->get('owner') == Horde_Auth::getAuth();
+                if (($my && $owner) || (!$my && !$owner)) {
+                    $code['conf']['calendars']['tasklists']['tasks/' . $id] = array(
+                        'name' => ($owner ? '' : '[' . Horde_Auth::convertUsername($tasklist->get('owner'), false) . '] ')
+                            . $tasklist->get('name'),
+                        'owner' => $owner,
+                        'fg' => self::foregroundColor($tasklist),
+                        'bg' => self::backgroundColor($tasklist),
+                        'show' => in_array('tasks/' . $id, $GLOBALS['display_external_calendars']),
+                        'edit' => $tasklist->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT));
                 }
             }
         }
+
+        // Timeobjects
         foreach ($GLOBALS['all_external_calendars'] as $api => $categories) {
             foreach ($categories as $id => $name) {
+                if ($api == 'tasks') {
+                    continue;
+                }
                 $calendar = $api . '/' . $id;
                 $code['conf']['calendars']['external'][$calendar] = array(
                     'name' => $name,
@@ -176,6 +202,8 @@ class Kronolith
                     'show' => in_array($calendar, $GLOBALS['display_external_calendars']));
             }
         }
+
+        // Remote calendars
         foreach ($GLOBALS['all_remote_calendars'] as $calendar) {
             $code['conf']['calendars']['remote'][$calendar['url']] = array(
                 'name' => $calendar['name'],
@@ -183,6 +211,8 @@ class Kronolith
                 'bg' => self::backgroundColor($calendar),
                 'show' => in_array($calendar['url'], $GLOBALS['display_remote_calendars']));
         }
+
+        // Holidays
         foreach ($GLOBALS['all_holidays'] as $holiday) {
             $code['conf']['calendars']['holiday'][$holiday['id']] = array(
                 'name' => $holiday['title'],
@@ -794,16 +824,18 @@ class Kronolith
                 } else {
                     $GLOBALS['display_remote_calendars'][] = $calendarId;
                 }
-            } elseif (strncmp($calendarId, 'external_', 9) === 0) {
-                $calendarId = substr($calendarId, 9);
+            } elseif ((strncmp($calendarId, 'external_', 9) === 0 &&
+                       $calendarId = substr($calendarId, 9)) ||
+                      (strncmp($calendarId, 'tasklists_', 10) === 0 &&
+                       $calendarId = substr($calendarId, 10))) {
                 if (in_array($calendarId, $GLOBALS['display_external_calendars'])) {
                     $key = array_search($calendarId, $GLOBALS['display_external_calendars']);
                     unset($GLOBALS['display_external_calendars'][$key]);
                 } else {
                     $GLOBALS['display_external_calendars'][] = $calendarId;
                 }
-            } elseif (strncmp($calendarId, 'holidays_', 9) === 0) {
-                $calendarId = substr($calendarId, 9);
+            } elseif (strncmp($calendarId, 'holiday_', 8) === 0) {
+                $calendarId = substr($calendarId, 8);
                 if (in_array($calendarId, $GLOBALS['display_holidays'])) {
                     $key = array_search($calendarId, $GLOBALS['display_holidays']);
                     unset($GLOBALS['display_holidays'][$key]);
index 56ca1f3..b0a1419 100644 (file)
 
   <h3>
     <a href="#" class="kronolithAdd">+</a>
+    <span><?php echo _("My Task Lists") ?></span>
+  </h3>
+
+  <div id="kronolithMyTasklists" class="kronolithCalendars" style="display:none">
+  </div>
+
+  <h3>
+    <a href="#" class="kronolithAdd">+</a>
     <span><?php echo _("Shared Calendars") ?></span>
   </h3>
 
   <div id="kronolithSharedCalendars" class="kronolithCalendars" style="display:none">
   </div>
 
+  <h3>
+    <a href="#" class="kronolithAdd">+</a>
+    <span><?php echo _("Shared Task Lists") ?></span>
+  </h3>
+
+  <div id="kronolithSharedTasklists" class="kronolithCalendars" style="display:none">
+  </div>
+
   <div id="kronolithExternalCalendars"></div>
 
   <h3>