From 061f3e9f5151158fec782ccd71e3eda95acb94aa Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 8 Oct 2020 18:17:35 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02847=20-=20Quick=20create:=20Add=20confi?= =?UTF-8?q?g.=20parameter=20for=20max.=20autocomplete=20results=20('quick?= =?UTF-8?q?=5Fcreate.max=5Fautocomplete=5Fresults')?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config.class.inc.php | 8 ++++++++ js/components/quick-create.js | 5 ++--- .../UI/Component/QuickCreate/QuickCreate.php | 13 +++++++++++++ templates/components/quick-create/layout.js.twig | 4 +++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/core/config.class.inc.php b/core/config.class.inc.php index dcf189b4b..0b002db8c 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -1136,6 +1136,14 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ), + 'quick_create.max_autocomplete_results' => array( + 'type' => 'integer', + 'description' => 'Max. number of elements returned by the autocomplete.', + 'default' => 10, + 'value' => 10, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), 'global_search.enabled' => array( 'type' => 'bool', 'description' => 'Whether or not the global search is enabled', diff --git a/js/components/quick-create.js b/js/components/quick-create.js index c18f758b9..11a7f9657 100644 --- a/js/components/quick-create.js +++ b/js/components/quick-create.js @@ -26,7 +26,7 @@ $(function() // default options options: { - + max_autocomplete_results: 10, }, css_classes: { @@ -58,7 +58,6 @@ $(function() { const me = this; - // TODO 2.8.0 Use config parameter for maxOptions value // Instantiate selectize.js on input this.element.find(this.js_selectors.input).selectize({ dropdownParent: this.js_selectors.select_dropdown_parent, @@ -66,7 +65,7 @@ $(function() dropdownContentClass: 'ibo-quick-create--compartment-results--element', openOnFocus: false, maxItems: 1, - maxOptions: 10, + maxOptions: this.options.max_autocomplete_results, }); // Remove some inline styling from the widget diff --git a/sources/application/UI/Component/QuickCreate/QuickCreate.php b/sources/application/UI/Component/QuickCreate/QuickCreate.php index 18b9af63e..e20c42f6b 100644 --- a/sources/application/UI/Component/QuickCreate/QuickCreate.php +++ b/sources/application/UI/Component/QuickCreate/QuickCreate.php @@ -21,6 +21,7 @@ namespace Combodo\iTop\Application\UI\Component\QuickCreate; use Combodo\iTop\Application\UI\UIBlock; +use MetaModel; use UserRights; /** @@ -52,6 +53,8 @@ class QuickCreate extends UIBlock protected $aAvailableClasses; /** @var array $aLastClasses */ protected $aLastClasses; + /** @var int $iMaxAutocompleteResults Max. number of elements returned by the autocomplete */ + protected $iMaxAutocompleteResults; /** * QuickCreate constructor. @@ -67,6 +70,7 @@ class QuickCreate extends UIBlock parent::__construct($sId); $this->aAvailableClasses = UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('bizmodel'), true); $this->aLastClasses = $aLastClasses; + $this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results'); } /** @@ -102,4 +106,13 @@ class QuickCreate extends UIBlock { return $this->aLastClasses; } + + /** + * @see $iMaxAutocompleteResults + * @return int + */ + public function GetMaxAutocompleteResults(): int + { + return $this->iMaxAutocompleteResults; + } } \ No newline at end of file diff --git a/templates/components/quick-create/layout.js.twig b/templates/components/quick-create/layout.js.twig index 8fa2f551b..3385300ec 100644 --- a/templates/components/quick-create/layout.js.twig +++ b/templates/components/quick-create/layout.js.twig @@ -1 +1,3 @@ -$('#{{ oUIBlock.GetId() }}').quick_create(); \ No newline at end of file +$('#{{ oUIBlock.GetId() }}').quick_create({ + max_autocomplete_results: {{ oUIBlock.GetMaxAutocompleteResults() }} +}); \ No newline at end of file