From: Michael M Slusarz Date: Thu, 29 Jul 2010 17:04:49 +0000 (-0600) Subject: Remove javascript notification listener X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5b68df4f310a217b1cebc18d3b4a5075b077225d;p=horde.git Remove javascript notification listener --- diff --git a/ansel/gallery.php b/ansel/gallery.php index aca84e3cd..28dbf3f2d 100644 --- a/ansel/gallery.php +++ b/ansel/gallery.php @@ -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; diff --git a/ansel/gallery/sort.php b/ansel/gallery/sort.php index 683305e05..7b1d44cc8 100644 --- a/ansel/gallery/sort.php +++ b/ansel/gallery/sort.php @@ -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) { . ''; } echo ''; -$notification->push('Sortable.create(\'sortContainer\', {tag: \'div\', overlap: \'horizontal\', constraint: false })', 'javascript'); require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/fima/postings.php b/fima/postings.php index 690ee52d4..00d6c73ff 100644 --- a/fima/postings.php +++ b/fima/postings.php @@ -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'; diff --git a/fima/report.php b/fima/report.php index c05d60735..cfe8f35a3 100644 --- a/fima/report.php +++ b/fima/report.php @@ -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')) { diff --git a/fima/search.php b/fima/search.php index ca5e88f71..7808c0a16 100644 --- a/fima/search.php +++ b/fima/search.php @@ -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')) { diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php index 549d110c7..e5a867d2b 100644 --- a/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Desktop.php @@ -18,11 +18,11 @@ 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)); } /** diff --git a/framework/Core/lib/Horde/Core/Binder/Alarm.php b/framework/Core/lib/Horde/Core/Binder/Alarm.php index 8c5b23e98..200971b9a 100644 --- a/framework/Core/lib/Horde/Core/Binder/Alarm.php +++ b/framework/Core/lib/Horde/Core/Binder/Alarm.php @@ -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 index aa85dd421..000000000 --- a/framework/Notification/lib/Horde/Notification/Listener/Javascript.php +++ /dev/null @@ -1,71 +0,0 @@ - - * @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: - *
-     * 'noscript' - TODO
-     * 
- */ - 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 '\n"; - } - - foreach ($files as $file) { - echo '\n"; - } - } - } - -} diff --git a/framework/Notification/package.xml b/framework/Notification/package.xml index e70dba110..720c56d61 100644 --- a/framework/Notification/package.xml +++ b/framework/Notification/package.xml @@ -24,7 +24,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Added unit tests. + * Removed javascript listener. + * Added unit tests. * Added Horde_Notification::replace(). * Initial Horde 4 package. @@ -45,7 +46,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -80,7 +80,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -124,7 +123,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -142,7 +140,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - 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 index 3f11306a1..000000000 --- a/framework/Notification/test/Horde/Notification/Class/Notification/Listener/JavascriptTest.php +++ /dev/null @@ -1,85 +0,0 @@ - - * @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 - * @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( - '' . "\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( - '' . "\n" - ); - $listener->notify($messages); - } - -} diff --git a/horde/admin/groups.php b/horde/admin/groups.php index d1cd4d7a3..5b6093697 100644 --- a/horde/admin/groups.php +++ b/horde/admin/groups.php @@ -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': diff --git a/horde/templates/common-footer.inc b/horde/templates/common-footer.inc index 406f64378..4e7f1d7fd 100644 --- a/horde/templates/common-footer.inc +++ b/horde/templates/common-footer.inc @@ -7,7 +7,7 @@ if (document.title && parent.frames && parent.frames.horde_main) { parent.document.title = document.title; } -notify(array('listeners' => array('audio', 'javascript'))); ?> +notify(array('listeners' => array('audio'))); ?> diff --git a/kastalia/templates/common-footer.inc b/kastalia/templates/common-footer.inc index fffa1d915..a47736c78 100644 --- a/kastalia/templates/common-footer.inc +++ b/kastalia/templates/common-footer.inc @@ -12,6 +12,6 @@ try { if (typeof(_setHordeTitle) == 'undefined' && document.title && parent.frames.horde_main) parent.document.title = document.title; // --> -notify(array('listeners' => array('audio', 'javascript'))); ?> +notify(array('listeners' => array('audio'))); ?> diff --git a/mnemo/search.php b/mnemo/search.php index 549cf77bf..0308b140c 100644 --- a/mnemo/search.php +++ b/mnemo/search.php @@ -14,9 +14,11 @@ 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(); diff --git a/nag/search.php b/nag/search.php index 0872b57ae..14cc3741e 100644 --- a/nag/search.php +++ b/nag/search.php @@ -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'; diff --git a/passwd/main.php b/passwd/main.php index 7889ed24c..93e96253d 100644 --- a/passwd/main.php +++ b/passwd/main.php @@ -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'; diff --git a/skoli/search.php b/skoli/search.php index e2a5e856b..848cc83bd 100644 --- a/skoli/search.php +++ b/skoli/search.php @@ -117,8 +117,11 @@ if ($conf['objects']['allow_absences']) { htmlspecialchars(_("Absences")) . "\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'); diff --git a/trean/add.php b/trean/add.php index 809a91243..45e967397 100644 --- a/trean/add.php +++ b/trean/add.php @@ -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')) { diff --git a/turba/search.php b/turba/search.php index 122ef3430..4261e8a71 100644 --- a/turba/search.php +++ b/turba/search.php @@ -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; diff --git a/wicked/lib/Page/EditPage.php b/wicked/lib/Page/EditPage.php index 486053afc..72fb40bf4 100644 --- a/wicked/lib/Page/EditPage.php +++ b/wicked/lib/Page/EditPage.php @@ -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'); diff --git a/wicked/lib/Page/NewPage.php b/wicked/lib/Page/NewPage.php index ed61103ca..e5cbe4c8d 100644 --- a/wicked/lib/Page/NewPage.php +++ b/wicked/lib/Page/NewPage.php @@ -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; }