From 3fc226b0ad0585b46d855535308d56d480ab133b Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Tue, 8 Jul 2014 18:21:40 +1000 Subject: [PATCH] Add search to record finder --- modules/backend/assets/css/october.css | 10 +++++ .../backend/assets/less/controls/forms.less | 12 +++++ modules/backend/formwidgets/RecordFinder.php | 32 +++++++++++++ .../partials/_recordfinder_form.htm | 5 ++- modules/backend/widgets/Search.php | 45 ++++++++++++++++--- .../widgets/search/partials/_search.htm | 2 +- 6 files changed, 97 insertions(+), 9 deletions(-) diff --git a/modules/backend/assets/css/october.css b/modules/backend/assets/css/october.css index b5dfb783c..fb406fc2b 100644 --- a/modules/backend/assets/css/october.css +++ b/modules/backend/assets/css/october.css @@ -8262,10 +8262,14 @@ label { margin-top: -44px; height: 88px; width: 36px; + color: #8c8c8c; } .field-recordfinder .btn i { font-size: 14px; } +.field-recordfinder .btn:hover { + color: #666666; +} .field-recordfinder .text-muted i { font-size: 14px; position: relative; @@ -8276,6 +8280,12 @@ label { .field-recordfinder .primary { font-weight: 600; } +.recordfinder-search { + background-position: right -81px !important; + border-top: none !important; + border-left: none !important; + border-right: none !important; +} .form-buttons { padding-bottom: 20px; font-size: 0; diff --git a/modules/backend/assets/less/controls/forms.less b/modules/backend/assets/less/controls/forms.less index 2a5942c05..62875db49 100644 --- a/modules/backend/assets/less/controls/forms.less +++ b/modules/backend/assets/less/controls/forms.less @@ -213,10 +213,15 @@ label { margin-top: -44px; height: 88px; width: 36px; + color: lighten(@btn-default-color, 15%); i { font-size: 14px; } + + &:hover { + color: @btn-default-color; + } } .text-muted i { font-size: 14px; @@ -230,6 +235,13 @@ label { } } +.recordfinder-search { + background-position: right -81px !important; + border-top: none !important; + border-left: none !important; + border-right: none !important; +} + .form-buttons { .clearfix(); padding-bottom: 20px; diff --git a/modules/backend/formwidgets/RecordFinder.php b/modules/backend/formwidgets/RecordFinder.php index 304738258..7b5346475 100644 --- a/modules/backend/formwidgets/RecordFinder.php +++ b/modules/backend/formwidgets/RecordFinder.php @@ -64,6 +64,11 @@ class RecordFinder extends FormWidgetBase */ protected $listWidget; + /** + * @var Backend\Classes\WidgetBase Reference to the widget used for searching. + */ + protected $searchWidget; + /** * {@inheritDoc} */ @@ -82,6 +87,20 @@ class RecordFinder extends FormWidgetBase if (post('recordfinder_flag')) { $this->listWidget = $this->makeListWidget(); + $this->listWidget->bindToController(); + + $this->searchWidget = $this->makeSearchWidget(); + $this->searchWidget->bindToController(); + + /* + * Link the Search Widget to the List Widget + */ + $this->searchWidget->bindEvent('search.submit', function() { + $this->listWidget->setSearchTerm($this->searchWidget->getActiveTerm()); + return $this->listWidget->onRefresh(); + }); + + $this->searchWidget->setActiveTerm(null); } } @@ -112,6 +131,7 @@ class RecordFinder extends FormWidgetBase $this->vars['nameValue'] = $this->getNameValue(); $this->vars['descriptionValue'] = $this->getDescriptionValue(); $this->vars['listWidget'] = $this->listWidget; + $this->vars['searchWidget'] = $this->searchWidget; $this->vars['prompt'] = str_replace('%s', '', $this->prompt); } @@ -168,6 +188,7 @@ class RecordFinder extends FormWidgetBase $config->alias = $this->alias . 'List'; $config->showSetup = false; $config->showCheckboxes = false; + $config->recordsPerPage = 20; $config->recordOnClick = sprintf("$('#%s').recordFinder('updateRecord', this, ':id')", $this->getId()); $widget = $this->makeWidget('Backend\Widgets\Lists', $config); @@ -185,4 +206,15 @@ class RecordFinder extends FormWidgetBase return $widget; } + + protected function makeSearchWidget() + { + $config = $this->makeConfig(); + $config->alias = $this->alias . 'Search'; + $config->growable = false; + $config->useSession = false; + $widget = $this->makeWidget('Backend\Widgets\Search', $config); + $widget->cssClasses[] = 'recordfinder-search'; + return $widget; + } } \ No newline at end of file diff --git a/modules/backend/formwidgets/recordfinder/partials/_recordfinder_form.htm b/modules/backend/formwidgets/recordfinder/partials/_recordfinder_form.htm index 5519b19bc..2b11c962c 100644 --- a/modules/backend/formwidgets/recordfinder/partials/_recordfinder_form.htm +++ b/modules/backend/formwidgets/recordfinder/partials/_recordfinder_form.htm @@ -5,7 +5,10 @@ - render() ?> +
+ render() ?> + render() ?> +