diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-08-13 17:49:27 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-08-13 17:49:27 -0400 |
commit | ffe61abc6910670c5c2c243eb82d9f5851f06c6b (patch) | |
tree | 0a1833f8a7f22ac239f8914f2e870a881e630e41 /app | |
parent | 4ffaba2ba0dd6b5810adea1916080c3b645f3d29 (diff) |
Improve form helpers and add more hooks
Diffstat (limited to 'app')
-rw-r--r-- | app/Controller/TaskModificationController.php | 3 | ||||
-rw-r--r-- | app/Controller/TaskViewController.php | 11 | ||||
-rw-r--r-- | app/Helper/FormHelper.php | 42 | ||||
-rw-r--r-- | app/Helper/TaskHelper.php | 18 | ||||
-rw-r--r-- | app/Model/TaskCreationModel.php | 2 | ||||
-rw-r--r-- | app/Model/TaskModificationModel.php | 2 | ||||
-rw-r--r-- | app/Template/dashboard/show.php | 2 | ||||
-rw-r--r-- | app/Template/dashboard/sidebar.php | 2 |
8 files changed, 53 insertions, 29 deletions
diff --git a/app/Controller/TaskModificationController.php b/app/Controller/TaskModificationController.php index d37f4bb4..cbc3777a 100644 --- a/app/Controller/TaskModificationController.php +++ b/app/Controller/TaskModificationController.php @@ -84,9 +84,6 @@ class TaskModificationController extends BaseController $values = $task; $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); $values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values)); - $values = $this->dateParser->format($values, array('date_due'), $this->dateParser->getUserDateFormat()); - $values = $this->dateParser->format($values, array('date_started'), $this->dateParser->getUserDateTimeFormat()); - return $values; } } diff --git a/app/Controller/TaskViewController.php b/app/Controller/TaskViewController.php index f40f8bea..e40ebdc0 100644 --- a/app/Controller/TaskViewController.php +++ b/app/Controller/TaskViewController.php @@ -22,7 +22,6 @@ class TaskViewController extends BaseController { $project = $this->projectModel->getByToken($this->request->getStringParam('token')); - // Token verification if (empty($project)) { throw AccessForbiddenException::getInstance()->withoutLayout(); } @@ -63,19 +62,9 @@ class TaskViewController extends BaseController $task = $this->getTask(); $subtasks = $this->subtaskModel->getAll($task['id']); - $values = array( - 'id' => $task['id'], - 'date_started' => $task['date_started'], - 'time_estimated' => $task['time_estimated'] ?: '', - 'time_spent' => $task['time_spent'] ?: '', - ); - - $values = $this->dateParser->format($values, array('date_started'), $this->dateParser->getUserDateTimeFormat()); - $this->response->html($this->helper->layout->task('task/show', array( 'task' => $task, 'project' => $this->projectModel->getById($task['project_id']), - 'values' => $values, 'files' => $this->taskFileModel->getAllDocuments($task['id']), 'images' => $this->taskFileModel->getAllImages($task['id']), 'comments' => $this->commentModel->getAll($task['id'], $this->userSession->getCommentSorting()), diff --git a/app/Helper/FormHelper.php b/app/Helper/FormHelper.php index c2ea1d72..0bb94d39 100644 --- a/app/Helper/FormHelper.php +++ b/app/Helper/FormHelper.php @@ -307,6 +307,48 @@ class FormHelper extends Base } /** + * Date field + * + * @access public + * @param string $label + * @param string $name + * @param array $values + * @param array $errors + * @param array $attributes + * @return string + */ + public function date($label, $name, array $values, array $errors = array(), array $attributes = array()) + { + $userFormat = $this->dateParser->getUserDateFormat(); + $values = $this->dateParser->format($values, array($name), $userFormat); + $attributes = array_merge(array('placeholder="'.date($userFormat).'"'), $attributes); + + return $this->helper->form->label($label, $name) . + $this->helper->form->text($name, $values, $errors, $attributes, 'form-date'); + } + + /** + * Datetime field + * + * @access public + * @param string $label + * @param string $name + * @param array $values + * @param array $errors + * @param array $attributes + * @return string + */ + public function datetime($label, $name, array $values, array $errors = array(), array $attributes = array()) + { + $userFormat = $this->dateParser->getUserDateTimeFormat(); + $values = $this->dateParser->format($values, array($name), $userFormat); + $attributes = array_merge(array('placeholder="'.date($userFormat).'"'), $attributes); + + return $this->helper->form->label($label, $name) . + $this->helper->form->text($name, $values, $errors, $attributes, 'form-datetime'); + } + + /** * Display the form error class * * @access private diff --git a/app/Helper/TaskHelper.php b/app/Helper/TaskHelper.php index 599146b9..32f2a9ae 100644 --- a/app/Helper/TaskHelper.php +++ b/app/Helper/TaskHelper.php @@ -207,24 +207,14 @@ class TaskHelper extends Base public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) { - $placeholder = date($this->configModel->get('application_date_format', 'm/d/Y H:i')); - $attributes = array_merge(array('tabindex="12"', 'placeholder="'.$placeholder.'"'), $attributes); - - $html = $this->helper->form->label(t('Start Date'), 'date_started'); - $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-datetime'); - - return $html; + $attributes = array_merge(array('tabindex="12"'), $attributes); + return $this->helper->form->datetime(t('Start Date'), 'date_started', $values, $errors, $attributes); } public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) { - $placeholder = date($this->configModel->get('application_date_format', 'm/d/Y')); - $attributes = array_merge(array('tabindex="13"', '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'); - - return $html; + $attributes = array_merge(array('tabindex="13"'), $attributes); + return $this->helper->form->date(t('Due Date'), 'date_due', $values, $errors, $attributes); } public function formatPriority(array $project, array $task) diff --git a/app/Model/TaskCreationModel.php b/app/Model/TaskCreationModel.php index 1c0fd7d9..b9b07d5e 100644 --- a/app/Model/TaskCreationModel.php +++ b/app/Model/TaskCreationModel.php @@ -85,5 +85,7 @@ class TaskCreationModel extends Base $values['date_modification'] = $values['date_creation']; $values['date_moved'] = $values['date_creation']; $values['position'] = $this->taskFinderModel->countByColumnAndSwimlaneId($values['project_id'], $values['column_id'], $values['swimlane_id']) + 1; + + $this->hook->reference('model:task:creation:prepare', $values); } } diff --git a/app/Model/TaskModificationModel.php b/app/Model/TaskModificationModel.php index 16b48f3d..6e16fbec 100644 --- a/app/Model/TaskModificationModel.php +++ b/app/Model/TaskModificationModel.php @@ -106,6 +106,8 @@ class TaskModificationModel extends Base $this->helper->model->convertIntegerFields($values, array('priority', 'is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate')); $values['date_modification'] = time(); + + $this->hook->reference('model:task:modification:prepare', $values); } /** diff --git a/app/Template/dashboard/show.php b/app/Template/dashboard/show.php index cb18b79d..aec6f591 100644 --- a/app/Template/dashboard/show.php +++ b/app/Template/dashboard/show.php @@ -15,3 +15,5 @@ <?= $this->render('dashboard/projects', array('paginator' => $project_paginator, 'user' => $user)) ?> <?= $this->render('dashboard/tasks', array('paginator' => $task_paginator, 'user' => $user)) ?> <?= $this->render('dashboard/subtasks', array('paginator' => $subtask_paginator, 'user' => $user)) ?> + +<?= $this->hook->render('template:dashboard:show', array('user' => $user)) ?> diff --git a/app/Template/dashboard/sidebar.php b/app/Template/dashboard/sidebar.php index df4e91a5..108c028a 100644 --- a/app/Template/dashboard/sidebar.php +++ b/app/Template/dashboard/sidebar.php @@ -21,6 +21,6 @@ <li <?= $this->app->checkMenuSelection('DashboardController', 'notifications') ?>> <?= $this->url->link(t('My notifications'), 'DashboardController', 'notifications', array('user_id' => $user['id'])) ?> </li> - <?= $this->hook->render('template:dashboard:sidebar') ?> + <?= $this->hook->render('template:dashboard:sidebar', array('user' => $user)) ?> </ul> </div> |