Rework prefsStatus() API call so it works on all prefs pages
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 06:18:31 +0000 (00:18 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 06:23:20 +0000 (00:23 -0600)
imp/lib/Api.php
imp/lib/Auth.php
imp/lib/Dimp.php
imp/lib/Notification/Listener/Status.php

index 0b050e4..c5e47d5 100644 (file)
@@ -475,20 +475,17 @@ class IMP_Api extends Horde_Registry_Api
     }
 
     /**
-     * Output notifications on the preferences page.
+     * Setup notifications handler for the preferences page. This will only
+     * be called if in dimp view mode.
      */
     public function prefsStatus()
     {
-        try {
-            $GLOBALS['imp_authentication'] = 'throw';
-            require_once dirname(__FILE__) . '/base.php';
-            if (IMP::getViewMode() == 'dimp') {
-                Horde::addInlineScript(array(IMP_Dimp::notify(true)), 'dom');
-                return;
-            }
-        } catch (Horde_Exception $e) {}
+        $GLOBALS['imp_authentication'] = 'none';
+        require_once dirname(__FILE__) . '/base.php';
 
-        IMP::status();
+        $notification = Horde_Notification::singleton();
+        $notification->detach('status');
+        $notification->attach('status', array('prefs' => true, 'viewmode' => 'dimp'), 'IMP_Notification_Listener_Status');
     }
 
     /**
index a0b3864..8b2a3af 100644 (file)
@@ -474,9 +474,11 @@ class IMP_Auth
                   $conf['cookie']['path'],
                   $conf['cookie']['domain']);
 
-        /* Suppress menus in options screen. */
+        /* Suppress menus in options screen, and indicate that it should
+         * use the IMP notification listener. */
         if ($sess['view'] == 'dimp') {
             $_SESSION['horde_prefs']['nomenu'] = true;
+            $_SESSION['horde_prefs']['status'] = 'imp';
         }
 
         /* Set up search information for the session. */
index b9c2722..ffef8ae 100644 (file)
@@ -97,17 +97,15 @@ class IMP_Dimp
     /**
      * Return the javascript code necessary to display notification popups.
      *
-     * @param boolean $parent  Send notifications to parent window?
-     *
      * @return string  The notification JS code.
      */
-    static public function notify($parent = false)
+    static public function notify()
     {
         $GLOBALS['notification']->notify(array('listeners' => 'status'));
         $msgs = $GLOBALS['imp_notify']->getStack();
 
         return count($msgs)
-            ? ($parent ? 'parent.' : '') . 'DimpCore.showNotifications(' . Horde_Serialize::serialize($msgs, Horde_Serialize::JSON) . ')'
+            ? 'DimpCore.showNotifications(' . Horde_Serialize::serialize($msgs, Horde_Serialize::JSON) . ')'
             : '';
     }
 
index 9c3da48..825dc08 100644 (file)
 class IMP_Notification_Listener_Status extends Horde_Notification_Listener_Status
 {
     /**
+     * Is this the prefs screen?
+     *
+     * @var boolean
+     */
+    protected $_isPrefs = false;
+
+    /**
      * The view mode.
      *
      * @var string
@@ -21,13 +28,16 @@ class IMP_Notification_Listener_Status extends Horde_Notification_Listener_Statu
     /**
      * Constructor.
      *
-     * @param array $options  One option required: 'viewmode'.
+     * @param array $options  Optional: 'prefs', 'viewmode'.
      */
-    public function __construct($options)
+    public function __construct($options = array())
     {
         parent::__construct();
 
-        $this->_viewmode = $options['viewmode'];
+        $this->_isPrefs = !empty($options['prefs']);
+        $this->_viewmode = empty($options['viewmode'])
+            ? IMP::getViewMode()
+            : $options['viewmode'];
 
         $image_dir = $GLOBALS['registry']->getImageDir();
 
@@ -65,7 +75,15 @@ class IMP_Notification_Listener_Status extends Horde_Notification_Listener_Statu
         if (($this->_viewmode == 'dimp') && Horde_Auth::getAuth()) {
             $options['store'] = true;
         }
+
         parent::notify($messageStack, $options);
+
+        /* Preferences display. */
+        if ($this->_isPrefs && ($msgs = $this->getStack())) {
+            Horde::addInlineScript(array(
+                'parent.DimpCore.showNotifications(' . Horde_Serialize::serialize($msgs, Horde_Serialize::JSON) . ')'
+            ), 'dom');
+        }
     }
 
 }