Remove some code duplication

This commit is contained in:
Frédéric Guillot
2014-11-26 21:30:21 -05:00
parent 3ba8e06632
commit 52b9899fc5
2 changed files with 9 additions and 20 deletions

View File

@@ -34,14 +34,14 @@ class Category extends Base
* *
* @access public * @access public
*/ */
public function index() public function index(array $values = array(), array $errors = array())
{ {
$project = $this->getProjectManagement(); $project = $this->getProjectManagement();
$this->response->html($this->projectLayout('category/index', array( $this->response->html($this->projectLayout('category/index', array(
'categories' => $this->category->getList($project['id'], false), 'categories' => $this->category->getList($project['id'], false),
'values' => array('project_id' => $project['id']), 'values' => $values + array('project_id' => $project['id']),
'errors' => array(), 'errors' => $errors,
'project' => $project, 'project' => $project,
'title' => t('Categories') 'title' => t('Categories')
))); )));
@@ -70,13 +70,7 @@ class Category extends Base
} }
} }
$this->response->html($this->projectLayout('category/index', array( $this->index($values, $errors);
'categories' => $this->category->getList($project['id'], false),
'values' => $values,
'errors' => $errors,
'project' => $project,
'title' => t('Categories')
)));
} }
/** /**
@@ -84,14 +78,14 @@ class Category extends Base
* *
* @access public * @access public
*/ */
public function edit() public function edit(array $values = array(), array $errors = array())
{ {
$project = $this->getProjectManagement(); $project = $this->getProjectManagement();
$category = $this->getCategory($project['id']); $category = $this->getCategory($project['id']);
$this->response->html($this->projectLayout('category/edit', array( $this->response->html($this->projectLayout('category/edit', array(
'values' => $category, 'values' => empty($values) ? $category : $values,
'errors' => array(), 'errors' => $errors,
'project' => $project, 'project' => $project,
'title' => t('Categories') 'title' => t('Categories')
))); )));
@@ -120,12 +114,7 @@ class Category extends Base
} }
} }
$this->response->html($this->projectLayout('category/edit', array( $this->edit($values, $errors);
'values' => $values,
'errors' => $errors,
'project' => $project,
'title' => t('Categories')
)));
} }
/** /**

View File

@@ -2,7 +2,7 @@
<h2><?= t('Category modification for the project "%s"', $project['name']) ?></h2> <h2><?= t('Category modification for the project "%s"', $project['name']) ?></h2>
</div> </div>
<form method="post" action="<?= Helper\u('category', 'update', array('project_id' => $project['id'])) ?>" autocomplete="off"> <form method="post" action="<?= Helper\u('category', 'update', array('project_id' => $project['id'], 'category_id' => $values['id'])) ?>" autocomplete="off">
<?= Helper\form_csrf() ?> <?= Helper\form_csrf() ?>