Add styles and readonly mode to relation controller

This commit is contained in:
Sam Georges 2014-06-30 20:01:22 +10:00
parent 2574760210
commit 3a275216e2
4 changed files with 103 additions and 18 deletions

View File

@ -118,6 +118,11 @@ class RelationController extends ControllerBehavior
*/
public $sessionKey;
/**
* @var bool Disables the ability to add, update, delete or create relations.
*/
public $readOnly = false;
/**
* Behavior constructor
* @param Backend\Classes\Controller $controller
@ -128,6 +133,7 @@ class RelationController extends ControllerBehavior
parent::__construct($controller);
$this->addJs('js/october.relation.js', 'core');
$this->addCss('css/relation.css', 'core');
/*
* Build configuration
@ -171,6 +177,7 @@ class RelationController extends ControllerBehavior
$this->relationObject = $this->model->{$field}();
$this->relationModel = $this->relationObject->getRelated();
$this->readOnly = $this->getConfig('readOnly');
$this->viewMode = $this->evalViewMode();
$this->manageMode = $this->evalManageMode();
$this->manageId = post('manage_id');
@ -178,27 +185,27 @@ class RelationController extends ControllerBehavior
/*
* Toolbar widget
*/
$this->toolbarWidget = $this->makeToolbarWidget();
$this->toolbarWidget->bindToController();
if ($this->toolbarWidget = $this->makeToolbarWidget())
$this->toolbarWidget->bindToController();
/*
* View widget
*/
$this->viewWidget = $this->makeViewWidget();
$this->viewWidget->bindToController();
if ($this->viewWidget = $this->makeViewWidget())
$this->viewWidget->bindToController();
/*
* Manage widget
*/
$this->manageWidget = $this->makeManageWidget();
$this->manageWidget->bindToController();
if ($this->manageWidget = $this->makeManageWidget())
$this->manageWidget->bindToController();
/*
* Pivot widget
*/
if ($this->manageMode == 'pivot') {
$this->pivotWidget = $this->makePivotWidget();
$this->pivotWidget->bindToController();
if ($this->pivotWidget = $this->makePivotWidget())
$this->pivotWidget->bindToController();
}
$this->initialized = true;
@ -268,7 +275,7 @@ class RelationController extends ControllerBehavior
$section = (isset($options['section'])) ? $options['section'] : null;
switch (strtolower($section)) {
case 'toolbar':
return $this->toolbarWidget->render();
return $this->toolbarWidget ? $this->toolbarWidget->render() : null;
case 'view':
return $this->relationMakePartial('view');
@ -537,6 +544,9 @@ class RelationController extends ControllerBehavior
protected function makeToolbarWidget()
{
if ($this->readOnly)
return;
$defaultConfig = [
'buttons' => '@/modules/backend/behaviors/relationcontroller/partials/_toolbar.htm',
];
@ -544,6 +554,7 @@ class RelationController extends ControllerBehavior
$toolbarConfig->alias = $this->alias . 'Toolbar';
$toolbarWidget = $this->makeWidget('Backend\Widgets\Toolbar', $toolbarConfig);
$toolbarWidget->cssClasses[] = 'list-header';
return $toolbarWidget;
}
@ -591,10 +602,11 @@ class RelationController extends ControllerBehavior
protected function makeManageWidget()
{
$widget = null;
/*
* Pivot
*/
if ($this->manageMode == 'pivot') {
if ($this->manageMode == 'pivot' && isset($this->config->list)) {
$config = $this->makeConfig($this->config->list);
$config->model = $this->relationModel;
$config->alias = $this->alias . 'ManagePivotList';
@ -605,7 +617,7 @@ class RelationController extends ControllerBehavior
/*
* List
*/
elseif ($this->manageMode == 'list') {
elseif ($this->manageMode == 'list' && isset($this->config->list)) {
$config = $this->makeConfig($this->config->list);
$config->model = $this->relationModel;
$config->alias = $this->alias . 'ManageList';
@ -616,7 +628,7 @@ class RelationController extends ControllerBehavior
/*
* Form
*/
elseif ($this->manageMode == 'form') {
elseif ($this->manageMode == 'form' && isset($this->config->form)) {
$config = $this->makeConfig($this->config->form);
$config->model = $this->relationModel;
$config->arrayName = Str::getRealClass($this->relationModel);
@ -638,6 +650,9 @@ class RelationController extends ControllerBehavior
$widget = $this->makeWidget('Backend\Widgets\Form', $config);
}
if (!$widget)
return null;
/*
* Exclude existing relationships
*/

View File

@ -0,0 +1,22 @@
.relation-behavior {
padding: 0;
margin-bottom: 20px;
background: white;
background: #ffffff;
border: 1px solid #dddddd;
}
.relation-behavior .list-header:first-child {
padding-top: 20px;
}
.relation-behavior .control-list:last-child > table {
margin-bottom: 0;
}
.relation-flush .relation-behavior {
border-top: 0;
}
.relation-flush .relation-behavior .relation-manager table.table.data thead tr th {
border-top: none !important;
}
.relation-flush .relation-behavior .relation-toolbar + .relation-manager table.table.data thead tr th {
border-top: 1px solid #e2e2e2 !important;
}

View File

@ -0,0 +1,44 @@
@import "../../../../assets/less/core/boot.less";
@color-relation-bg: #fff;
@color-relation-border: #ddd;
.relation-behavior {
padding: 0;
margin-bottom: 20px;
background: white;
background: @color-relation-bg;
border: 1px solid @color-relation-border;
.list-header:first-child {
padding-top: 20px;
}
.control-list:last-child > table {
margin-bottom: 0;
}
}
// Relation manager to sit flush to the element above
.relation-flush {
.relation-behavior {
border-top: 0;
.relation-manager {
table.table.data {
thead tr th {
border-top: none !important;
}
}
}
.relation-toolbar + .relation-manager {
table.table.data {
thead tr th {
border-top: 1px solid @color-list-border !important;
}
}
}
}
}

View File

@ -1,12 +1,16 @@
<div data-request-data="_relation_field: '<?= $relationField ?>'" id="<?= $this->relationGetId() ?>">
<div
data-request-data="_relation_field: '<?= $relationField ?>'" id="<?= $this->relationGetId() ?>"
class="relation-behavior">
<!-- Relation Toolbar -->
<div id="<?= $this->relationGetId('toolbar') ?>">
<?= $this->relationRenderToolbar() ?>
</div>
<?php if ($toolbar = $this->relationRenderToolbar()): ?>
<!-- Relation Toolbar -->
<div id="<?= $this->relationGetId('toolbar') ?>" class="relation-toolbar">
<?= $toolbar ?>
</div>
<?php endif ?>
<!-- Relation View -->
<div id="<?= $this->relationGetId('view') ?>">
<div id="<?= $this->relationGetId('view') ?>" class="relation-manager">
<?= $this->relationRenderView() ?>
</div>