From: Jan Schneider Date: Fri, 13 Feb 2009 18:54:00 +0000 (+0100) Subject: Render events in month view. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=c6475a809a54e9fde8733f50256a2fba7c59b179;p=horde.git Render events in month view. --- diff --git a/kronolith/ajax.php b/kronolith/ajax.php new file mode 100644 index 000000000..e309dbe6d --- /dev/null +++ b/kronolith/ajax.php @@ -0,0 +1,90 @@ + + * @author Jan Schneider + * @package Kronolith + */ + +// Need to load Util:: to give us access to Util::getPathInfo(). +$kronolith_dir = dirname(__FILE__); +if (!defined('HORDE_BASE')) { + /* Temporary fix - if horde does not live directly under the kronolith + * directory, the HORDE_BASE constant should be defined in + * kronolith/lib/base.local.php. */ + if (file_exists($kronolith_dir . '/lib/base.local.php')) { + include $kronolith_dir . '/lib/base.local.php'; + } else { + define('HORDE_BASE', $kronolith_dir . '/..'); + } +} +require_once HORDE_BASE . '/lib/core.php'; +$action = basename(Util::getPathInfo()); +if (empty($action)) { + // This is the only case where we really don't return anything, since + // the frontend can be presumed not to make this request on purpose. + // Other missing data cases we return a response of boolean false. + exit; +} + +// The following actions do not need write access to the session and +// should be opened read-only for performance reasons. +if (in_array($action, array())) { + $session_control = 'readonly'; +} + +$session_timeout = 'json'; +require_once $kronolith_dir . '/lib/base.php'; + +// Process common request variables. +$cacheid = Util::getPost('cacheid'); + +// Open an output buffer to ensure that we catch errors that might break JSON +// encoding. +ob_start(); + +$notify = true; +$result = false; + +switch ($action) { +case 'ListEvents': + $dates = Kronolith::listEvents(Util::getFormData('start'), Util::getFormData('end')); + if (is_a($dates, 'PEAR_Error')) { + $notification->push($dates, 'horde.error'); + $result = false; + } else { + $result = new stdClass; + $result->events = array(); + foreach ($dates as $date => $events) { + foreach ($events as $id => $event) { + $result->events[$date][$id] = $event->toJSON(); + } + } + } + break; + +case 'ChunkContent': + $chunk = basename(Util::getPost('chunk')); + if (!empty($chunk)) { + $result = new stdClass; + $result->chunk = Util::bufferOutput('include', KRONOLITH_TEMPLATES . '/chunks/' . $chunk . '.php'); + } + break; +} + +// Clear the output buffer that we started above, and log any unexpected +// output at a DEBUG level. +$errors = ob_get_clean(); +if ($errors) { + Horde::logMessage('Kronolith: unexpected output: ' . + $errors, __FILE__, __LINE__, PEAR_LOG_DEBUG); +} + +// Send the final result. +Horde::sendHTTPResponse(Horde::prepareResponse($result, $notify ? $GLOBALS['kronolith_notify'] : null), 'json'); diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index e6823de96..242c830ee 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -439,6 +439,7 @@ KronolithCore = { // Fill week number and day cells. var cell = row.down().setText(monday.getWeek()).next(); while (cell) { + cell.id = 'kronolithMonthDay' + day.toString('yyyyMMdd'); cell.removeClassName('kronolithOtherMonth'); if (typeof month != 'undefined' && day.getMonth() != month) { cell.addClassName('kronolithOtherMonth'); @@ -512,6 +513,12 @@ KronolithCore = { */ _monthCallback: function(r) { + r = r.response; + $H(r.events).each(function(date) { + $H(date.value).each(function(event) { + $('kronolithMonthDay' + date.key).insert(new Element('DIV', { 'class': 'kronolithEvent', 'style': 'background-color:' + event.value.bg + ';color:' + event.value.fg }).setText(event.value.t)); + }); + }); }, /** diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index 1ea063b65..1ab93ee92 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -1256,6 +1256,21 @@ class Kronolith_Event { } /** + * Returns a simple object suitable for json transport representing this + * event. + * + * @return object A simple object. + */ + function toJSON() + { + $json = new stdClass; + $json->t = $this->getTitle(); + $json->bg = $this->_backgroundColor; + $json->fg = $this->_foregroundColor; + return $json; + } + + /** * TODO */ function isInitialized() diff --git a/kronolith/templates/index/month.inc b/kronolith/templates/index/month.inc index 1ff8180d8..1d581a3fc 100644 --- a/kronolith/templates/index/month.inc +++ b/kronolith/templates/index/month.inc @@ -15,22 +15,22 @@