From 906d97dce434b30cc2e2a0f3193fd31fa6c42779 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 6 Dec 2014 15:32:20 +1100 Subject: [PATCH] Add new options to RelationController (view mode): recordUrl, recordOnClick, toolbarButtons --- modules/backend/assets/css/october.css | 3 ++ .../backend/assets/less/controls/forms.less | 6 +++ .../backend/behaviors/RelationController.php | 40 ++++++++++++++----- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/modules/backend/assets/css/october.css b/modules/backend/assets/css/october.css index c3824a6fe..71d373066 100644 --- a/modules/backend/assets/css/october.css +++ b/modules/backend/assets/css/october.css @@ -8865,6 +8865,9 @@ label { .form-preview > .form-group:last-child { padding-bottom: 0; } +.form-preview.form-flush { + border-top: none; +} .form-elements:before, .form-tabless-fields:before, .form-elements:after, diff --git a/modules/backend/assets/less/controls/forms.less b/modules/backend/assets/less/controls/forms.less index 8d60b19f5..fb34edf33 100644 --- a/modules/backend/assets/less/controls/forms.less +++ b/modules/backend/assets/less/controls/forms.less @@ -36,8 +36,14 @@ label { >.form-group:last-child { padding-bottom: 0; } + + // Form to sit flush to the element above + &.form-flush { + border-top: none; + } } + // // Nice forms // diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index f31bd4992..28898504b 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -641,25 +641,42 @@ class RelationController extends ControllerBehavior protected function makeToolbarWidget() { - if ($this->readOnly) { - return; + $defaultConfig = []; + + /* + * Add buttons to toolbar + */ + $defaultButtons = null; + + if (!$this->readOnly) { + $defaultButtons = '~/modules/backend/behaviors/relationcontroller/partials/_toolbar.htm'; } - $defaultConfig = [ - 'buttons' => '@/modules/backend/behaviors/relationcontroller/partials/_toolbar.htm', - ]; + $defaultConfig['buttons'] = $this->getConfig('view[toolbarButtons]', $defaultButtons); + + /* + * Make config + */ $toolbarConfig = $this->makeConfig($this->getConfig('toolbar', $defaultConfig)); $toolbarConfig->alias = $this->alias . 'Toolbar'; /* * Add search to toolbar */ - if ($this->viewMode == 'multi' && $this->getConfig('view[showSearch]')) { + $useSearch = $this->viewMode == 'multi' && $this->getConfig('view[showSearch]'); + + if ($useSearch) { $toolbarConfig->search = [ 'prompt' => 'backend::lang.list.search_prompt' ]; } + /* + * No buttons, no search should mean no toolbar + */ + if (empty($toolbarConfig->search) && empty($toolbarConfig->buttons)) + return; + $toolbarWidget = $this->makeWidget('Backend\Widgets\Toolbar', $toolbarConfig); $toolbarWidget->cssClasses[] = 'list-header'; @@ -680,15 +697,20 @@ class RelationController extends ControllerBehavior $config->recordsPerPage = $this->getConfig('view[recordsPerPage]'); $config->showCheckboxes = $this->getConfig('view[showCheckboxes]', false); + $defaultOnClick = null; + if (!$this->readOnly) { - $config->recordOnClick = sprintf( + $defaultOnClick = sprintf( "$.oc.relationBehavior.clickManageListRecord(:id, '%s', '%s')", $this->field, $this->relationGetSessionKey() ); - $config->showCheckboxes = true; + $config->showCheckboxes = $this->getConfig('view[showCheckboxes]', true); } + $config->recordOnClick = $this->getConfig('view[recordOnClick]', $defaultOnClick); + $config->recordUrl = $this->getConfig('view[recordUrl]', null); + if ($emptyMessage = $this->getConfig('emptyMessage')) { $config->noRecordsMessage = $emptyMessage; } @@ -699,7 +721,7 @@ class RelationController extends ControllerBehavior $widget = $this->makeWidget('Backend\Widgets\Lists', $config); $widget->bindEvent('list.extendQuery', function ($query) { $this->controller->relationExtendQuery($query, $this->field, $this->manageMode); - + $this->relationObject->setQuery($query); if ($this->model->exists) { $this->relationObject->addConstraints();