From 7c98645a7afe4fa57ac3b92748efbc1719cc5c6c Mon Sep 17 00:00:00 2001 From: Alex Arnaud <alex.arnaud@biblibre.com> Date: Wed, 8 Jul 2015 10:57:59 +0200 Subject: [PATCH] dev #24821 user notices Auth page and login box notifications rendered as popups. Ajax login as bar. --- .../modules/opac/controllers/AuthController.php | 4 ++-- library/Class/ScriptLoader.php | 5 ++++- .../Controller/Action/Helper/FlashMessenger.php | 4 +++- library/ZendAfi/Controller/Action/Helper/Notify.php | 10 +++++++++- .../modules/opac/controllers/AuthControllerTest.php | 13 ++++++++----- tests/library/Class/ScriptLoaderTest.php | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index e00ef876019..413c0b2c74f 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -101,7 +101,7 @@ class AuthController extends ZendAfi_Controller_Action { $strategy = Auth_Strategy_Abstract::strategyForController($this); $strategy->setDefaultUrl($this->_getParam('redirect','/opac')); $strategy->onLoginSuccess(function($user) { - $user->registerNotificationsOn($this->getHelper('notify')); + $user->registerNotificationsOn($this->getHelper('notify')->bePopup()); }); $strategy->processLogin(); $this->view->form_action = 'login'; @@ -155,7 +155,7 @@ class AuthController extends ZendAfi_Controller_Action { $strategy = Auth_Strategy_Abstract::strategyForController($this); $strategy->setDefaultUrl($this->_request->getServer('HTTP_REFERER')); $strategy->onLoginSuccess(function($user) { - $user->registerNotificationsOn($this->getHelper('notify')); + $user->registerNotificationsOn($this->getHelper('notify')->bePopup()); }); $strategy->processLogin(); diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index f7575c3f87c..ed5b1401967 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -21,6 +21,8 @@ class Class_ScriptLoader { + use Trait_Translator; + const MODE_JQUERY_READY = 0, MODE_JQUERY_MOBILE = 1, @@ -332,7 +334,8 @@ class Class_ScriptLoader { $this->notify(implode('. ', $bar_messages)); if ($popup_messages) - $this->addJQueryReady("$('<p>" .implode('<br> ', $popup_messages). "</p>').dialog()"); + $this->addJQueryReady("$('<p title=\"" . $this->_('Information') . "\">" + .implode('<br> ', $popup_messages). "</p>').dialog()"); return $this; diff --git a/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php b/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php index 42a104919b9..a86f3d0b844 100644 --- a/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php +++ b/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php @@ -66,7 +66,9 @@ class FlashMessengerNotification { } public function isPopup() { - return isset($this->_params['display']) && ($this->_params['display'] == 'popup'); + return + isset($this->_params['display']) + && ($this->_params['display'] == ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP); } } diff --git a/library/ZendAfi/Controller/Action/Helper/Notify.php b/library/ZendAfi/Controller/Action/Helper/Notify.php index 9f252615141..818b2dbc505 100644 --- a/library/ZendAfi/Controller/Action/Helper/Notify.php +++ b/library/ZendAfi/Controller/Action/Helper/Notify.php @@ -20,18 +20,26 @@ */ class ZendAfi_Controller_Action_Helper_Notify extends Zend_Controller_Action_Helper_Abstract { + protected $_options = []; + /** * [[file:~/public_html/afi-opac3/library/Class/ScriptLoader.php::public%20function%20showNotifications()%20{][voir Class_ScriptLoader::showNotifications]] */ public function notify($message) { $this->getActionController() ->getHelper('flashMessenger') - ->addNotification($message); + ->addNotification($message, $this->_options); } public function direct($message) { $this->notify($message); } + + + public function bePopup() { + $this->_options['display'] = ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP; + return $this; + } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index b294999e4b0..b9436ebd547 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -894,10 +894,10 @@ class AuthControllerPostSimpleSuccessfulTest extends AuthControllerPostSimpleSuc 2])); } - /** @test */ public function flasMessengerShouldContainMessageDeNotification() { - $this->assertFlashMessengerContentContains('Message de notification'); + $this->assertFlashMessengerContains([ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION => ['message' => 'Message de notification', + 'display' => 'popup']]); } } @@ -908,15 +908,17 @@ class AuthControllerAjaxLoginPostTest extends AuthControllerPostSimpleSuccessful parent::setUp(); $_SERVER['HTTP_REFERER'] = '/recherche/viewnotice'; $this->postDispatch('/opac/auth/ajax-login', - ['username' => 'foo', 'password' => 'bar'],true); + ['username' => 'foo', 'password' => 'bar'], true); } /** @test */ public function flashMessengerShouldContainMessageDeNotification() { - $this->assertFlashMessengerContentContains('Message de notification'); + $this->assertFlashMessengerContains( + [ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION => ['message' => 'Message de notification']]); } + /** @test */ public function responseShouldRedirectToReferrer() { $this->assertRedirectTo('/recherche/viewnotice'); @@ -937,7 +939,8 @@ class AuthControllerBoiteLoginPostTest extends AuthControllerPostSimpleSuccessfu /** @test */ public function flashMessengerShouldContainMessageDeNotification() { $this->assertFlashMessengerContains( - [ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION => ['message' => 'Message de notification']]); + [ZendAfi_Controller_Action_Helper_FlashMessenger::NOTIFICATION => ['message' => 'Message de notification', + 'display' => ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP]]); } /** @test */ diff --git a/tests/library/Class/ScriptLoaderTest.php b/tests/library/Class/ScriptLoaderTest.php index c01dc055841..e47360c48f9 100644 --- a/tests/library/Class/ScriptLoaderTest.php +++ b/tests/library/Class/ScriptLoaderTest.php @@ -267,7 +267,7 @@ class ScriptLoaderNotificationsBarTest extends Storm_Test_ModelTestCase { /** @test */ public function messageThreeAndFourShouldBePopupedUpInJQueryDialog() { - $this->assertContains("$('<p>Third message<br> Fourth message</p>').dialog()", + $this->assertContains("$('<p title=\"Information\">Third message<br> Fourth message</p>').dialog()", $this->_html); } } -- GitLab