Improve form helpers and add more hooks

This commit is contained in:
Frederic Guillot 2016-08-13 17:49:27 -04:00
parent 4ffaba2ba0
commit ffe61abc69
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
11 changed files with 70 additions and 42 deletions

View File

@ -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;
}
}

View File

@ -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()),

View File

@ -306,6 +306,48 @@ class FormHelper extends Base
return $this->input('text', $name, $values, $errors, $attributes, $class.' form-numeric');
}
/**
* 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
*

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);
}
/**

View File

@ -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)) ?>

View File

@ -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>

File diff suppressed because one or more lines are too long

View File

@ -26,16 +26,25 @@ input
outline: 0
box-shadow: 0 0 8px rgba(82, 168, 236, 0.6)
input[type="number"]
width: 70px
input[type="text"]:not(.input-addon-field)
&.form-numeric
width: 70px
&.form-datetime, &.form-date
width: 150px
&.form-input-large
width: 400px
&.form-input-small
width: 150px
textarea:focus
color: color('dark')
border-color: rgba(82, 168, 236, 0.8)
outline: 0
box-shadow: 0 0 8px rgba(82, 168, 236, 0.6)
input
&.form-numeric, &[type="number"]
width: 70px
textarea
border: 1px solid #ccc
width: 400px
@ -101,14 +110,6 @@ ul.form-errors li
.form-inline-group
display: inline
input
&.form-datetime, &.form-date
width: 150px
&.form-input-large
width: 400px
&.form-input-small
width: 150px
.form-columns
display: -webkit-flex
display: flex

View File

@ -138,6 +138,8 @@ List of reference hooks:
| `formatter:board:query` | Alter database query before rendering board |
| `pagination:dashboard:task:query` | Alter database query for tasks pagination on the dashboard |
| `pagination:dashboard:subtask:query` | Alter database query for subtasks pagination on the dashboard |
| `model:task:creation:prepare` | Alter form values before to save a task |
| `model:task:modification:prepare` | Alter form values before to edit a task |
Template Hooks
@ -186,6 +188,7 @@ List of template hooks:
| `template:config:email` | Email settings page |
| `template:config:integrations` | Integration page in global settings |
| `template:dashboard:sidebar` | Sidebar on dashboard page |
| `template:dashboard:show` | Main page of the dashboard |
| `template:export:sidebar` | Sidebar on export pages |
| `template:import:sidebar` | Sidebar on import pages |
| `template:header:dropdown` | Page header dropdown menu (user avatar icon) |