Open form to create customer filters in modal box

This commit is contained in:
Frederic Guillot
2017-01-08 12:16:05 -05:00
parent bb222a79cd
commit e377f450ad
5 changed files with 72 additions and 57 deletions

View File

@@ -9,6 +9,7 @@ Improvements:
* Add helpers to open modal boxes * Add helpers to open modal boxes
* Make icons clickable in menus * Make icons clickable in menus
* Open task import in modal box * Open task import in modal box
* Open form to create customer filters in modal box
Version 1.0.36 (Dec 30, 2016) Version 1.0.36 (Dec 30, 2016)
----------------------------- -----------------------------

View File

@@ -18,23 +18,37 @@ class CustomFilterController extends BaseController
* Display list of filters * Display list of filters
* *
* @access public * @access public
* @param array $values
* @param array $errors
* @throws \Kanboard\Core\Controller\PageNotFoundException * @throws \Kanboard\Core\Controller\PageNotFoundException
*/ */
public function index(array $values = array(), array $errors = array()) public function index()
{ {
$project = $this->getProject(); $project = $this->getProject();
$this->response->html($this->helper->layout->project('custom_filter/index', array( $this->response->html($this->helper->layout->project('custom_filter/index', array(
'values' => $values + array('project_id' => $project['id']),
'errors' => $errors,
'project' => $project, 'project' => $project,
'custom_filters' => $this->customFilterModel->getAll($project['id'], $this->userSession->getId()), 'custom_filters' => $this->customFilterModel->getAll($project['id'], $this->userSession->getId()),
'title' => t('Custom filters'), 'title' => t('Custom filters'),
))); )));
} }
/**
* Show creation form for custom filters
*
* @access public
* @param array $values
* @param array $errors
*/
public function create(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$this->response->html($this->template->render('custom_filter/create', array(
'values' => $values + array('project_id' => $project['id']),
'errors' => $errors,
'project' => $project,
)));
}
/** /**
* Save a new custom filter * Save a new custom filter
* *
@@ -52,13 +66,14 @@ class CustomFilterController extends BaseController
if ($valid) { if ($valid) {
if ($this->customFilterModel->create($values) !== false) { if ($this->customFilterModel->create($values) !== false) {
$this->flash->success(t('Your custom filter have been created successfully.')); $this->flash->success(t('Your custom filter have been created successfully.'));
return $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id']))); $this->response->redirect($this->helper->url->to('CustomFilterController', 'index', array('project_id' => $project['id'])), true);
return;
} else { } else {
$this->flash->failure(t('Unable to create your custom filter.')); $this->flash->failure(t('Unable to create your custom filter.'));
} }
} }
return $this->index($values, $errors); $this->create($values, $errors);
} }
/** /**

View File

@@ -2,12 +2,11 @@
<h2><?= t('Add a new filter') ?></h2> <h2><?= t('Add a new filter') ?></h2>
</div> </div>
<form method="post" action="<?= $this->url->href('CustomFilterController', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off"> <form method="post" action="<?= $this->url->href('CustomFilterController', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
<?= $this->form->hidden('project_id', $values) ?> <?= $this->form->hidden('project_id', $values) ?>
<?= $this->form->label(t('Name'), 'name') ?> <?= $this->form->label(t('Name'), 'name') ?>
<?= $this->form->text('name', $values, $errors, array('required', 'maxlength="100"')) ?> <?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?>
<?= $this->form->label(t('Filter'), 'filter') ?> <?= $this->form->label(t('Filter'), 'filter') ?>
<?= $this->form->text('filter', $values, $errors, array('required', 'maxlength="100"')) ?> <?= $this->form->text('filter', $values, $errors, array('required', 'maxlength="100"')) ?>
@@ -18,7 +17,5 @@
<?= $this->form->checkbox('append', t('Append filter (instead of replacement)'), 1) ?> <?= $this->form->checkbox('append', t('Append filter (instead of replacement)'), 1) ?>
<div class="form-actions"> <?= $this->modal->submitButtons() ?>
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
</div>
</form> </form>

View File

@@ -1,51 +1,53 @@
<?php if (! empty($custom_filters)): ?> <?php if (! empty($custom_filters)): ?>
<div class="page-header"> <div class="page-header">
<h2><?= t('Custom filters') ?></h2> <h2><?= t('Custom filters') ?></h2>
<ul>
<li>
<?= $this->modal->medium('filter', t('Add custom filters'), 'CustomFilterController', 'create', array('project_id' => $project['id'])) ?>
</li>
</ul>
</div> </div>
<div> <table class="table-striped table-scrolling">
<table class="table-striped table-scrolling"> <tr>
<tr> <th class="column-15"><?= t('Name') ?></th>
<th class="column-15"><?= t('Name') ?></th> <th class="column-30"><?= t('Filter') ?></th>
<th class="column-30"><?= t('Filter') ?></th> <th class="column-10"><?= t('Shared') ?></th>
<th class="column-10"><?= t('Shared') ?></th> <th class="column-15"><?= t('Append/Replace') ?></th>
<th class="column-15"><?= t('Append/Replace') ?></th> <th class="column-25"><?= t('Owner') ?></th>
<th class="column-25"><?= t('Owner') ?></th> <th class="column-5"><?= t('Actions') ?></th>
<th class="column-5"><?= t('Actions') ?></th> </tr>
</tr> <?php foreach ($custom_filters as $filter): ?>
<?php foreach ($custom_filters as $filter): ?> <tr>
<tr> <td><?= $this->text->e($filter['name']) ?></td>
<td><?= $this->text->e($filter['name']) ?></td> <td><?= $this->text->e($filter['filter']) ?></td>
<td><?= $this->text->e($filter['filter']) ?></td> <td>
<td> <?php if ($filter['is_shared'] == 1): ?>
<?php if ($filter['is_shared'] == 1): ?> <?= t('Yes') ?>
<?= t('Yes') ?> <?php else: ?>
<?php else: ?> <?= t('No') ?>
<?= t('No') ?> <?php endif ?>
</td>
<td>
<?php if ($filter['append'] == 1): ?>
<?= t('Append') ?>
<?php else: ?>
<?= t('Replace') ?>
<?php endif ?>
</td>
<td><?= $this->text->e($filter['owner_name'] ?: $filter['owner_username']) ?></td>
<td>
<?php if ($filter['user_id'] == $this->user->getId() || $this->user->hasProjectAccess('CustomFilterController', 'edit', $project['id'])): ?>
<div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a>
<ul>
<li><?= $this->modal->medium('edit', t('Edit'), 'CustomFilterController', 'edit', array('project_id' => $filter['project_id'], 'filter_id' => $filter['id'])) ?></li>
<li><?= $this->modal->confirm('trash-o', t('Remove'), 'CustomFilterController', 'confirm', array('project_id' => $filter['project_id'], 'filter_id' => $filter['id'])) ?></li>
</ul>
</div>
<?php endif ?> <?php endif ?>
</td> </td>
<td> </tr>
<?php if ($filter['append'] == 1): ?> <?php endforeach ?>
<?= t('Append') ?> </table>
<?php else: ?>
<?= t('Replace') ?>
<?php endif ?>
</td>
<td><?= $this->text->e($filter['owner_name'] ?: $filter['owner_username']) ?></td>
<td>
<?php if ($filter['user_id'] == $this->user->getId() || $this->user->hasProjectAccess('CustomFilterController', 'edit', $project['id'])): ?>
<div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a>
<ul>
<li><?= $this->modal->medium('edit', t('Edit'), 'CustomFilterController', 'edit', array('project_id' => $filter['project_id'], 'filter_id' => $filter['id'])) ?></li>
<li><?= $this->modal->confirm('trash-o', t('Remove'), 'CustomFilterController', 'confirm', array('project_id' => $filter['project_id'], 'filter_id' => $filter['id'])) ?></li>
</ul>
</div>
<?php endif ?>
</td>
</tr>
<?php endforeach ?>
</table>
</div>
<?php endif ?> <?php endif ?>
<?= $this->render('custom_filter/add', array('project' => $project, 'values' => $values, 'errors' => $errors)) ?>

View File

@@ -32,7 +32,7 @@
<?php if ($this->user->hasProjectAccess('CustomFilterController', 'index', $project['id'])): ?> <?php if ($this->user->hasProjectAccess('CustomFilterController', 'index', $project['id'])): ?>
<li> <li>
<?= $this->url->icon('filter', t('Custom filters'), 'CustomFilterController', 'index', array('project_id' => $project['id'])) ?> <?= $this->modal->medium('filter', t('Add custom filters'), 'CustomFilterController', 'create', array('project_id' => $project['id'])) ?>
</li> </li>
<?php endif ?> <?php endif ?>