Skip to content
Snippets Groups Projects
Commit b0f7b6e2 authored by Laurent's avatar Laurent
Browse files

dev #153909 Advanced search ListeSuggestion default mode

Add option "search_mode" to ListeSuggestion element to be able to
select wich search mode is selected by default on a custom advanced
search form
parent 52e5ad0c
Branches
Tags
1 merge request!4401dev #153909 Advanced search ListeSuggestion default mode
Pipeline #16829 canceled with stage
in 1 minute and 16 seconds
- fonctionnalité #153909 : Formulaire de recherche avancée : ajout de l'option "search_mode" pour les elements "listeSuggestion" qui permet de choisir quel mode de recherche est sélectionné par défaut.
\ No newline at end of file
......@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Form_Decorator_ListeSuggestion extends Zend_Form_Decorator_Abstract {
/**
......@@ -24,11 +24,16 @@ class ZendAfi_Form_Decorator_ListeSuggestion extends Zend_Form_Decorator_Abstrac
* @return string
*/
public function render($content) {
return $content
.$this->_element->getView()->tagListeSuggestion(
$this->_element->getRubrique(),
$this->_element->getName(),
$this->_element->getValue());
$helper = $this->_element->getView()->newHelper('TagListeSuggestion');
return
$content
.
$helper
->setSearchMode((int)$this->_element->getAttrib('search_mode'))
->tagListeSuggestion($this->_element->getRubrique(),
$this->_element->getName(),
$this->_element->getValue());
}
}
?>
\ No newline at end of file
?>
......@@ -22,6 +22,8 @@
class ZendAfi_View_Helper_TagListeSuggestion
extends ZendAfi_View_Helper_BaseHelper {
protected int $_search_mode = 0;
protected
$_config,
$_type,
......@@ -51,6 +53,12 @@ class ZendAfi_View_Helper_TagListeSuggestion
}
public function setSearchMode(int $search_mode) : self {
$this->_search_mode = $search_mode;
return $this;
}
protected function _renderSearch() {
return $this
->_div(['id' => $this->_name . '_saisie', 'class' => 'tag_saisie'],
......@@ -66,7 +74,12 @@ class ZendAfi_View_Helper_TagListeSuggestion
$options = $this->_config->getOptions();
$options = array_map(
function($label, $value) {
return $this->_tag('option', $label, ['value' => $value]);
$params = ['value' => $value];
if ($value === $this->_search_mode)
$params['selected'] = 'selected';
return $this->_tag('option', $label, $params);
},
$options,
array_keys($options));
......@@ -75,7 +88,7 @@ class ZendAfi_View_Helper_TagListeSuggestion
->_tag('select',
implode('', $options),
['id' => $this->_mode_name,
'onchange' => $this->_suggest_call
'onchange' => $this->_suggest_call,
]);
}
......
......@@ -890,13 +890,19 @@ class AdvancedSearchFormWithDeprecatedDomainsCriteriaTest
'rubrique' => 'dewey'])
->addElement('listeSuggestion', 'pcdm4',
['label' => 'Pcdm4',
'rubrique' => 'pcdm4'])
'rubrique' => 'pcdm4',
'search_mode' => Class_CodifSuggest::MODE_CONTAINS_EXACT_WORDS])
->addElement('listeSuggestion', 'interest',
['label' => 'Centres d\'intérêt',
'rubrique' => 'interet'])
->addElement('listeSuggestion', 'tag',
['label' => 'Tags utilisateur',
'rubrique' => 'tag'])
->addElement('listeSuggestion',
'THE1',
['label' => 'Thesaurus TEST',
'rubrique' => 'thesaurus',
'search_mode' => Class_CodifThesaurus::SUGGEST_LABEL_STARTS_WITH])
->addElement('cochesSuggestion', 'location',
['label' => 'Emplacements',
'rubrique' => 'emplacement'])
......@@ -950,6 +956,7 @@ class AdvancedSearchFormWithDeprecatedDomainsCriteriaTest
['pcdm4', 'pcdm4'],
['interet', 'interest'],
['tag', 'tag'],
['thesaurus', 'THE1']
];
}
......@@ -976,6 +983,27 @@ class AdvancedSearchFormWithDeprecatedDomainsCriteriaTest
return sprintf('//%s[contains(@%s, "/authority-suggest/suggest/type_autorite/%s/id_champ/%s")]',
$element, $attrib, $type, $id);
}
/** @test */
public function THE1suggestSelectedOptionShouldBeValueTwoLibelleCommencePar() {
$this->assertXPathContentContains('//select[@id="mode_THE1"]/option[@value=2][@selected]',
'Libellé commence par');
}
/** @test */
public function authorSuggestShouldNotHaveAnySelectedOption() {
$this->assertNotXPath('//select[@id="mode_author"]/option[@selected]');
}
/** @test */
public function pcdm4SuggestSelectOptionContainsExactWordsShouldBeSelected() {
$this->assertXPathContentContains('//select[@id="mode_pcdm4"]/option[@value=3][@selected]',
'Libellé contient l\'expression');
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment