From ba11dcb144f6f80c26672406d383240ab188d102 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Mon, 29 Oct 2018 10:48:45 +0100 Subject: [PATCH] dev #80538 search reset button tracks wich form tab to display --- .../opac/controllers/RechercheController.php | 2 +- .../views/scripts/recherche/avancee.phtml | 4 +- .../ZendAfi/View/Helper/AdvancedSearch.php | 22 ++++++----- public/opac/js/tabify.js | 4 +- .../AdvancedSearch/AdvancedSearchTest.php | 37 ++++++++++++++++--- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index 03b098d8ded..2e9b1a88b94 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -284,7 +284,7 @@ class RechercheController extends ZendAfi_Controller_Action { public function avanceeAction() { $this->view->annexes = Class_CodifAnnexe::getMultiOptions(); $this->view->criteres_recherche = $this->newCriteresRecherches($this->_request->getParams()); - + $this->view->active_tab = $this->_getParam('form_id', 0); $this->view->search_forms = Class_SearchForm::findAllByPrefs(isset($this->preferences['forms']) ? $this->preferences['forms'] diff --git a/application/modules/opac/views/scripts/recherche/avancee.phtml b/application/modules/opac/views/scripts/recherche/avancee.phtml index 722476d96dd..085725d03fc 100644 --- a/application/modules/opac/views/scripts/recherche/avancee.phtml +++ b/application/modules/opac/views/scripts/recherche/avancee.phtml @@ -1,6 +1,6 @@ <?php echo $this->openBoite($this->_current_module['preferences']['titre']) - . $this->advancedSearch($this->search_forms) + . $this->advancedSearch($this->search_forms, $this->active_tab) . $this->closeBoite() - . $this->tag('div', $this->historiqueRecherche(), ['class' => 'conteneur_simple']); \ No newline at end of file + . $this->tag('div', $this->historiqueRecherche(), ['class' => 'conteneur_simple']); diff --git a/library/ZendAfi/View/Helper/AdvancedSearch.php b/library/ZendAfi/View/Helper/AdvancedSearch.php index 06434069005..72b02f8422e 100644 --- a/library/ZendAfi/View/Helper/AdvancedSearch.php +++ b/library/ZendAfi/View/Helper/AdvancedSearch.php @@ -22,7 +22,7 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper { - public function advancedSearch($search_forms = []) { + public function advancedSearch($search_forms = [], $active_tab = 0) { if(!Class_AdminVar::isCustomSearchFormEnabled()) return $this->view->legacyAdvancedSearch(); @@ -32,14 +32,14 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper return empty($html) ? $this->_renderDefaultAdvancedSearch() - : $this->_renderSearchForms($html); + : $this->_renderSearchForms($html, $active_tab); } - protected function _renderSearchForms($html_array) { + protected function _renderSearchForms($html_array, $active_tab) { $html = []; - foreach($html_array as $form) - $html [] = $this->_tag('div', $form, ['id' => md5($form), + foreach($html_array as $id => $form) + $html [] = $this->_tag('div', $form, ['id' => $id, 'class' => 'tabify_me']); $content = implode($html); @@ -48,8 +48,9 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper Class_ScriptLoader::getInstance() ->addOPACScript('tabify') - ->addJQueryReady(sprintf('$("#%s").tabify();', - $forms_container_id)); + ->addJQueryReady(sprintf('$("#%s").tabify({active:%d});', + $forms_container_id, + $active_tab)); return $this->_tag('div', $content, @@ -63,12 +64,13 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper } - protected function _clearFormButton() { + protected function _clearFormButton($form_id) { return $this->view->button((new Class_Entity()) ->setUrl($this->view->url(['module' => 'opac', 'controller' => 'recherche' , 'action' => 'avancee', - 'statut' => 'reset'], null,true)) + 'statut' => 'reset', + 'form_id' => $form_id], null,true)) ->setAttribs(['class' => 'bouton init', 'title' => $this->_('Réinitialiser le formulaire')]) ->setText($this->_('Réinitialiser'))); @@ -108,7 +110,7 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper $html = $this->_tag('p', $this->_('Ce formulaire n\'est pas visible.'), ['class' => 'error']) . $html; $html .= $this->view->renderForm($this->_populateForm($form_wrapper->getForm()), - ['append' => [$this->_clearFormButton()]]); + ['append' => [$this->_clearFormButton(count($content))]]); $content[] = $html; return $content; diff --git a/public/opac/js/tabify.js b/public/opac/js/tabify.js index c2969d5d3bd..b1e0b5cf7bd 100644 --- a/public/opac/js/tabify.js +++ b/public/opac/js/tabify.js @@ -19,7 +19,7 @@ */ (function ( $ ) { - $.fn.tabify = function() { + $.fn.tabify = function(options) { var html = $(this); var html_content = html.find('.tabify_me'); @@ -48,7 +48,7 @@ legend.remove(); }); - html.prepend(tabs).tabs(); + html.prepend(tabs).tabs(options); html.prepend(no_legend); html.find('a.errors.ui-tabs-anchor').first().click(); } diff --git a/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php b/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php index 8e0a297e2e9..65ff48fb005 100644 --- a/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php +++ b/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php @@ -468,11 +468,8 @@ $form - -class AdvancedSearchValidCustomFormsSelectedAndPublishedTest - extends AdvancedSearchCustomFormSelectedTestCase { - - protected function _prepareFixtures() { +abstract class AdvancedSearchValidCustomFormsSelectedAndPublishedTestCase extends AdvancedSearchCustomFormSelectedTestCase { + protected function _prepareFixtures() { parent::_prepareFixtures(); $author_search_form = 'userfiles/forms/author_search_form.php'; @@ -534,8 +531,13 @@ class AdvancedSearchValidCustomFormsSelectedAndPublishedTest ->setCfgModules(['recherche' => ['avancee' => ['forms' => '3;9']]]); ZendAfi_Auth::getInstance()->clearIdentity(); } +} + + +class AdvancedSearchValidCustomFormsSelectedAndPublishedTest extends AdvancedSearchValidCustomFormsSelectedAndPublishedTestCase { + /** @test */ public function authorFieldShouldBePresent() { $this->assertXPath('//input[@name="author_field"]', $this->_response->getBody()); @@ -568,7 +570,30 @@ class AdvancedSearchValidCustomFormsSelectedAndPublishedTest /** @test */ public function formShouldContainsResetButton() { - $this->assertXPathContentContains('//button[contains(@data-url,"/recherche/avancee/statut/reset")]', 'Réinitialiser'); + $this->assertXPathContentContains('//button[contains(@data-url,"/recherche/avancee/statut/reset/form_id/1")]', 'Réinitialiser'); + } +} + + + +class AdvancedSearchResetSecondFormTest extends AdvancedSearchValidCustomFormsSelectedAndPublishedTestCase { + public function setUp() { + AbstractControllerTestCase::setUp(); + + $this->_prepareFixtures(); + } + + /** @test */ + public function resetFormIdOneShouldActivateFormIdOne() { + $this->dispatch('/recherche/avancee/statut/reset/form_id/1', true); + $this->assertXPathContentContains('//script', '.tabify({active:1})'); + } + + + /** @test */ + public function resetFormEmptyShouldActivateFormIdZero() { + $this->dispatch('/recherche/avancee/statut/reset', true); + $this->assertXPathContentContains('//script', '.tabify({active:0})'); } } -- GitLab