Move task edit form to the task layout

This commit is contained in:
Frédéric Guillot
2014-09-23 20:16:07 +02:00
parent dd7579e5a8
commit a5337cfe5c
6 changed files with 95 additions and 73 deletions

View File

@@ -160,6 +160,7 @@ class Task extends Base
} }
$task['score'] = $task['score'] ?: ''; $task['score'] = $task['score'] ?: '';
$ajax = $this->request->isAjax();
$params = array( $params = array(
'values' => $task, 'values' => $task,
@@ -168,15 +169,16 @@ class Task extends Base
'users_list' => $this->projectPermission->getUsersList($task['project_id']), 'users_list' => $this->projectPermission->getUsersList($task['project_id']),
'colors_list' => $this->color->getList(), 'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($task['project_id']), 'categories_list' => $this->category->getList($task['project_id']),
'ajax' => $this->request->isAjax(), 'ajax' => $ajax,
'menu' => 'tasks', 'menu' => 'tasks',
'title' => t('Edit a task') 'title' => t('Edit a task')
); );
if ($this->request->isAjax()) {
if ($ajax) {
$this->response->html($this->template->load('task_edit', $params)); $this->response->html($this->template->load('task_edit', $params));
} }
else { else {
$this->response->html($this->template->layout('task_edit', $params)); $this->response->html($this->taskLayout('task_edit', $params));
} }
} }
@@ -209,7 +211,7 @@ class Task extends Base
} }
} }
$this->response->html($this->template->layout('task_edit', array( $this->response->html($this->taskLayout('task_edit', array(
'values' => $values, 'values' => $values,
'errors' => $errors, 'errors' => $errors,
'task' => $task, 'task' => $task,
@@ -218,7 +220,8 @@ class Task extends Base
'colors_list' => $this->color->getList(), 'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($values['project_id']), 'categories_list' => $this->category->getList($values['project_id']),
'menu' => 'tasks', 'menu' => 'tasks',
'title' => t('Edit a task') 'title' => t('Edit a task'),
'ajax' => $this->request->isAjax(),
))); )));
} }

View File

@@ -8,8 +8,8 @@ namespace Core;
* @package core * @package core
* @author Frederic Guillot * @author Frederic Guillot
*/ */
interface Listener { interface Listener
{
/** /**
* Execute the listener * Execute the listener
* *

View File

@@ -79,13 +79,35 @@ class TaskValidator extends Base
} }
/** /**
* Validate task modification * Validate task modification (form)
* *
* @access public * @access public
* @param array $values Form values * @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors * @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/ */
public function validateModification(array $values) public function validateModification(array $values)
{
$rules = array(
new Validators\Required('id', t('The id is required')),
new Validators\Required('title', t('The title is required')),
);
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
return array(
$v->execute(),
$v->getErrors()
);
}
/**
* Validate task modification (Api)
*
* @access public
* @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
public function validateApiModification(array $values)
{ {
$rules = array( $rules = array(
new Validators\Required('id', t('The id is required')), new Validators\Required('id', t('The id is required')),

View File

@@ -1,14 +1,8 @@
<section id="main"> <div class="page-header">
<div class="page-header">
<h2><?= t('Edit a task') ?></h2> <h2><?= t('Edit a task') ?></h2>
<?php if (! $ajax): ?> </div>
<ul> <section id="task-section">
<li><a href="?controller=board&amp;action=show&amp;project_id=<?= $task['project_id'] ?>"><?= t('Back to the board') ?></a></li> <form method="post" action="?controller=task&amp;action=update&amp;task_id=<?= $task['id'] ?>&amp;ajax=<?= $ajax ?>" autocomplete="off">
</ul>
<?php endif ?>
</div>
<section id="task-section">
<form method="post" action="?controller=task&amp;action=update&amp;task_id=<?= $task['id'] ?>&amp;ajax=<?= $ajax ?>" autocomplete="off">
<?= Helper\form_csrf() ?> <?= Helper\form_csrf() ?>
@@ -53,6 +47,5 @@
<a href="?controller=task&amp;action=show&amp;task_id=<?= $task['id'] ?>"><?= t('cancel') ?></a> <a href="?controller=task&amp;action=show&amp;task_id=<?= $task['id'] ?>"><?= t('cancel') ?></a>
<?php endif ?> <?php endif ?>
</div> </div>
</form> </form>
</section>
</section> </section>

View File

@@ -222,6 +222,10 @@ textarea.form-error {
list-style-type: none; list-style-type: none;
} }
ul.form-errors li {
margin-left: 0;
}
.form-help { .form-help {
font-size: 0.8em; font-size: 0.8em;
color: brown; color: brown;

View File

@@ -211,7 +211,7 @@ $server->register('updateTask', function($id, $title = null, $project_id = null,
} }
} }
list($valid) = $taskValidator->validateModification($values); list($valid) = $taskValidator->validateApiModification($values);
return $valid && $task->update($values); return $valid && $task->update($values);
}); });