Removes non functional buttons in pivot mode

Refs https://github.com/daftspunk/oc-test-plugin/issues/28
This commit is contained in:
Samuel Georges 2017-12-06 17:19:37 +11:00
parent da9369bb14
commit 2036823eee
1 changed files with 26 additions and 8 deletions

View File

@ -341,10 +341,10 @@ class RelationController extends ControllerBehavior
$this->foreignId = post('foreign_id'); $this->foreignId = post('foreign_id');
$this->readOnly = $this->getConfig('readOnly'); $this->readOnly = $this->getConfig('readOnly');
$this->deferredBinding = $this->getConfig('deferredBinding') || !$this->model->exists; $this->deferredBinding = $this->getConfig('deferredBinding') || !$this->model->exists;
$this->toolbarButtons = $this->evalToolbarButtons();
$this->viewMode = $this->evalViewMode(); $this->viewMode = $this->evalViewMode();
$this->manageMode = $this->evalManageMode(); $this->manageMode = $this->evalManageMode();
$this->manageTitle = $this->evalManageTitle(); $this->manageTitle = $this->evalManageTitle();
$this->toolbarButtons = $this->evalToolbarButtons();
/* /*
* Toolbar widget * Toolbar widget
@ -916,12 +916,14 @@ class RelationController extends ControllerBehavior
public function onRelationButtonAdd() public function onRelationButtonAdd()
{ {
$this->eventTarget = 'button-add'; $this->eventTarget = 'button-add';
return $this->onRelationManageForm(); return $this->onRelationManageForm();
} }
public function onRelationButtonCreate() public function onRelationButtonCreate()
{ {
$this->eventTarget = 'button-create'; $this->eventTarget = 'button-create';
return $this->onRelationManageForm(); return $this->onRelationManageForm();
} }
@ -933,6 +935,7 @@ class RelationController extends ControllerBehavior
public function onRelationButtonLink() public function onRelationButtonLink()
{ {
$this->eventTarget = 'button-link'; $this->eventTarget = 'button-link';
return $this->onRelationManageForm(); return $this->onRelationManageForm();
} }
@ -949,6 +952,7 @@ class RelationController extends ControllerBehavior
public function onRelationButtonUpdate() public function onRelationButtonUpdate()
{ {
$this->eventTarget = 'button-update'; $this->eventTarget = 'button-update';
return $this->onRelationManageForm(); return $this->onRelationManageForm();
} }
@ -988,6 +992,7 @@ class RelationController extends ControllerBehavior
$this->vars['newSessionKey'] = str_random(40); $this->vars['newSessionKey'] = str_random(40);
$view = 'manage_' . $this->manageMode; $view = 'manage_' . $this->manageMode;
return $this->relationMakePartial($view); return $this->relationMakePartial($view);
} }
@ -1233,6 +1238,7 @@ class RelationController extends ControllerBehavior
$this->beforeAjax(); $this->beforeAjax();
$this->vars['foreignId'] = $this->foreignId ?: post('checked'); $this->vars['foreignId'] = $this->foreignId ?: post('checked');
return $this->relationMakePartial('pivot_form'); return $this->relationMakePartial('pivot_form');
} }
@ -1382,6 +1388,10 @@ class RelationController extends ControllerBehavior
return $buttons; return $buttons;
} }
if ($this->manageMode == 'pivot') {
return ['add', 'remove'];
}
switch ($this->relationType) { switch ($this->relationType) {
case 'hasMany': case 'hasMany':
case 'morphMany': case 'morphMany':
@ -1441,7 +1451,6 @@ class RelationController extends ControllerBehavior
else { else {
return 'backend::lang.relation.add_a_new'; return 'backend::lang.relation.add_a_new';
} }
break;
case 'form': case 'form':
if ($this->readOnly) { if ($this->readOnly) {
return 'backend::lang.relation.preview_name'; return 'backend::lang.relation.preview_name';
@ -1452,7 +1461,6 @@ class RelationController extends ControllerBehavior
else { else {
return 'backend::lang.relation.create_name'; return 'backend::lang.relation.create_name';
} }
break;
} }
} }
@ -1486,16 +1494,26 @@ class RelationController extends ControllerBehavior
case 'morphToMany': case 'morphToMany':
case 'morphedByMany': case 'morphedByMany':
case 'belongsToMany': case 'belongsToMany':
if (isset($this->config->pivot)) return 'pivot'; if (isset($this->config->pivot)) {
elseif ($this->eventTarget == 'list') return 'form'; return 'pivot';
else return 'list'; }
elseif ($this->eventTarget == 'list') {
return 'form';
}
else {
return 'list';
}
case 'hasOne': case 'hasOne':
case 'morphOne': case 'morphOne':
case 'hasMany': case 'hasMany':
case 'morphMany': case 'morphMany':
if ($this->eventTarget == 'button-add') return 'list'; if ($this->eventTarget == 'button-add') {
else return 'form'; return 'list';
}
else {
return 'form';
}
} }
} }