From d8e452d375493a70186866b876c0617bb3269e5f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jan 2016 11:50:28 -0500 Subject: Move task form elements to Task helper --- ChangeLog | 1 + app/Controller/Gantt.php | 3 +- app/Controller/Taskcreation.php | 2 - app/Helper/Task.php | 82 +++++++++++++++++++++++++++- app/Template/board/popover_category.php | 3 +- app/Template/gantt/task_creation.php | 27 +++------ app/Template/task_creation/form.php | 29 ++-------- app/Template/task_modification/edit_task.php | 15 +---- 8 files changed, 100 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 967117b0..8868d410 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ Improvements: * Have a new task assigned to the creator by default instead of "no assignee" * Show progress for task links in board tooltips * Simplify code to handle ajax popover and redirects +* Move task form elements to Task helper Version 1.0.24 -------------- diff --git a/app/Controller/Gantt.php b/app/Controller/Gantt.php index ac0e6fad..f312130c 100644 --- a/app/Controller/Gantt.php +++ b/app/Controller/Gantt.php @@ -103,6 +103,7 @@ class Gantt extends Base $project = $this->getProject(); $this->response->html($this->template->render('gantt/task_creation', array( + 'project' => $project, 'errors' => $errors, 'values' => $values + array( 'project_id' => $project['id'], @@ -113,8 +114,6 @@ class Gantt extends Base 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($project['id']), 'swimlanes_list' => $this->swimlane->getList($project['id'], false, true), - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), 'title' => $project['name'].' > '.t('New task') ))); } diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index ed2ac1b9..396d5f6f 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -38,8 +38,6 @@ class Taskcreation extends Base 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($project['id']), 'swimlanes_list' => $swimlanes_list, - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), 'title' => $project['name'].' > '.t('New task') ))); } diff --git a/app/Helper/Task.php b/app/Helper/Task.php index 06f7d58e..57ad6c91 100644 --- a/app/Helper/Task.php +++ b/app/Helper/Task.php @@ -51,7 +51,43 @@ class Task extends Base $html = $this->helper->form->label(t('Assignee'), 'owner_id'); $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); - $html .= ''.t('Me').''; + $html .= ' '.t('Me').''; + + return $html; + } + + public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + $html = ''; + + if (! (! $allow_one_item && count($categories) === 1 && key($categories) == 0)) { + $html .= $this->helper->form->label(t('Category'), 'category_id'); + $html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); + } + + return $html; + } + + public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="5"'), $attributes); + $html = ''; + + if (! (count($swimlanes) === 1 && key($swimlanes) == 0)) { + $html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); + $html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); + } + + return $html; + } + + public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="6"'), $attributes); + + $html = $this->helper->form->label(t('Column'), 'column_id'); + $html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); return $html; } @@ -72,6 +108,50 @@ class Task extends Base return $html; } + public function selectScore(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="8"'), $attributes); + + $html = $this->helper->form->label(t('Complexity'), 'score'); + $html .= $this->helper->form->number('score', $values, $errors, $attributes); + + return $html; + } + + public function selectTimeEstimate(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="9"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = $this->helper->text->in($this->config->get('application_date_format'), $this->dateParser->getAvailableFormats()); + $attributes = array_merge(array('tabindex="10"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Start Date'), 'date_started'); + $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-date'); + + return $html; + } + + public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = $this->helper->text->in($this->config->get('application_date_format'), $this->dateParser->getAvailableFormats()); + $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Due Date'), 'date_due'); + $html .= $this->helper->form->text('date_due', $values, $errors, $attributes, 'form-date'); + $html .= '
'.t('Others formats accepted: %s and %s', date('Y-m-d'), date('Y_m_d')).'
'; + + return $html; + } + public function formatPriority(array $project, array $task) { $html = ''; diff --git a/app/Template/board/popover_category.php b/app/Template/board/popover_category.php index 224ce8d1..e65593cd 100644 --- a/app/Template/board/popover_category.php +++ b/app/Template/board/popover_category.php @@ -9,8 +9,7 @@ form->hidden('id', $values) ?> form->hidden('project_id', $values) ?> - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, array(), array('autofocus')) ?>
+ task->selectCategory($categories_list, $values, array(), array('autofocus'), true) ?>
diff --git a/app/Template/gantt/task_creation.php b/app/Template/gantt/task_creation.php index 7997e231..a08f41b4 100644 --- a/app/Template/gantt/task_creation.php +++ b/app/Template/gantt/task_creation.php @@ -33,26 +33,13 @@
- form->label(t('Assignee'), 'owner_id') ?> - form->select('owner_id', $users_list, $values, $errors, array('tabindex="3"')) ?>
- - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, $errors, array('tabindex="4"')) ?>
- - - form->label(t('Swimlane'), 'swimlane_id') ?> - form->select('swimlane_id', $swimlanes_list, $values, $errors, array('tabindex="5"')) ?>
- - - form->label(t('Complexity'), 'score') ?> - form->number('score', $values, $errors, array('tabindex="6"')) ?>
- - form->label(t('Start Date'), 'date_started') ?> - form->text('date_started', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="7"'), 'form-date') ?> - - form->label(t('Due Date'), 'date_due') ?> - form->text('date_due', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="8"'), 'form-date') ?>
-
+ task->selectAssignee($users_list, $values, $errors) ?> + task->selectCategory($categories_list, $values, $errors) ?> + task->selectSwimlane($swimlanes_list, $values, $errors) ?> + task->selectPriority($project, $values) ?> + task->selectScore($values, $errors) ?> + task->selectStartDate($values, $errors) ?> + task->selectDueDate($values, $errors) ?>
diff --git a/app/Template/task_creation/form.php b/app/Template/task_creation/form.php index a814219b..b222f00f 100644 --- a/app/Template/task_creation/form.php +++ b/app/Template/task_creation/form.php @@ -47,31 +47,14 @@
form->hidden('project_id', $values) ?> - task->selectAssignee($users_list, $values, $errors) ?> - - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, $errors, array('tabindex="4"')) ?> - - - form->label(t('Swimlane'), 'swimlane_id') ?> - form->select('swimlane_id', $swimlanes_list, $values, $errors, array('tabindex="5"')) ?> - - - form->label(t('Column'), 'column_id') ?> - form->select('column_id', $columns_list, $values, $errors, array('tabindex="6"')) ?> - + task->selectCategory($categories_list, $values, $errors) ?> + task->selectSwimlane($swimlanes_list, $values, $errors) ?> + task->selectColumn($columns_list, $values, $errors) ?> task->selectPriority($project, $values) ?> - - form->label(t('Complexity'), 'score') ?> - form->number('score', $values, $errors, array('tabindex="9"')) ?> - - form->label(t('Original estimate'), 'time_estimated') ?> - form->numeric('time_estimated', $values, $errors, array('tabindex="10"')) ?> - - form->label(t('Due Date'), 'date_due') ?> - form->text('date_due', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="11"'), 'form-date') ?> -
+ task->selectScore($values, $errors) ?> + task->selectTimeEstimate($values, $errors) ?> + task->selectDueDate($values, $errors) ?>
diff --git a/app/Template/task_modification/edit_task.php b/app/Template/task_modification/edit_task.php index 1daa318c..fe7fb009 100644 --- a/app/Template/task_modification/edit_task.php +++ b/app/Template/task_modification/edit_task.php @@ -43,20 +43,11 @@
form->hidden('id', $values) ?> form->hidden('project_id', $values) ?> - task->selectAssignee($users_list, $values, $errors) ?> - - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, $errors, array('tabindex="4"')) ?> - - form->label(t('Complexity'), 'score') ?> - form->number('score', $values, $errors, array('tabindex="6"')) ?> - + task->selectCategory($categories_list, $values, $errors) ?> task->selectPriority($project, $values) ?> - - form->label(t('Due Date'), 'date_due') ?> - form->text('date_due', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="8"'), 'form-date') ?> -
+ task->selectScore($values, $errors) ?> + task->selectDueDate($values, $errors) ?>
-- cgit v1.2.3