Add custom role edition
This commit is contained in:
parent
7399c3c596
commit
0e055eabe1
|
|
@ -69,6 +69,55 @@ class ProjectRoleController extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show form to change existing role
|
||||
*
|
||||
* @param array $values
|
||||
* @param array $errors
|
||||
* @throws AccessForbiddenException
|
||||
*/
|
||||
public function edit(array $values = array(), array $errors = array())
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$role = $this->getRole($project['id']);
|
||||
|
||||
if (empty($values)) {
|
||||
$values = $role;
|
||||
}
|
||||
|
||||
$this->response->html($this->template->render('project_role/edit', array(
|
||||
'role' => $role,
|
||||
'project' => $project,
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update role
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$role = $this->getRole($project['id']);
|
||||
|
||||
$values = $this->request->getValues();
|
||||
|
||||
list($valid, $errors) = $this->projectRoleValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->projectRoleModel->update($role['role_id'], $project['id'], $values['role'])) {
|
||||
$this->flash->success(t('Your custom project role has been updated successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to update custom project role.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectRoleController', 'show', array('project_id' => $project['id'])));
|
||||
} else {
|
||||
$this->edit($values, $errors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm suppression
|
||||
*
|
||||
|
|
@ -77,11 +126,11 @@ class ProjectRoleController extends BaseController
|
|||
public function confirm()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$role_id = $this->request->getIntegerParam('role_id');
|
||||
$role = $this->getRole($project['id']);
|
||||
|
||||
$this->response->html($this->helper->layout->project('project_role/remove', array(
|
||||
'project' => $project,
|
||||
'role' => $this->projectRoleModel->getById($project['id'], $role_id),
|
||||
'role' => $role,
|
||||
)));
|
||||
}
|
||||
|
||||
|
|
@ -104,4 +153,10 @@ class ProjectRoleController extends BaseController
|
|||
|
||||
$this->response->redirect($this->helper->url->to('ProjectRoleController', 'show', array('project_id' => $project['id'])));
|
||||
}
|
||||
|
||||
protected function getRole($project_id)
|
||||
{
|
||||
$role_id = $this->request->getIntegerParam('role_id');
|
||||
return $this->projectRoleModel->getById($project_id, $role_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
<section id="main">
|
||||
<div class="page-header">
|
||||
<h2><?= t('New custom project role') ?></h2>
|
||||
<div class="page-header">
|
||||
<h2><?= t('New custom project role') ?></h2>
|
||||
</div>
|
||||
<form class="popover-form" method="post" action="<?= $this->url->href('ProjectRoleController', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off">
|
||||
<?= $this->form->csrf() ?>
|
||||
<?= $this->form->hidden('project_id', $values) ?>
|
||||
|
||||
<?= $this->form->label(t('Role'), 'role') ?>
|
||||
<?= $this->form->text('role', $values, $errors, array('autofocus', 'required', 'maxlength="50"')) ?>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
|
||||
<?= t('or') ?>
|
||||
<?= $this->url->link(t('cancel'), 'ProjectRoleController', 'show', array(), false, 'close-popover') ?>
|
||||
</div>
|
||||
<form class="popover-form" method="post" action="<?= $this->url->href('ProjectRoleController', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off">
|
||||
<?= $this->form->csrf() ?>
|
||||
<?= $this->form->hidden('project_id', $values) ?>
|
||||
|
||||
<?= $this->form->label(t('Role'), 'role') ?>
|
||||
<?= $this->form->text('role', $values, $errors, array('autofocus', 'required', 'maxlength="50"')) ?>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
|
||||
<?= t('or') ?>
|
||||
<?= $this->url->link(t('cancel'), 'ProjectRoleController', 'show', array(), false, 'close-popover') ?>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<div class="page-header">
|
||||
<h2><?= t('Edit custom project role') ?></h2>
|
||||
</div>
|
||||
<form class="popover-form" method="post" action="<?= $this->url->href('ProjectRoleController', 'update', array('project_id' => $project['id'], 'role_id' => $role['role_id'])) ?>" autocomplete="off">
|
||||
<?= $this->form->csrf() ?>
|
||||
<?= $this->form->hidden('project_id', $values) ?>
|
||||
<?= $this->form->hidden('role_id', $values) ?>
|
||||
|
||||
<?= $this->form->label(t('Role'), 'role') ?>
|
||||
<?= $this->form->text('role', $values, $errors, array('autofocus', 'required', 'maxlength="50"')) ?>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
|
||||
<?= t('or') ?>
|
||||
<?= $this->url->link(t('cancel'), 'ProjectRoleController', 'show', array(), false, 'close-popover') ?>
|
||||
</div>
|
||||
</form>
|
||||
|
|
@ -26,6 +26,10 @@
|
|||
<i class="fa fa-plus fa-fw" aria-hidden="true"></i>
|
||||
<?= $this->url->link(t('Add a new column restriction'), 'ColumnMoveRestrictionController', 'create', array('project_id' => $project['id'], 'role_id' => $role['role_id']), false, 'popover') ?>
|
||||
</li>
|
||||
<li>
|
||||
<i class="fa fa-pencil fa-fw" aria-hidden="true"></i>
|
||||
<?= $this->url->link(t('Edit this role'), 'ProjectRoleController', 'edit', array('project_id' => $project['id'], 'role_id' => $role['role_id']), false, 'popover') ?>
|
||||
</li>
|
||||
<li>
|
||||
<i class="fa fa-trash-o fa-fw" aria-hidden="true"></i>
|
||||
<?= $this->url->link(t('Remove this role'), 'ProjectRoleController', 'confirm', array('project_id' => $project['id'], 'role_id' => $role['role_id']), false, 'popover') ?>
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class ProjectRoleValidator extends BaseValidator
|
|||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('The id is required')),
|
||||
new Validators\Required('role_id', t('The id is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
|
@ -64,7 +64,7 @@ class ProjectRoleValidator extends BaseValidator
|
|||
new Validators\MaxLength('role', t('The maximum length is %d characters', 100), 100),
|
||||
new Validators\Required('project_id', t('This field is required')),
|
||||
new Validators\Integer('project_id', t('This value must be an integer')),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
new Validators\Integer('role_id', t('This value must be an integer')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue