From: Jan Schneider Date: Thu, 5 Mar 2009 00:42:50 +0000 (+0100) Subject: Build calendar list on the client side. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=66c3d7d76037e53defd7f75e204652e91cedcf9d;p=horde.git Build calendar list on the client side. Retrieve each calendar's events seperately. --- diff --git a/kronolith/ajax.php b/kronolith/ajax.php index af2b0602b..078d2d322 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -56,17 +56,19 @@ switch ($action) { case 'ListEvents': $start = new Horde_Date(Util::getFormData('start')); $end = new Horde_Date(Util::getFormData('end')); - $dates = Kronolith::listEvents($start, $end); - if (is_a($dates, 'PEAR_Error')) { - $notification->push($dates, 'horde.error'); + $cal = Util::getFormData('cal'); + list($driver, $calendar) = explode('|', $cal); + $kronolith_driver = Kronolith::getDriver($driver, $calendar); + $events = $kronolith_driver->listEvents($start, $end, true, false, true); + if (is_a($events, 'PEAR_Error')) { + $notification->push($events, 'horde.error'); $result = false; } else { $result = new stdClass; + $result->cal = $cal; $result->sig = $start->dateString() . $end->dateString(); - foreach ($dates as $date => $events) { - foreach ($events as $id => $event) { - $result->events[$date][$id] = $event->toJSON(); - } + if (count($events)) { + $result->events = $events; } } break; diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index cee2fd7b9..e2884d913 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -17,12 +17,13 @@ var frames = { horde_main: true }, KronolithCore = { // Vars used and defaulting to null/false: // DMenu, alertrequest, inAjaxCallback, is_logout, onDoActionComplete, - // eventForm, eventsLoading + // eventForm view: '', calendars: [], ecache: {}, efifo: {}, + eventsLoading: $H(), date: new Date(), doActionOpts: { @@ -468,11 +469,78 @@ KronolithCore = { }, /** + * Rebuilds the list of calendars. */ - _loadEvents: function(firstDay, lastDay, callback, calendar) + updateCalendarList: function() { - this.eventsLoading = firstDay.dateString() + lastDay.dateString(); - this.doAction('ListEvents', { start: firstDay.dateString(), end: lastDay.dateString() }, callback); + var internal = $H(Kronolith.conf.calendars.internal), + remote = $H(Kronolith.conf.calendars.remote), + my = 0, shared = 0, div; + + internal.each(function(cal) { + if (cal.value.owner) { + my++; + div = $('kronolithMyCalendars'); + } else { + shared++; + div = $('kronolithSharedCalendars'); + } + div.appendChild(new Element('DIV', { 'class': cal.value.show ? 'kronolithCalOn' : 'kronolithCalOff' }).setStyle({ backgroundColor: cal.value.bg, color: cal.value.fg }).update(cal.value.name)); + }); + if (my) { + $('kronolithMyCalendars').show(); + } else { + $('kronolithMyCalendars').hide(); + } + if (shared) { + $('kronolithSharedCalendars').show(); + } else { + $('kronolithSharedCalendars').hide(); + } + + remote.each(function(cal) { + $('kronolithRemoteCalendars').appendChild(new Element('DIV', { 'class': cal.value.show ? 'kronolithCalOn' : 'kronolithCalOff' }).setStyle({ backgroundColor: cal.value.bg, color: cal.value.fg }).update(cal.value.name)); + }); + if (remote.size()) { + $('kronolithRemoteCalendars').show(); + } else { + $('kronolithRemoteCalendars').hide(); + } + }, + + /** + */ + _loadEvents: function(firstDay, lastDay, callback, calendars) + { + var start = firstDay.dateString(), end = lastDay.dateString(), + driver, calendar; + if (typeof calendars == 'undefined') { + calendars = Kronolith.conf.calendars; + } + calendars = $H(calendars); + calendars.each(function(type) { + switch (type.key) { + case 'internal': + driver = ''; + break; + case 'external': + driver = 'Horde'; + break; + case 'remote': + driver = 'Ical'; + break; + case 'holiday': + driver = 'Holiday'; + break; + } + $H(type.value).each(function(cal) { + if (cal.value.show) { + calendar = driver + '|' + cal.key; + this.eventsLoading[calendar] = start + end; + this.doAction('ListEvents', { start: start, end: end, cal: calendar }, callback); + } + }, this); + }, this); }, /** @@ -485,7 +553,7 @@ KronolithCore = { var div; // Check if this is the still the result of the most current request. - if (r.response.sig != this.eventsLoading) { + if (r.response.sig != this.eventsLoading[r.response.cal]) { return; } @@ -733,12 +801,14 @@ KronolithCore = { /* Onload function. */ onDomLoad: function() { - KronolithCore.init(); + this.init(); if (Horde.dhtmlHistory.initialize()) { Horde.dhtmlHistory.addListener(this.go.bind(this)); } + this.updateCalendarList(); + /* Initialize the starting page if necessary. addListener() will have * already fired if there is a current location so only do a go() * call if there is no current location. */ diff --git a/kronolith/lib/Driver/Holidays.php b/kronolith/lib/Driver/Holidays.php index 17db2dbf8..ed3b51c9c 100644 --- a/kronolith/lib/Driver/Holidays.php +++ b/kronolith/lib/Driver/Holidays.php @@ -32,11 +32,14 @@ class Kronolith_Driver_Holidays extends Kronolith_Driver * $startDate - $endDate range. * @param boolean $hasAlarm Only return events with alarms? Has no * effect in this driver. + * @param boolean $json Store the results of the events' + * toJSON() method? * * @return array Events in the given time range. */ public function listEvents($startDate = null, $endDate = null, - $showRecurrence = false, $hasAlarm = false) + $showRecurrence = false, $hasAlarm = false, + $json = false) { if (!class_exists('Date_Holidays')) { Horde::logMessage('Support for Date_Holidays has been enabled but the package seems to be missing.', @@ -68,7 +71,7 @@ class Kronolith_Driver_Holidays extends Kronolith_Driver $events = $this->_getEvents($dh, $startDate, $endDate); foreach ($events as $event) { Kronolith::addEvents($results, $event, $startDate, $endDate, - $showRecurrence); + $showRecurrence, $json); } } diff --git a/kronolith/lib/Driver/Horde.php b/kronolith/lib/Driver/Horde.php index f6b49bb3e..c89781d2a 100644 --- a/kronolith/lib/Driver/Horde.php +++ b/kronolith/lib/Driver/Horde.php @@ -44,11 +44,14 @@ class Kronolith_Driver_Horde extends Kronolith_Driver * recurring events once inside the * $startDate - $endDate range. * @param boolean $hasAlarm Only return events with alarms? + * @param boolean $json Store the results of the events' + * toJSON() method? * * @return array Events in the given time range. */ public function listEvents($startDate = null, $endDate = null, - $showRecurrence = false, $hasAlarm = false) + $showRecurrence = false, $hasAlarm = false, + $json = false) { list($this->api, $category) = explode('/', $this->_calendar, 2); if (!$this->_params['registry']->hasMethod($this->api . '/listTimeObjects')) { @@ -86,7 +89,7 @@ class Kronolith_Driver_Horde extends Kronolith_Driver } Kronolith::addEvents($results, $event, $startDate, - $endDate, $showRecurrence); + $endDate, $showRecurrence, $json); } return $results; diff --git a/kronolith/lib/Driver/Ical.php b/kronolith/lib/Driver/Ical.php index 956923b11..cc42b6f83 100644 --- a/kronolith/lib/Driver/Ical.php +++ b/kronolith/lib/Driver/Ical.php @@ -46,11 +46,14 @@ class Kronolith_Driver_Ical extends Kronolith_Driver * recurring events once inside the * $startDate - $endDate range. * @param boolean $hasAlarm Only return events with alarms? + * @param boolean $json Store the results of the events' + * toJSON() method? * * @return array Events in the given time range. */ public function listEvents($startDate = null, $endDate = null, - $showRecurrence = false, $hasAlarm = false) + $showRecurrence = false, $hasAlarm = false, + $json = false) { $data = $this->_getRemoteCalendar(); if (is_a($data, 'PEAR_Error')) { @@ -118,7 +121,7 @@ class Kronolith_Driver_Ical extends Kronolith_Driver $timestamp = $exceptions[$event->getUID()][$event->getSequence()]; $events[$key]->recurrence->addException(date('Y', $timestamp), date('m', $timestamp), date('d', $timestamp)); Kronolith::addEvents($results, $event, $startDate, $endDate, - $showRecurrence); + $showRecurrence, $json); } } diff --git a/kronolith/lib/Driver/Kolab.php b/kronolith/lib/Driver/Kolab.php index ad7cb4332..4f931b62c 100644 --- a/kronolith/lib/Driver/Kolab.php +++ b/kronolith/lib/Driver/Kolab.php @@ -195,11 +195,14 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver * recurring events once inside the * $startDate - $endDate range. * @param boolean $hasAlarm Only return events with alarms? + * @param boolean $json Store the results of the events' + * toJSON() method? * * @return array Events in the given time range. */ public function listEvents($startDate = null, $endDate = null, - $showRecurrence = false, $hasAlarm = false) + $showRecurrence = false, $hasAlarm = false, + $json = false) { $result = $this->synchronize(); if (is_a($result, 'PEAR_Error')) { @@ -245,7 +248,7 @@ class Kronolith_Driver_Kolab extends Kronolith_Driver } Kronolith::addEvents($events, $event, $startDate, $endDate, - $showRecurrence); + $showRecurrence, $json); } return $events; diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index f1b60d6d0..bbb4879e9 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -225,11 +225,14 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * recurring events once inside the * $startDate - $endDate range. * @param boolean $hasAlarm Only return events with alarms? + * @param boolean $json Store the results of the events' + * toJSON() method? * * @return array Events in the given time range. */ public function listEvents($startDate = null, $endDate = null, - $showRecurrence = false, $hasAlarm = false) + $showRecurrence = false, $hasAlarm = false, + $json = false) { if (is_null($startDate)) { $startDate = new Horde_Date(array('mday' => 1, @@ -257,7 +260,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver $results = array(); foreach ($events as $id) { Kronolith::addEvents($results, $this->getEvent($id), $startDate, - $endDate, $showRecurrence); + $endDate, $showRecurrence, $json); } return $results; diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 35b181003..3c4506b40 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -146,6 +146,32 @@ class Kronolith // Turn debugging on? 'debug' => !empty($conf['js']['debug']), ); + foreach ($GLOBALS['all_calendars'] as $id => $calendar) { + $owner = $calendar->get('owner') == Auth::getAuth(); + $code['conf']['calendars']['internal'][$id] = array( + 'name' => ($owner ? '' : '[' . Auth::removeHook($calendar->get('owner')) . '] ') + . $calendar->get('name'), + 'owner' => $owner, + 'fg' => Kronolith::foregroundColor($calendar), + 'bg' => Kronolith::backgroundColor($calendar), + 'show' => in_array($id, $GLOBALS['display_calendars'])); + } + foreach ($GLOBALS['all_external_calendars'] as $api => $categories) { + foreach ($categories as $id => $name) { + $calendar = $api . '/' . $id; + $code['conf']['calendars']['external'][$calendar] = array( + 'name' => $name, + 'api' => $GLOBALS['registry']->get('name', $GLOBALS['registry']->hasInterface($api)), + 'show' => in_array($calendar, $GLOBALS['display_external_calendars'])); + } + } + foreach ($GLOBALS['all_remote_calendars'] as $calendar) { + $code['conf']['calendars']['remote'][$calendar['url']] = array( + 'name' => $calendar['name'], + 'fg' => Kronolith::foregroundColor($calendar), + 'bg' => Kronolith::backgroundColor($calendar), + 'show' => in_array($calendar['url'], $GLOBALS['display_remote_calendars'])); + } /* Gettext strings used in core javascript files. */ $code['text'] = array_map('addslashes', array( @@ -637,7 +663,7 @@ class Kronolith * @access private */ public static function addEvents(&$results, &$event, $startDate, $endDate, - $showRecurrence) + $showRecurrence, $json) { if ($event->recurs() && $showRecurrence) { /* Recurring Event. */ @@ -679,7 +705,7 @@ class Kronolith if (!$event->recurrence->hasException($event->start->year, $event->start->month, $event->start->mday)) { - Kronolith::addCoverDates($results, $event, $event->start, $event->end); + Kronolith::addCoverDates($results, $event, $event->start, $event->end, $json); } /* Start searching for recurrences from the day after it @@ -699,7 +725,7 @@ class Kronolith $nextEnd->mday += $diff[2]; $nextEnd->hour += $diff[3]; $nextEnd->min += $diff[4]; - Kronolith::addCoverDates($results, $event, $next, $nextEnd); + Kronolith::addCoverDates($results, $event, $next, $nextEnd, $json); } $next = $event->recurrence->nextRecurrence( array('year' => $next->year, @@ -781,7 +807,7 @@ class Kronolith 'month' => $eventEnd->month, 'mday' => $eventEnd->mday, 'year' => $eventEnd->year)); } - $results[$loopDate->dateString()][$addEvent->getId()] = $addEvent; + $results[$loopDate->dateString()][$addEvent->getId()] = $json ? $addEvent->toJSON() : $addEvent; } $loopDate = new Horde_Date( @@ -801,9 +827,11 @@ class Kronolith * @param Horde_Date $eventStart The event's start at the actual * recurrence. * @param Horde_Date $eventEnd The event's end at the actual recurrence. + * @param boolean $json Store the results of the events' toJSON() + * method? */ public static function addCoverDates(&$results, $event, $eventStart, - $eventEnd) + $eventEnd, $json) { $i = $eventStart->mday; $loopDate = new Horde_Date(array('month' => $eventStart->month, @@ -815,7 +843,7 @@ class Kronolith $addEvent = clone $event; $addEvent->start = $eventStart; $addEvent->end = $eventEnd; - $results[$loopDate->dateString()][$addEvent->getId()] = $addEvent; + $results[$loopDate->dateString()][$addEvent->getId()] = $json ? $addEvent->toJSON() : $addEvent; } $loopDate = new Horde_Date( array('month' => $eventStart->month, @@ -965,12 +993,13 @@ class Kronolith /* Make sure all the remote calendars still exist. */ $_temp = $GLOBALS['display_remote_calendars']; $GLOBALS['display_remote_calendars'] = array(); - $_all = @unserialize($GLOBALS['prefs']->getValue('remote_cals')); - if (is_array($_all)) { - foreach ($_all as $id) { - if (in_array($id['url'], $_temp)) { - $GLOBALS['display_remote_calendars'][] = $id['url']; - } + $GLOBALS['all_remote_calendars'] = @unserialize($GLOBALS['prefs']->getValue('remote_cals')); + if (!is_array($GLOBALS['all_remote_calendars'])) { + $GLOBALS['all_remote_calendars'] = array(); + } + foreach ($GLOBALS['all_remote_calendars'] as $id) { + if (in_array($id['url'], $_temp)) { + $GLOBALS['display_remote_calendars'][] = $id['url']; } } $GLOBALS['prefs']->setValue('display_remote_cals', serialize($GLOBALS['display_remote_calendars'])); diff --git a/kronolith/templates/index/index.inc b/kronolith/templates/index/index.inc index fe8d93710..54a25357d 100644 --- a/kronolith/templates/index/index.inc +++ b/kronolith/templates/index/index.inc @@ -51,39 +51,24 @@ - -
- $cal): ?> -
get('name')) ?>
- + -

+

- -
- $cal): ?> -
get('name')) ?>
- + -

+

- -
- $cal): ?> -
- + -
diff --git a/kronolith/templates/panel.inc b/kronolith/templates/panel.inc index 55032bb55..174865147 100644 --- a/kronolith/templates/panel.inc +++ b/kronolith/templates/panel.inc @@ -1,10 +1,10 @@ 'calendar-info'), $registry->getImageDir('horde')); -$remote_calendars = @unserialize($prefs->getValue('remote_cals')); $current_user = Auth::getAuth(); $my_calendars = array(); $shared_calendars = array(); @@ -110,10 +109,10 @@ $tagger = Kronolith::getTagger(); - +

    - $cal): ?> + $cal): ?> >