Support for overriding list views

For consistency, entry partial for controller behaviors should be called "container"
Added addViewPath() method to ViewMaker
Remove "fa" from icon docs (not necessary)
Fixes #2439
This commit is contained in:
Samuel Georges 2016-10-29 14:10:21 +11:00
parent 788f109361
commit 57b10704ce
9 changed files with 57 additions and 44 deletions

View File

@ -273,7 +273,7 @@ class ImportExportController extends ControllerBehavior
public function importRender()
{
return $this->importExportMakePartial('import');
return $this->importExportMakePartial('container_import');
}
public function importGetModel()
@ -456,7 +456,7 @@ class ImportExportController extends ControllerBehavior
public function exportRender()
{
return $this->importExportMakePartial('export');
return $this->importExportMakePartial('container_export');
}
public function exportGetModel()

View File

@ -137,6 +137,7 @@ class ListController extends ControllerBehavior
'showCheckboxes',
'showTree',
'treeExpanded',
'customViewPath',
];
foreach ($configFieldsToTransfer as $field) {
@ -342,18 +343,8 @@ class ListController extends ControllerBehavior
'toolbar' => null,
'filter' => null,
'list' => null,
'topPartial' => null,
'sidePartial' => null
];
if (isset($listConfig->topPartial)) {
$vars['topPartial'] = $listConfig->topPartial;
}
if (isset($listConfig->sidePartial)) {
$vars['sidePartial'] = $listConfig->sidePartial;
}
if (isset($this->toolbarWidgets[$definition])) {
$vars['toolbar'] = $this->toolbarWidgets[$definition];
}
@ -364,7 +355,23 @@ class ListController extends ControllerBehavior
$vars['list'] = $this->listWidgets[$definition];
return $this->makePartial('list', $vars);
return $this->listMakePartial('container', $vars);
}
/**
* Controller accessor for making partials within this behavior.
* @param string $partial
* @param array $params
* @return string Partial contents
*/
public function listMakePartial($partial, $params = [])
{
$contents = $this->controller->makePartial('list_'.$partial, $params + $this->vars, false);
if (!$contents) {
$contents = $this->makePartial($partial, $params);
}
return $contents;
}
/**

View File

@ -0,0 +1,9 @@
<?php if ($toolbar): ?>
<?= $toolbar->render() ?>
<?php endif ?>
<?php if ($filter): ?>
<?= $filter->render() ?>
<?php endif ?>
<?= $list->render() ?>

View File

@ -1,24 +0,0 @@
<?php if ($toolbar): ?>
<?= $toolbar->render() ?>
<?php endif ?>
<?php if ($filter): ?>
<?= $filter->render() ?>
<?php endif ?>
<?php if ($topPartial): ?>
<?= $this->makePartial($topPartial) ?>
<?php endif ?>
<?php if ($sidePartial): ?>
<div class="row row-flush">
<div class="col-sm-3">
<?= $this->makePartial($sidePartial) ?>
</div>
<div class="col-sm-9 list-with-sidebar">
<?= $list->render() ?>
</div>
</div>
<?php else: ?>
<?= $list->render() ?>
<?php endif ?>

View File

@ -97,6 +97,11 @@ class Lists extends WidgetBase
*/
public $showPagination = 'auto';
/**
* @var string Specify a custom view path to override partials used by the list.
*/
public $customViewPath;
//
// Object properties
//
@ -194,6 +199,7 @@ class Lists extends WidgetBase
'showTree',
'treeExpanded',
'showPagination',
'customViewPath',
]);
/*
@ -205,6 +211,10 @@ class Lists extends WidgetBase
$this->showPagination = $this->recordsPerPage && $this->recordsPerPage > 0;
}
if ($this->customViewPath) {
$this->addViewPath($this->customViewPath);
}
$this->validateModel();
$this->validateTree();
}

View File

@ -22,11 +22,11 @@ Place icons just about anywhere with the `<i>` tag or to an existing element usi
To increase icon sizes relative to their container, use the `icon-lg` (33% increase), `icon-2x`, `icon-3x`, `icon-4x`, or `icon-5x` classes.
<i class="fa icon-camera-retro icon-5x"></i> icon-5x
<i class="fa icon-camera-retro icon-4x"></i> icon-4x
<i class="fa icon-camera-retro icon-3x"></i> icon-3x
<i class="fa icon-camera-retro icon-2x"></i> icon-2x
<i class="fa icon-camera-retro icon-lg"></i> icon-lg
<i class="icon-camera-retro icon-5x"></i> icon-5x
<i class="icon-camera-retro icon-4x"></i> icon-4x
<i class="icon-camera-retro icon-3x"></i> icon-3x
<i class="icon-camera-retro icon-2x"></i> icon-2x
<i class="icon-camera-retro icon-lg"></i> icon-lg
### Icon buttons

View File

@ -44,6 +44,17 @@ trait ViewMaker
*/
public $suppressLayout = false;
/**
* Prepends a path on the available view locations.
* @param string $path
* @return void
*/
public function addViewPath($path)
{
$this->viewPath = (array) $this->viewPath;
array_unshift($this->viewPath, $path);
}
/**
* Render a partial file contents located in the views folder.
* @param string $partial The view to load.