Switch the manage popup title according to the button pressed

Fixes #1755
This commit is contained in:
Samuel Georges 2016-03-25 14:03:11 +11:00
parent 4fe6cc6509
commit 762c5e754b
6 changed files with 45 additions and 8 deletions

View File

@ -130,6 +130,11 @@ class RelationController extends ControllerBehavior
*/
protected $viewMode;
/**
* @var string The title used for the manage popup.
*/
protected $manageTitle;
/**
* @var string Management of relation as list, form, or pivot.
*/
@ -220,6 +225,7 @@ class RelationController extends ControllerBehavior
{
$this->vars['relationManageId'] = $this->manageId;
$this->vars['relationLabel'] = $this->config->label ?: $this->field;
$this->vars['relationManageTitle'] = $this->manageTitle;
$this->vars['relationField'] = $this->field;
$this->vars['relationType'] = $this->relationType;
$this->vars['relationSearchWidget'] = $this->searchWidget;
@ -309,6 +315,7 @@ class RelationController extends ControllerBehavior
$this->toolbarButtons = $this->evalToolbarButtons();
$this->viewMode = $this->evalViewMode();
$this->manageMode = $this->evalManageMode();
$this->manageTitle = $this->evalManageTitle();
$this->manageId = post('manage_id');
$this->foreignId = post('foreign_id');
@ -1315,6 +1322,39 @@ class RelationController extends ControllerBehavior
}
}
/**
* Determine the management mode popup title.
* @return string
*/
protected function evalManageTitle()
{
if ($customTitle = $this->getConfig('manage[title]')) {
return $customTitle;
}
switch ($this->manageMode) {
case 'list':
if ($this->eventTarget == 'button-link') {
return 'backend::lang.relation.add_a_link';
}
else {
return 'backend::lang.relation.add_a_new';
}
break;
case 'form':
if ($this->readOnly) {
return 'backend::lang.relation.preview_name';
}
else {
return 'backend::lang.relation.update_name';
}
break;
case 'pivot':
return 'backend::lang.relation.add_a_new';
break;
}
}
/**
* Determine the management mode based on the relation type and settings.
* @return string

View File

@ -18,7 +18,7 @@ use Backend\Models\UserPreferences;
*/
class UserPreferencesModel extends SettingsModel
{
private static $instances = [];
protected static $instances = [];
/**
* Constructor

View File

@ -12,11 +12,7 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="popup">&times;</button>
<h4 class="modal-title">
<?php if ($this->readOnly): ?>
<?= e(trans('backend::lang.relation.preview_name', ['name' => trans($relationLabel)])) ?>
<?php else: ?>
<?= e(trans('backend::lang.relation.update_name', ['name' => trans($relationLabel)])) ?>
<?php endif ?>
<?= e(trans($relationManageTitle, ['name' => trans($relationLabel)])) ?>
</h4>
</div>

View File

@ -2,7 +2,7 @@
<?= Form::open() ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="popup">&times;</button>
<h4 class="modal-title"><?= e(trans('backend::lang.relation.add_a_new', [
<h4 class="modal-title"><?= e(trans($relationManageTitle, [
'name' => trans($relationLabel)
])) ?></h4>
</div>

View File

@ -2,7 +2,7 @@
<?= Form::open() ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="popup">&times;</button>
<h4 class="modal-title"><?= e(trans('backend::lang.relation.add_a_new', ['name'=>trans($relationLabel)])) ?></h4>
<h4 class="modal-title"><?= e(trans($relationManageTitle, ['name'=>trans($relationLabel)])) ?></h4>
</div>
<?php if (!$relationSearchWidget): ?>
<div class="modal-body">

View File

@ -228,6 +228,7 @@ return [
'add' => 'Add',
'add_selected' => 'Add selected',
'add_a_new' => 'Add a new :name',
'add_a_link' => 'Link a new :name',
'link_selected' => 'Link selected',
'link_a_new' => 'Link a new :name',
'cancel' => 'Cancel',