Status message support.
authorJan Schneider <jan@horde.org>
Fri, 13 Feb 2009 00:32:12 +0000 (01:32 +0100)
committerJan Schneider <jan@horde.org>
Fri, 13 Feb 2009 00:49:58 +0000 (01:49 +0100)
kronolith/js/src/kronolith.js
kronolith/lib/Notification/Listener/status.php [new file with mode: 0644]
kronolith/lib/base.php
kronolith/templates/index/index.inc
kronolith/themes/print/screen.css
kronolith/themes/screen.css

index 7214b1d..0e6cd59 100644 (file)
@@ -53,12 +53,12 @@ KronolithCore = {
             case 'kronolith.request':
             case 'kronolith.sticky':
                 var iefix, log, tmp,
-                    alerts = $('alerts'),
+                    alerts = $('hordeAlerts'),
                     div = new Element('DIV', { className: m.type.replace('.', '-') }),
                     msg = m.message;
 
                 if (!alerts) {
-                    alerts = new Element('DIV', { id: 'alerts' });
+                    alerts = new Element('DIV', { id: 'hordeAlerts' });
                     $(document.body).insert(alerts);
                 }
 
@@ -77,7 +77,7 @@ KronolithCore = {
                 // overlay the div with a like sized div containing a clear
                 // gif, which tricks IE into the correct behavior.
                 if (Kronolith.conf.is_ie6) {
-                    iefix = new Element('DIV', { id: 'ie6alertsfix' }).clonePosition(div, { setLeft: false, setTop: false });
+                    iefix = new Element('DIV', { id: 'hordeIE6AlertsFix' }).clonePosition(div, { setLeft: false, setTop: false });
                     iefix.insert(div.remove());
                     alerts.insert(iefix);
                 }
@@ -90,7 +90,7 @@ KronolithCore = {
                     this.alertrequest = div;
                 }
 
-                if (tmp = $('alertslog')) {
+                if (tmp = $('hordeAlertslog')) {
                     switch (m.type) {
                     case 'horde.error':
                         log = Kronolith.text.alog_error;
@@ -111,7 +111,7 @@ KronolithCore = {
 
                     if (log) {
                         tmp = tmp.down('DIV UL');
-                        if (tmp.down().hasClassName('noalerts')) {
+                        if (tmp.down().hasClassName('hordeNoalerts')) {
                             tmp.down().remove();
                         }
                         tmp.insert(new Element('LI').insert(new Element('P', { className: 'label' }).insert(log)).insert(new Element('P', { className: 'indent' }).insert(msg).insert(new Element('SPAN', { className: 'alertdate'}).insert('[' + (new Date).toLocaleString() + ']'))));
@@ -131,7 +131,7 @@ KronolithCore = {
     toggleAlertsLog: function()
     {
         var alink = $('alertsloglink').down('A'),
-            div = $('alertslog').down('DIV'),
+            div = $('hordeAlertslog').down('DIV'),
             opts = { duration: 0.5 };
         if (div.visible()) {
             Effect.BlindUp(div, opts);
@@ -150,7 +150,7 @@ KronolithCore = {
 
             elt.remove();
             if (!parent.childElements().size() &&
-                parent.readAttribute('id') == 'ie6alertsfix') {
+                parent.readAttribute('id') == 'hordeIE6AlertsFix') {
                 parent.remove();
             }
         } catch (e) {
@@ -553,9 +553,6 @@ KronolithCore = {
 
     _onResize: function(noupdate, nowait)
     {
-        if (this.viewport) {
-            this.viewport.onResize(noupdate, nowait);
-        }
         this._resizeIE6();
     },
 
@@ -716,7 +713,7 @@ KronolithCore = {
                 this.toggleAlertsLog();
                 break;
 
-            case 'alerts':
+            case 'hordeAlerts':
                 this.alertsFade(elt);
                 break;
             }
diff --git a/kronolith/lib/Notification/Listener/status.php b/kronolith/lib/Notification/Listener/status.php
new file mode 100644 (file)
index 0000000..ec792d6
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+
+require_once 'Horde/Notification/Listener/status.php';
+require_once 'Horde/Notification/Event.php';
+
+/**
+ * The Notification_Listener_status_kronolith:: class extends the
+ * Notification_Listener_status:: class to return all messages instead of
+ * printing them.
+ *
+ * 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.
+ *
+ * @todo    Move this into Notification core functionality
+ * @author  Jan Schneider <jan@horde.org>
+ * @package Horde_Notification
+ */
+class Notification_Listener_status_kronolith extends Notification_Listener_status {
+
+    /**
+     * The notified message stack.
+     *
+     * @var array
+     */
+    var $_messageStack = array();
+
+    /**
+     * Returns all status message if there are any on the 'status' message
+     * stack.
+     *
+     * @param array &$messageStack  The stack of messages.
+     * @param array $options        An array of options.
+     */
+    function notify(&$messageStack, $options = array())
+    {
+        while ($message = array_shift($messageStack)) {
+            $event = @unserialize($message['event']);
+            $this->_messageStack[] = array('type' => $message['type'],
+                                           'flags' => $message['flags'],
+                                           'message' => is_object($event)
+                                               ? $event->getMessage()
+                                               : null);
+        }
+    }
+
+    /**
+     * Handle every message of type dimp.*; otherwise delegate back to
+     * the parent.
+     *
+     * @param string $type  The message type in question.
+     *
+     * @return boolean  Whether this listener handles the type.
+     */
+    function handles($type)
+    {
+        if (substr($type, 0, 10) == 'kronolith.') {
+            return true;
+        }
+        return parent::handles($type);
+    }
+
+    /**
+     * Returns the message stack.
+     * To return something useful, notify() needs to be called first.
+     *
+     * @param boolean $encode  Encode HTML entities?
+     *
+     * @return array  List of message hashes.
+     */
+    function getStack($encode = false)
+    {
+        $msgs = $this->_messageStack;
+        if (!$encode) {
+            return $msgs;
+        }
+
+        for ($i = 0, $mcount = count($msgs); $i < $mcount; ++$i) {
+            if (!in_array('content.raw', $this->getFlags($msgs[$i]))) {
+                $msgs[$i]['message'] = htmlspecialchars($msgs[$i]['message'], ENT_COMPAT, NLS::getCharset());
+            }
+        }
+
+        return $msgs;
+    }
+
+}
index a7ad8d3..a180188 100644 (file)
@@ -61,7 +61,8 @@ require_once 'Horde/Help.php';
 
 /* Notification system. */
 $notification = &Notification::singleton();
-$notification->attach('status');
+require_once KRONOLITH_BASE . '/lib/Notification/Listener/status.php';
+$GLOBALS['kronolith_notify'] = &$notification->attach('status', null, 'Notification_Listener_status_kronolith');
 
 /* Kronolith base library. */
 require_once KRONOLITH_BASE . '/lib/Kronolith.php';
index ea21851..fe8d937 100644 (file)
@@ -232,3 +232,13 @@ require dirname(__FILE__) . '/day.inc';
   <a href="#">teste</a>
   <a href="#">teste</a>
 </div>
+
+<?php if (!($browser->isBrowser('msie') && ($browser->getMajor() < 7))): ?>
+<div id="hordeAlertslog">
+ <div style="display:none">
+  <ul>
+   <li class="hordeNoalerts"><strong><?php echo _("No Alerts") ?></strong></li>
+  </ul>
+ </div>
+</div>
+<?php endif; ?>
index 97f6f57..116ba3d 100644 (file)
@@ -55,3 +55,7 @@ table.monthgrid td.today {
 body.rightPanel #page {
     margin: 0;
 }
+
+#hordeAlertslog {
+    display: none !important;
+}
index c2adfbf..1227f2b 100644 (file)
@@ -1119,3 +1119,10 @@ li.panel-tags {
 .panel-tags li:hover {
     text-decoration: underline;
 }
+
+#hordeAlerts div.kronolith-sticky, #hordeAlerts div.kronolith-sticky {
+    background-color: #ebe20c;
+    background-image: url("graphics/warning.png");
+    border-color: #807b00;
+    color: #000;
+}