Commit 934ac16e authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #67009 change select by ajaxSearch

parent a0e14d00
'67009' =>
['Label' => $this->_('Configuration de la Boîte bibliothèque numérique dans le contexte actuelle à + de 100000 albums'),
'Desc' => '',
'Image' => '',
'Video' => '',
'Category' => '',
'Right' => function($feature_description, $user) {return true;},
'Wiki' => '',
'Test' => '',
'Date' => '2017-12-11'],
\ No newline at end of file
- ticket #67009 : Configuration de la Boîte bibliothèque numérique dans le contexte actuelle à + de 100000 albums
\ No newline at end of file
......@@ -1463,6 +1463,18 @@ class Class_Album extends Storm_Model_Abstract {
return 'liste';
}
public function getLabel() {
return $this->getTitre();
}
public function getFullLabel() {
return $this->_('%s de %s',
$this->getAbsolutePath(),
$this->getMainAuthorName());
}
/**
* Main author
* @return string
......@@ -1630,4 +1642,3 @@ class Class_Album extends Storm_Model_Abstract {
return (new self())->_('Domaine public');
}
}
\ No newline at end of file
?>
\ No newline at end of file
......@@ -87,6 +87,32 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi
}
public function ajaxSearchAction() {
if(!$term = $this->_getParam('term'))
return $this->_helper->json(['error' => $this->_('Veuillez préciser un terme ( url : /search/term/somethings )')]);
$models = call_user_func([$this->_getModelLoader(),
'findAllBy'],
$this->_getSearchParams($term));
$response = [];
foreach($models as $model)
$response [] = ['label' => $model->getFullLabel(),
'value' => $model->getId()];
$this->_helper->json($response);
}
protected function _getSearchParams($term) {
$term = Zend_Db_Table::getDefaultAdapter()->quote('%' . $term . '%');
$where = $this->_getModelLabel() . ' like ' . $term;
return ['where' => $where,
'order' => $this->_getModelOrder(),
'limit' => 10];
}
public function addAction() {
if ($this->_response->isRedirect())
return;
......@@ -520,4 +546,37 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi
protected function _getModelActions() {
return call_user_func($this->_model_actions);
}
public function visitModelLoader($callback) {
$this->_model_loader = $callback;
return $this;
}
protected function _getModelLoader() {
return call_user_func($this->_model_loader);
}
public function visitModelLabel($callback) {
$this->_model_label = $callback;
return $this;
}
protected function _getModelLabel() {
return call_user_func($this->_model_label);
}
public function visitModelOrder($callback) {
$this->_model_order = $callback;
return $this;
}
protected function _getModelOrder() {
return call_user_func($this->_model_order);
}
}
\ No newline at end of file
......@@ -165,6 +165,13 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen
}
public function getModelLabel() {
if (isset($this->_attribs['model']['model_label']))
return $this->_attribs['model']['model_label'];
return 'libelle';
}
public function getOrder() {
if (isset($this->_attribs['model']['order']))
return $this->_attribs['model']['order'];
......@@ -340,6 +347,14 @@ abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends Zen
{
return $this->getModelId();
})
->visitModelLabel(function()
{
return $this->getModelLabel();
})
->visitModelOrder(function()
{
return $this->getOrder();
})
->visitModelActions(function()
{
return $this->getModelActions();
......
......@@ -25,8 +25,8 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_Album extends ZendAfi_Control
public function getDefinitions() {
return ['model' => ['class' => 'Class_Album',
'name' => 'album',
'order' => 'libelle',
'model_id' => 'id']];
'order' => 'titre',
'model_id' => 'id',
'model_label' => 'titre']];
}
}
\ No newline at end of file
?>
\ No newline at end of file
......@@ -44,10 +44,11 @@ class ZendAfi_Form_Configuration_Widget_Albums extends ZendAfi_Form_Configuratio
['label' => $this->_('Collection'),
'multiOptions' => $this->_getCollections()])
->addElement('select',
->addElement('ajaxSearch',
'id_albums',
['label' => $this->_('Album'),
'multiOptions' => $this->_getAlbums()])
'source' => Class_Url::absolute('/admin/album/ajax-search'),
'placeholder' => $this->_('Rechercher un album')])
->addElement('imagesViewer',
'style_liste',
......@@ -150,7 +151,7 @@ formSelectToggleVisibilityForElement("#type_aff", $("#id_categorie, #nb_aff_by_p
protected function _getAlbums() {
$albums = [];
return $albums = [];
foreach (Class_AlbumCategorie::findAlbumsRecursively() as $album)
$albums[$album->getId()] = $this->_getAlbum($album);
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* 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
*/
class ZendAfi_Form_Decorator_AjaxSearch extends Zend_Form_Decorator_Abstract {
public function render($content) {
$settings = new Class_Entity(array_merge(
['InputName' => $this->_element->getName(),
'InputValue' => $this->_element->getValue(),
'Source' => $this->_element->getSource()],
$this->_element->getAttribs()));
return $this->_element->getView()->ajaxSearch($settings);
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* 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
*/
class ZendAfi_Form_Element_AjaxSearch extends Zend_Form_Element {
protected
$_source;
public function __construct($spec, $options = null) {
parent::__construct($spec, $options);
$decorators = $this->_decorators;
$this->_decorators = ['AjaxSearch' => new ZendAfi_Form_Decorator_AjaxSearch()];
foreach ($decorators as $name => $value)
$this->_decorators[$name] = $value;
$this->removeDecorator('ViewHelper');
}
public function setSource($source) {
$this->_source = $source;
return $this;
}
public function getSource() {
return $this->_source;
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* 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
*/
class ZendAfi_View_Helper_AjaxSearch extends ZendAfi_View_Helper_BaseHelper {
public function ajaxSearch($settings) {
$name = $settings->getInputName();
Class_ScriptLoader::getInstance()
->addJQueryReady(sprintf('$("#%s").autocomplete({ source: "%s" , delay: 300 , minLength: 2 });',
$name,
$settings->getSource()));
return $this->_tag('input',
null,
['type' => 'text',
'id' => $name,
'name' => $name,
'value' => $settings->getInputValue(),
'placeholder' => $settings->getplaceholder()]);
}
}
\ No newline at end of file
......@@ -3379,3 +3379,28 @@ class Admin_AbstractControllerAlbumDeleteVignetteTest extends Admin_AlbumControl
$this->assertEquals('', $this->_album->getNotice()->getUrlVignette());
}
}
class Admin_AlbumControllerAjaxSearchTest extends Admin_AbstractControllerTestCase {
public function setUp() {
parent::setUp();
$album = $this->fixture('Class_Album',
['id' => 1,
'titre' => 'Hello world']);
$second_album = $this->fixture('Class_Album',
['id' => 2,
'titre' => 'Hello moon']);
$this->dispatch('/admin/album/ajax-search/term/hello', true);
}
/** @test */
public function shouldReturnAlbumsJson() {
$this->assertEquals('[{"label":"Albums non class\u00e9s>Hello moon de ","value":2},{"label":"Albums non class\u00e9s>Hello world de ","value":1}]', $this->_response->getBody());
}
}
\ No newline at end of file
......@@ -602,3 +602,25 @@ class WidgetsButtonsTest extends WidgetsNavSimpleTestCase {
$this->assertNotXPathContentContains('//button', 'Valider et continuer');
}
}
class WidgetsEditAlbumsWidgetTest extends WidgetsSimpleTestCase {
public function setUp() {
parent::setUp();
$simple_widgets = ['modules' => ['4' => ['division' => '1',
'type_module' => Class_Systeme_ModulesAccueil_BibliothequeNumerique::CODE]]];;
Class_Profil::getCurrentProfil()
->setCfgAccueil($simple_widgets)
->save();
$this->dispatch('admin/widget/edit-widget/id/4/id_profil/2', true);
}
/** @test */
public function ajaxSearchShouldBePresent() {
$this->assertXPathContentContains('//script', '$("#id_albums").autocomplete');
}
}
\ No newline at end of file
Markdown is supported
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