diff --git a/FEATURES/142671 b/FEATURES/142671 new file mode 100644 index 0000000000000000000000000000000000000000..20201723327c5c1a52de3e85d23bbc1afe865ecc --- /dev/null +++ b/FEATURES/142671 @@ -0,0 +1,10 @@ + '142671' => + ['Label' => $this->_('Lors de l\'ajout d'une boite sur le catalogue, la vue reste focalisée sur la nouvelle boite'), + 'Desc' => '', + 'Image' => '', + 'Video' => '', + 'Category' => 'Administration', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'https://wiki.bokeh-library-portal.org/index.php?title=Configurer_une_page', + 'Test' => '', + 'Date' => '2021-12-07'], \ No newline at end of file diff --git a/VERSION_WIP/142671 b/VERSION_WIP/142671 new file mode 100644 index 0000000000000000000000000000000000000000..51ba9b31b7fc1aca9eaf0a6b2a8c24bb95040024 --- /dev/null +++ b/VERSION_WIP/142671 @@ -0,0 +1 @@ + - ticket #142671 : Administration : Lors de l'ajout d'une boite sur un profil, la vue se re-centre automatiquement sur la nouvelle boite. \ No newline at end of file diff --git a/application/modules/admin/controllers/WidgetController.php b/application/modules/admin/controllers/WidgetController.php index f2b18caec9937863bcb7073d354e4bcec980662c..fb8d43cb11b0b545421e42345932704c7f7d9642 100644 --- a/application/modules/admin/controllers/WidgetController.php +++ b/application/modules/admin/controllers/WidgetController.php @@ -287,7 +287,13 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { return $this->_redirectClose($this->_getReferer()); } - $this->_helper->notify($widget->getSuccessSaveMessage(), ['status' => 'success']); + $this->_helper + ->getHelper('flashMessenger') + ->addScript('document.getElementById(\'boite_' . $widget->getId() . '\').' + . 'scrollIntoView({behavior:\'smooth\',block:\'start\'})'); + + $this->_helper->notify($widget->getSuccessSaveMessage(), + ['status' => 'success']); $this->_plugins ->eachDo(function($plugin) use($widget) diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml index cc0e08e593577434785fd7dea79622c8c5573282..ec6cd5fda302cc80ac3dc327a1bdb91cdf406be0 100644 --- a/application/modules/opac/views/scripts/head.phtml +++ b/application/modules/opac/views/scripts/head.phtml @@ -44,7 +44,8 @@ initializePopups(); initializeDivisionFive(); initializeReloadModule();') - ->showNotifications(); + ->showNotifications() + ->addFlashScripts(); $this->adminTools(); diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index 08f5d5749c8b3ddb0d4f528b6e3b609abdb44d76..4481ca751b33f0298bbdf84e6c4a345c8137187c 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -324,6 +324,14 @@ class Class_ScriptLoader { } + public function addFlashScripts() : self { + if ($scripts = (new ZendAfi_Controller_Action_Helper_FlashMessenger)->getScripts()) + $this->addJQueryReady(implode(';', $scripts)); + + return $this; + } + + /** * Affiche les messages du flashMessenger dans un popup / drop down * voir [[file:~/public_html/afi-opac3/application/modules/opac/views/scripts/head.phtml::->showNotifications()%3B][head]] diff --git a/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php b/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php index fef217f94f2ac676e60ffbe79499d51cf662a7b5..9a9e6a262b82ce769a53a1546ff29d9e9546fcf8 100644 --- a/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php +++ b/library/ZendAfi/Controller/Action/Helper/FlashMessenger.php @@ -22,24 +22,43 @@ class ZendAfi_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Action_Helper_FlashMessenger { const POPUP = 'popup', - NOTIFICATION = 'notification'; + NOTIFICATION = 'notification', + SCRIPT = 'script'; public static function reset() { self::$_session = null; } + public function addNotification($message, $options = []) { $params = ['message' => $message] + $options; - $this->addMessage([self::NOTIFICATION => $params]); + $this->addMessage([static::NOTIFICATION => $params]); + } + + + public function addScript(string $script) : self { + $this->addMessage([static::SCRIPT => $script]); + return $this; } + public function isNotification($message) { - return is_array($message) && isset($message[self::NOTIFICATION]); + return $this->isType($message, static::NOTIFICATION); } public function isPopup($message) { - return is_array($message) && isset($message[self::POPUP]); + return $this->isType($message, static::POPUP); + } + + + public function isScript($message) { + return $this->isType($message, static::SCRIPT); + } + + + public function isType($message, $type) { + return is_array($message) && isset($message[$type]); } @@ -48,7 +67,7 @@ class ZendAfi_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Ac ->select(function($e) {return $this->isNotification($e);}) ->collect(function($e) { - return new ZendAfi_Controller_Action_Helper_FlashMessenger_Notification($e[self::NOTIFICATION]); + return new ZendAfi_Controller_Action_Helper_FlashMessenger_Notification($e[static::NOTIFICATION]); }); } @@ -56,4 +75,13 @@ class ZendAfi_Controller_Action_Helper_FlashMessenger extends Zend_Controller_Ac public function getPopups() { return array_filter($this->getMessages(), [$this, 'isPopup']); } + + + public function getScripts() : array { + return array_map(function($message) + { + return $message[static::SCRIPT]; + }, + array_filter($this->getMessages(), [$this, 'isScript'])); + } } \ No newline at end of file diff --git a/library/templates/Intonation/View/Opac.php b/library/templates/Intonation/View/Opac.php index cbdba0df2543829c3c6e25460f6b1306d32c8ee8..aaa9529b1f28950f7346af8a7e8f679e2dee3e1b 100644 --- a/library/templates/Intonation/View/Opac.php +++ b/library/templates/Intonation/View/Opac.php @@ -150,6 +150,7 @@ class Intonation_View_Opac extends ZendAfi_View_Helper_BaseHelper { '$("html, body").scrollTop(' . $this->_scrollOffset() . ');']; $script_loader->addJQueryReady(implode($scroll_script)); + $head_scripts->addFlashScripts(); if ($this->_template->getJquery()) $head_scripts->loadJQuery(); diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index e46a9708da039e720374a9c07e8c14715514c22a..0a04c018fa646b148006b90a0716e75fbca798ac 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -391,14 +391,24 @@ Error: ', public function assertFlashMessengerContainsPopup($url) { - $searched = [ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP => ['url' => $url]]; + return $this->assertFlashMessengerContainsValueForType(['url' => $url], ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP); + } + + + public function assertFlashMessengerContainsScript($script) { + return $this->assertFlashMessengerContainsValueForType($script, ZendAfi_Controller_Action_Helper_FlashMessenger::SCRIPT); + } + + + public function assertFlashMessengerContainsValueForType($value, $type) { + $searched = [$type => $value]; $messages = $this->_getFlashMessengerMessages(); - foreach($messages as $message_value) { + foreach($messages as $message_value) if ($message_value == $searched) return true; - } - $this->fail(sprintf('Flash messenger does not contains popup with url : %s \n %s', $url, json_encode($messages))); + $this->fail(sprintf('Flash messenger does not contains %s : %s \n %s', + $type, json_encode($value), json_encode($messages))); } diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php index e3703dbb5d11aa1a1e031c704afd2fc0eb236e7e..98f55aff1abc252d8f787b524e9c6ac6e1adf671 100644 --- a/tests/application/modules/admin/controllers/WidgetControllerTest.php +++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php @@ -2204,6 +2204,18 @@ class WidgetControllerAddActionPostDispatchTest extends WidgetControllerWidgetCo public function currentProfilShouldHaveNbNotices() { $this->assertEquals(20, $this->_profil->getCfgAccueilAsArray()['modules'][1]['preferences']['nb_notices']); } + + + /** @test */ + public function flashMessengerShouldContainsConfigDeBoiteSauvé() { + $this->assertFlashMessengerContentContains('La configuration de la boite mon titre a été sauvegardée'); + } + + + /** @test */ + public function flashMessengerShouldContainsScriptScrollToMonTitre() { + $this->assertFlashMessengerContainsScript('document.getElementById(\'boite_1\').scrollIntoView({behavior:\'smooth\',block:\'start\'})'); + } } diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php index 216cbc26208fa3b661a3f9898c3486ad442f0de0..99597094c013771bf59384d72960d6a047ea7a2d 100644 --- a/tests/application/modules/opac/controllers/IndexControllerTest.php +++ b/tests/application/modules/opac/controllers/IndexControllerTest.php @@ -554,6 +554,25 @@ class IndexControllerPrivateProfilesRewriteUrlWithDeletedLoginPageTest +class IndexControllerFlashScriptTestCase extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $messenger = new ZendAfi_Controller_Action_Helper_FlashMessenger(); + $messenger->addScript('alert("toto")'); + ZendAfi_Controller_Action_Helper_FlashMessenger::reset(); + $this->dispatch('/index'); + } + + + /** @test */ + public function indexShouldContainsAlertToto() { + $this->assertXPathContentContains('//script', 'alert("toto")'); + } +} + + + + abstract class IndexControllerCnilTrackingTestCase extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; protected $_expected_message = 'showNotification({"message":"En poursuivant votre navigation sur ce site, vous acceptez l\'utilisation de cookies.","autoClose":false'; diff --git a/tests/scenarios/Templates/TemplatesNotifyTest.php b/tests/scenarios/Templates/TemplatesNotifyTest.php index 522209cdc4b4271ca2377061c92e452039ba4eed..fa226213d15b6e7b5f83c50161a81a8bc3f4f465 100644 --- a/tests/scenarios/Templates/TemplatesNotifyTest.php +++ b/tests/scenarios/Templates/TemplatesNotifyTest.php @@ -44,7 +44,7 @@ class TemplatesDispatchIntonationWithNotificationsTest extends TemplatesIntonati parent::setUp(); (new ZendAfi_Controller_Action_Helper_FlashMessenger)->addNotification('Hello bokeh', ['status' => 'success']); ZendAfi_Controller_Action_Helper_FlashMessenger::reset(); - $this->dispatch('/opac/index/index/id_profil/72', true); + $this->dispatch('/opac/index/index/id_profil/72'); } @@ -53,3 +53,21 @@ class TemplatesDispatchIntonationWithNotificationsTest extends TemplatesIntonati $this->assertXPathContentContains('//div[contains(@class, "notify")]//div[contains(@class, "alert")][contains(@class, "alert-dismissible")][@role="alert"]', 'Hello bokeh'); } } + + + + +class TemplatesDispatchIntonationWithScriptTest extends TemplatesIntonationTestCase { + public function setUp() { + parent::setUp(); + (new ZendAfi_Controller_Action_Helper_FlashMessenger)->addScript('alert("Hello bokeh")'); + ZendAfi_Controller_Action_Helper_FlashMessenger::reset(); + $this->dispatch('/opac/index/index/id_profil/72'); + } + + + /** @test */ + public function headShouldContainsScriptAlertHelloBokeh() { + $this->assertXPathContentContains('//script', 'alert("Hello bokeh")'); + } +} \ No newline at end of file