Remove javascript notification listener
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 29 Jul 2010 17:04:49 +0000 (11:04 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 29 Jul 2010 17:27:58 +0000 (11:27 -0600)
21 files changed:
ansel/gallery.php
ansel/gallery/sort.php
fima/postings.php
fima/report.php
fima/search.php
framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php
framework/Core/lib/Horde/Core/Binder/Alarm.php
framework/Notification/lib/Horde/Notification/Listener/Javascript.php [deleted file]
framework/Notification/package.xml
framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php [deleted file]
horde/admin/groups.php
horde/templates/common-footer.inc
kastalia/templates/common-footer.inc
mnemo/search.php
nag/search.php
passwd/main.php
skoli/search.php
trean/add.php
turba/search.php
wicked/lib/Page/EditPage.php
wicked/lib/Page/NewPage.php

index aca84e3..28dbf3f 100644 (file)
@@ -35,7 +35,9 @@ case 'add':
     $gallery_mode = 'Normal';
     $gallery_passwd = '';
 
-    $notification->push('document.gallery.gallery_name.focus();', 'javascript');
+    Horde::addInlineScript(array(
+        '$("gallery_name").focus()'
+    ), 'dom');
 
     $title = _("Adding A New Gallery");
     break;
@@ -73,7 +75,10 @@ case 'addchild':
     $gallery_mode = 'Normal';
     $gallery_passwd = '';
 
-    $notification->push('document.gallery.gallery_name.focus();', 'javascript');
+    Horde::addInlineScript(array(
+        '$("gallery_name").focus()'
+    ), 'dom');
+
     $title = sprintf(_("Adding A Subgallery to %s"), $parent->get('name'));
     break;
 
index 683305e..7b1d44c 100644 (file)
@@ -57,8 +57,13 @@ case 'Sort':
     exit;
 }
 
+Horde::addInlineScript(array(
+    'Sortable.create("sortContainer", { tag: "div", overlap: "horizontal", constraint: false })'
+), 'dom');
+
 Horde::addScriptFile('effects.js', 'horde');
 Horde::addScriptFile('dragdrop.js', 'horde');
+
 $title = sprintf(_("%s :: Sort"), $gallery->get('name'));
 require ANSEL_TEMPLATES . '/common-header.inc';
 require ANSEL_TEMPLATES . '/menu.inc';
@@ -92,5 +97,4 @@ foreach ($images as $image) {
         . '</a></div>';
 }
 echo '</div>';
-$notification->push('Sortable.create(\'sortContainer\', {tag: \'div\', overlap: \'horizontal\', constraint: false })', 'javascript');
 require $registry->get('templates', 'horde') . '/common-footer.inc';
index 690ee52..00d6c73 100644 (file)
@@ -663,6 +663,8 @@ $rowId = 0;
 $datefmt = $prefs->getValue('date_format');
 $amountfmt = $prefs->getValue('amount_format');
 
+$js_onload = array();
+
 if ($pageOb['mode'] == 'edit') {
     /* Fix date format. */
     $datefmt = Fima::convertDateFormat($datefmt);
@@ -670,15 +672,19 @@ if ($pageOb['mode'] == 'edit') {
     /* Add current date in first field if no postings. */
     foreach ($postings as $key => $value) {
         if ($value['date'] == '') {
-            $notification->push('document.getElementById(\'date1\').value = \'' . strftime($datefmt) . '\';', 'javascript');
+            $js_onload[] = '$("date1").setValue(' . Horde_Serialize::serialize(strftime($datefmt), Horde_Serialize::JSON, $registry->getCharset()) . ')';
         }
         break;
     }
 
     /* Select first date field. */
-    $notification->push('updateResult(); updateAssetResult(_getall(\'asset[]\')[0]); document.getElementById(\'date1\').focus(); document.getElementById(\'date1\').select();', 'javascript');
+    $js_onload[] = 'updateResult()';
+    $js_onload[] = 'updateAssetResult(_getall("asset[]")[0])';
+    $js_onload[] = '$("date1").focus().select()';
 }
 
+Horde::addInlineScript($js_onload, 'dom');
+
 require FIMA_TEMPLATES . '/common-header.inc';
 if ($print_view) {
     require_once $registry->get('templates', 'horde') . '/javascript/print.js';
index c05d607..cfe8f35 100644 (file)
@@ -158,7 +158,10 @@ default:
 $datefmt = $prefs->getValue('date_format');
 $amountfmt = $prefs->getValue('amount_format');
 
-$notification->push('document.report.report_id.focus();', 'javascript');
+Horde::addInlineScript(array(
+    '$("report_id").focus()'
+), 'dom');
+
 require FIMA_TEMPLATES . '/common-header.inc';
 require FIMA_TEMPLATES . '/menu.inc';
 if ($browser->hasFeature('javascript')) {
index ca5e88f..7808c0a 100644 (file)
@@ -66,8 +66,11 @@ $eos = array('-1' => '',
 $datefmt = $prefs->getValue('date_format');
 $amountfmt = $prefs->getValue('amount_format');
 
+Horde::addInlineScript(array(
+    '$("search_type").focus()'
+), 'dom');
+
 $title = _("Search Postings");
-$notification->push('document.search.search_type.focus();', 'javascript');
 require FIMA_TEMPLATES . '/common-header.inc';
 require FIMA_TEMPLATES . '/menu.inc';
 if ($browser->hasFeature('javascript')) {
index 549d110..e5a867d 100644 (file)
 class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler
 {
     /**
-     * A notification handler.
+     * A notification callback.
      *
-     * @var Horde_Notification_Handler
+     * @var callback
      */
-    protected $_notification;
+    protected $_jsNotify;
 
     /**
      * An icon URL.
@@ -36,7 +36,7 @@ class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler
      *
      * @param array $params  Any parameters that the handler might need.
      *                       Required parameter:
-     *                       - notification: A Horde_Notification_Handler
+     *                       - js_notify: A Horde_Notification_Handler
      *                         instance.
      *                       Optional parameter:
      *                       - icon: URL of an icon to display.
@@ -44,23 +44,25 @@ class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler
     public function __construct(array $params = null)
     {
         /*
-        if (!isset($params['notification'])) {
-            throw new Horde_Alarm_Exception('Parameter \'notification\' missing.');
+        if (!isset($params['js_notify'])) {
+            throw new InvalidArgumentException('Parameter \'js_notify\' missing.');
         }
-        if (!($params['notification'] instanceof Horde_Notification_Handler)) {
-            throw new Horde_Alarm_Exception('Parameter \'notification\' is not a Horde_Notification_Handler object.');
+        if (!is_callable($params['js_notify'])) {
+            throw new Horde_Alarm_Exception('Parameter \'js_notify\' is not a Horde_Notification_Handler object.');
         }
-        $this->_notification = $params['notification'];
+        $this->_jsNotify = $params['jsNotify'];
         if (isset($params['icon'])) {
             $this->_icon = $params['icon'];
         }
         */
-        $this->_notification = isset($params['notification']) ? $params['notification'] : $GLOBALS['injector']->getInstance('Horde_Notification');
+        $this->_jsNotify = isset($params['js_notify'])
+            ? $params['js_notify']
+            : array('Horde', 'addInlineScript');
         $this->_icon = isset($params['icon']) ? $params['icon'] : (string)Horde_Themes::img('alerts/alarm.png');
     }
 
     /**
-     * Notifies about an alarm through Horde_Notification.
+     * Notifies about an alarm through javscript.
      *
      * @param array $alarm  An alarm hash.
      */
@@ -70,7 +72,7 @@ class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler
                       $this->_icon,
                       addslashes($alarm['title']),
                       isset($alarm['text']) ? addslashes($alarm['text']) : '');
-        $this->_notification->push($js, 'javascript');
+        call_user_func($this->_jsNotify($js));
     }
 
     /**
index 8c5b23e..200971b 100644 (file)
@@ -32,7 +32,7 @@ class Horde_Core_Binder_Alarm implements Horde_Injector_Binder
         );
 
         $handler_params = array(
-            'notification' => $injector->getInstance('Horde_Notification'),
+            'js_notify' => array('Horde', 'addInlineScript'),
             'icon' => (string)Horde_Themes::img('alerts/alarm.png')
         );
         $alarm->addHandler('desktop', new Horde_Alarm_Handler_Desktop($handler_params));
diff --git a/framework/Notification/lib/Horde/Notification/Listener/Javascript.php b/framework/Notification/lib/Horde/Notification/Listener/Javascript.php
deleted file mode 100644 (file)
index aa85dd4..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-/**
- * The Horde_Notification_Listener_Javascript:: class provides functionality
- * for inserting javascript code from the message stack into the page.
- *
- * Copyright 2004-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author   Jan Schneider <jan@horde.org>
- * @category Horde
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @package  Notification
- */
-class Horde_Notification_Listener_Javascript extends Horde_Notification_Listener
-{
-    /**
-     * Constructor.
-     */
-    public function __construct()
-    {
-        $this->_handles['javascript'] = 'Horde_Notification_Event';
-        $this->_handles['javascript-file'] = 'Horde_Notification_Event';
-        $this->_name = 'javascript';
-    }
-
-    /**
-     * Outputs the javascript code if there are any messages on the
-     * 'javascript' message stack and if the 'notify_javascript' option is set.
-     *
-     * @param array $events   The list of events to handle.
-     * @param array $options  An array of options:
-     * <pre>
-     * 'noscript' - TODO
-     * </pre>
-     */
-    public function notify($events, $options = array())
-    {
-        $files = $js_text = array();
-
-        foreach ($events as $event) {
-            switch ($event->type) {
-            case 'javascript':
-                $js_text[] = strval($event);
-                break;
-
-            case 'javascript-file':
-                $files[] = strval($event);
-                break;
-            }
-        }
-
-        if (empty($options['noscript']) && !empty($js_text)) {
-            echo '<script type="text/javascript">//<![CDATA[' . "\n";
-        }
-
-        echo implode('', $js_text);
-
-        if (empty($options['noscript'])) {
-            if (!empty($js_text)) {
-                echo "\n//]]></script>\n";
-            }
-
-            foreach ($files as $file) {
-                echo '<script type="text/javascript" src="' . htmlspecialchars($file) . "\"></script>\n";
-            }
-        }
-    }
-
-}
index e70dba1..720c56d 100644 (file)
@@ -24,7 +24,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Added unit tests.
+ <notes>* Removed javascript listener.
+ * Added unit tests.
  * Added Horde_Notification::replace().
  * Initial Horde 4 package.
  </notes>
@@ -45,7 +46,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
       </dir> <!-- /lib/Horde/Notification/Handler -->
       <dir name="Listener">
        <file name="Audio.php" role="php" />
-       <file name="Javascript.php" role="php" />
        <file name="Status.php" role="php" />
       </dir> <!-- /lib/Horde/Notification/Listener -->
       <dir name="Storage">
@@ -80,7 +80,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
         <file name="ListenerTest.php" role="test" />
         <dir name="Listener">
          <file name="AudioTest.php" role="test" />
-         <file name="JavascriptTest.php" role="test" />
          <file name="StatusTest.php" role="test" />
         </dir> <!-- /test/Horde/Notification/Class/Notification/Listener -->
        </dir> <!-- /test/Horde/Notification/Class/Notification -->
@@ -124,7 +123,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Notification/Handler/Decorator/Base.php" as="Horde/Notification/Handler/Decorator/Base.php" />
    <install name="lib/Horde/Notification/Handler/Decorator/Log.php" as="Horde/Notification/Handler/Decorator/Log.php" />
    <install name="lib/Horde/Notification/Listener/Audio.php" as="Horde/Notification/Listener/Audio.php" />
-   <install name="lib/Horde/Notification/Listener/Javascript.php" as="Horde/Notification/Listener/Javascript.php" />
    <install name="lib/Horde/Notification/Listener/Status.php" as="Horde/Notification/Listener/Status.php" />
    <install name="lib/Horde/Notification/Storage/Interface.php" as="Horde/Notification/Storage/Interface.php" />
    <install name="lib/Horde/Notification/Storage/Object.php" as="Horde/Notification/Storage/Object.php" />
@@ -142,7 +140,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="test/Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php" as="Horde/Notification/Class/Notification/Handler/Decorator/LogTest.php" />
    <install name="test/Horde/Notification/Class/Notification/ListenerTest.php" as="Horde/Notification/Class/Notification/ListenerTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Listener/AudioTest.php" as="Horde/Notification/Class/Notification/Listener/AudioTest.php" />
-   <install name="test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php" as="Horde/Notification/Class/Notification/Listener/JavascriptTest.php" />
    <install name="test/Horde/Notification/Class/Notification/Listener/StatusTest.php" as="Horde/Notification/Class/Notification/Listener/StatusTest.php" />
   </filelist>
  </phprelease>
diff --git a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php b/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php
deleted file mode 100644 (file)
index 3f11306..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * Test the javascript listener class.
- *
- * @category Horde
- * @package  Notification
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Notification
- */
-
-/**
- * Prepare the test setup.
- */
-require_once dirname(__FILE__) . '/../../../Autoload.php';
-
-/**
- * Test the javascript listener class.
- *
- * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Horde
- * @package  Notification
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Notification
- */
-class Horde_Notification_Class_Notification_Listener_JavascriptTest extends PHPUnit_Extensions_OutputTestCase
-{
-    public function testMethodHandleHasEventClassForjavascriptMessages()
-    {
-        $listener = new Horde_Notification_Listener_Javascript();
-        $this->assertEquals('Horde_Notification_Event', $listener->handles('javascript'));
-    }
-
-    public function testMethodGetnameHasResultStringJavascript()
-    {
-        $listener = new Horde_Notification_Listener_Javascript();
-        $this->assertEquals('javascript', $listener->getName());
-    }
-
-    public function testMethodNotifyHasNoOutputIfTheMessageStackIsEmpty()
-    {
-        $listener = new Horde_Notification_Listener_Javascript();
-        $messages = array();
-        $listener->notify($messages);
-    }
-
-    public function testMethodNotifyHasOutputEventMessageEmbeddedInScriptElement()
-    {
-        $listener = new Horde_Notification_Listener_Javascript();
-        $event = new Horde_Notification_Event('test', 'javascript');
-        $messages = array($event);
-        $this->expectOutputString(
-            '<script type="text/javascript">//<![CDATA['
-            . "\n" . 'test' . "\n" . '//]]></script>' . "\n"
-        );
-        $listener->notify($messages);
-    }
-
-    public function testMethodNotifyHasOutputEventMessageNotEmbeddedIfEmbeddingIsDeactivated()
-    {
-        $listener = new Horde_Notification_Listener_Javascript();
-        $event = new Horde_Notification_Event('test', 'javascript');
-        $messages = array($event);
-        $this->expectOutputString('test');
-        $listener->notify($messages, array('noscript' => true));
-    }
-
-    public function testMethodNotifyHasOutputJavaScriptFileLinkIfTheEventContainedSuchAFileLink()
-    {
-        $listener = new Horde_Notification_Listener_Javascript();
-        $event = new Horde_Notification_Event('test');
-        $event->type = 'javascript-file';
-        $messages = array($event);
-        $this->expectOutputString(
-            '<script type="text/javascript" src="test"></script>' . "\n"
-        );
-        $listener->notify($messages);
-    }
-
-}
index d1cd4d7..5b60936 100644 (file)
@@ -155,7 +155,9 @@ case 'editform':
 
 switch ($form) {
 case 'addchild.inc':
-    $notification->push('document.add_child.child.focus()', 'javascript');
+    Horde::addInlineScript(array(
+        '$("child").focus()'
+    ), 'dom');
     break;
 
 case 'edit.inc':
index 406f643..4e7f1d7 100644 (file)
@@ -7,7 +7,7 @@ if (document.title && parent.frames && parent.frames.horde_main) {
     parent.document.title = document.title;
 }
 </script>
-<?php $GLOBALS['notification']->notify(array('listeners' => array('audio', 'javascript'))); ?>
+<?php $GLOBALS['notification']->notify(array('listeners' => array('audio'))); ?>
 <?php endif; ?>
 </body>
 </html>
index fffa1d9..a47736c 100644 (file)
@@ -12,6 +12,6 @@ try {
 if (typeof(_setHordeTitle) == 'undefined' && document.title && parent.frames.horde_main) parent.document.title = document.title;
 // -->
 </script>
-<?php if (isset($GLOBALS['notification'])) $GLOBALS['notification']->notify(array('listeners' => array('audio', 'javascript'))); ?>
+<?php if (isset($GLOBALS['notification'])) $GLOBALS['notification']->notify(array('listeners' => array('audio'))); ?>
 </body>
 </html>
index 549cf77..0308b14 100644 (file)
 require_once dirname(__FILE__) . '/lib/Application.php';
 Horde_Registry::appInit('mnemo');
 
+Horde::addInlineScript(array(
+    '$("search_pattern").focus()'
+), 'dom');
+
 $title = _("Search");
-$notification->push('document.getElementById(\'search_pattern\').focus();', 'javascript');
-Horde::addScriptFile('prototype.js', 'horde', true);
 require MNEMO_TEMPLATES . '/common-header.inc';
 require MNEMO_TEMPLATES . '/menu.inc';
 $notification->notify();
index 0872b57..14cc374 100644 (file)
@@ -9,9 +9,11 @@
 require_once dirname(__FILE__) . '/lib/Application.php';
 Horde_Registry::appInit('nag');
 
+Horde::addInlineScript(array(
+    '$("search_pattern")'
+), 'dom');
+
 $title = _("Search");
-$notification->push('document.search.search_pattern.focus()', 'javascript');
-Horde::addScriptFile('prototype.js', 'horde');
 require NAG_TEMPLATES . '/common-header.inc';
 require NAG_TEMPLATES . '/menu.inc';
 require NAG_TEMPLATES . '/search/search.inc';
index 7889ed2..93e9625 100644 (file)
@@ -268,7 +268,10 @@ if (empty($userid)) {
     }
 }
 
-$notification->push('setFocus()', 'javascript');
+Horde::addInlineScript(array(
+    'setFocus()'
+), 'dom');
+
 $title = _("Change Password");
 require PASSWD_TEMPLATES . '/common-header.inc';
 require PASSWD_TEMPLATES . '/main/main.inc';
index e2a5e85..848cc83 100644 (file)
@@ -117,8 +117,11 @@ if ($conf['objects']['allow_absences']) {
                       htmlspecialchars(_("Absences")) . "</option>\n";
 }
 
+Horde::addInlineScript(array(
+    '$("stext").focus()'
+), 'dom');
+
 $title = _("Search");
-$notification->push('document.skoli_searchform.stext.focus();', 'javascript');
 
 Horde::addScriptFile('quickfinder.js', 'horde');
 Horde::addScriptFile('effects.js', 'horde');
index 809a912..45e9673 100644 (file)
@@ -108,8 +108,11 @@ case 'add_folder':
 }
 
 if (Horde_Util::getFormData('popup')) {
-    $notification->push('window.focus();', 'javascript');
+    Horde::addInlineScript(array(
+        'window.focus()'
+    ), 'dom');
 }
+
 $title = _("New Bookmark");
 require TREAN_TEMPLATES . '/common-header.inc';
 if (!Horde_Util::getFormData('popup') && !Horde_Util::getFormData('iframe')) {
index 122ef34..4261e8a 100644 (file)
@@ -248,12 +248,18 @@ if ($_SESSION['turba']['search_mode'] != 'duplicate') {
 switch ($_SESSION['turba']['search_mode']) {
 case 'basic':
     $title = _("Basic Search");
-    $notification->push('document.directory_search.val.focus();', 'javascript');
+    Horde::addInlineScript(array(
+        '$("val").focus()'
+    ), 'dom');
     break;
+
 case 'advanced':
     $title = _("Advanced Search");
-    $notification->push('document.directory_search.name.focus();', 'javascript');
+    Horde::addInlineScript(array(
+        '$("name").focus()'
+    ), 'dom');
     break;
+
 case 'duplicate':
     $title = _("Duplicate Search");
     break;
index 486053a..72fb40b 100644 (file)
@@ -161,12 +161,14 @@ class EditPage extends Page {
                 (Horde_String::lower(Horde_Util::getFormData('wicked_captcha')) != Horde_String::lower(Wicked::getCAPTCHA()))) {
                 $notification->push(_("Random string did not match."), 'horde.error');
                 return;
-            } 
+            }
             $text = Horde_Util::getFormData('page_text');
             $changelog = Horde_Util::getFormData('changelog');
             if ($conf['wicked']['require_change_log'] && empty($changelog)) {
                 $notification->push(_("You must provide a change log."), 'horde.error');
-                $notification->push('if (document.editform && document.editform.changelog) document.editform.changelog.focus();', 'javascript');
+                Horde::addInlineScript(array(
+                    'if (document.editform && document.editform.changelog) document.editform.changelog.focus()'
+                ), 'dom');
                 return;
             }
             $minorchange = Horde_Util::getFormData('minor');
index ed61103..e5cbe4c 100644 (file)
@@ -85,8 +85,6 @@ class NewPage extends Page {
      */
     function display()
     {
-        global $notification;
-
         // Load the page template.
         if ($this->_template) {
             $page = Page::getPage($this->_template);
@@ -95,7 +93,10 @@ class NewPage extends Page {
             $page_text = '';
         }
 
-        $notification->push('if (document.editform && document.editform.page_text) document.editform.page_text.focus();', 'javascript');
+        Horde::addInlineScript(array(
+            'if (document.editform && document.editform.page_text) document.editform.changelog.page_text()'
+        ), 'dom');
+
         require WICKED_TEMPLATES . '/edit/new.inc';
         return true;
     }