Render events in month view.
authorJan Schneider <jan@horde.org>
Fri, 13 Feb 2009 18:54:00 +0000 (19:54 +0100)
committerJan Schneider <jan@horde.org>
Fri, 13 Feb 2009 18:54:19 +0000 (19:54 +0100)
kronolith/ajax.php [new file with mode: 0644]
kronolith/js/src/kronolith.js
kronolith/lib/Driver.php
kronolith/templates/index/month.inc

diff --git a/kronolith/ajax.php b/kronolith/ajax.php
new file mode 100644 (file)
index 0000000..e309dbe
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Performs the AJAX-requested action.
+ *
+ * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @author  Jan Schneider <jan@horde.org>
+ * @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');
index e6823de..242c830 100644 (file)
@@ -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));
+            });
+        });
     },
 
     /**
index 1ea063b..1ab93ee 100644 (file)
@@ -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()
index 1ff8180..1d581a3 100644 (file)
 
 <div id="kronolithRowTemplate" class="kronolithRow" style="display:none">
   <div class="kronolithFirstCol"></div>
-  <div class="kronolithCol kronolithOtherMonth">
+  <div class="kronolithCol">
     <div class="kronolithCorner"><div class="kronolithDay"></div><a class="kronolithAdd"><?php echo $img_blank ?></a></div>
   </div>
-  <div class="kronolithCol kronolithOtherMonth">
+  <div class="kronolithCol">
     <div class="kronolithCorner"><div class="kronolithDay"></div><a class="kronolithAdd"><?php echo $img_blank ?></a></div>
   </div>
-  <div class="kronolithCol kronolithOtherMonth">
+  <div class="kronolithCol">
     <div class="kronolithCorner"><div class="kronolithDay"></div><a class="kronolithAdd"><?php echo $img_blank ?></a></div>
   </div>
-  <div class="kronolithCol kronolithOtherMonth">
+  <div class="kronolithCol">
     <div class="kronolithCorner"><div class="kronolithDay"></div><a class="kronolithAdd"><?php echo $img_blank ?></a></div>
   </div>
-  <div class="kronolithCol kronolithOtherMonth">
+  <div class="kronolithCol">
     <div class="kronolithCorner"><div class="kronolithDay"></div><a class="kronolithAdd"><?php echo $img_blank ?></a></div>
   </div>
-  <div class="kronolithCol kronolithOtherMonth">
+  <div class="kronolithCol">
     <div class="kronolithCorner"><div class="kronolithDay"></div><a class="kronolithAdd"><?php echo $img_blank ?></a></div>
   </div>
   <div class="kronolithCol">