From e377f450ad9a97ae9031d852e9195b9092d3e9db Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 8 Jan 2017 12:16:05 -0500 Subject: [PATCH] Open form to create customer filters in modal box --- ChangeLog | 1 + app/Controller/CustomFilterController.php | 29 ++++-- .../custom_filter/{add.php => create.php} | 7 +- app/Template/custom_filter/index.php | 90 ++++++++++--------- app/Template/project_header/dropdown.php | 2 +- 5 files changed, 72 insertions(+), 57 deletions(-) rename app/Template/custom_filter/{add.php => create.php} (79%) diff --git a/ChangeLog b/ChangeLog index eb3d4042e..068f5ecf3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ Improvements: * Add helpers to open modal boxes * Make icons clickable in menus * Open task import in modal box +* Open form to create customer filters in modal box Version 1.0.36 (Dec 30, 2016) ----------------------------- diff --git a/app/Controller/CustomFilterController.php b/app/Controller/CustomFilterController.php index e5f674cd6..b0b2daff2 100644 --- a/app/Controller/CustomFilterController.php +++ b/app/Controller/CustomFilterController.php @@ -18,23 +18,37 @@ class CustomFilterController extends BaseController * Display list of filters * * @access public - * @param array $values - * @param array $errors * @throws \Kanboard\Core\Controller\PageNotFoundException */ - public function index(array $values = array(), array $errors = array()) + public function index() { $project = $this->getProject(); $this->response->html($this->helper->layout->project('custom_filter/index', array( - 'values' => $values + array('project_id' => $project['id']), - 'errors' => $errors, 'project' => $project, 'custom_filters' => $this->customFilterModel->getAll($project['id'], $this->userSession->getId()), '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 * @@ -52,13 +66,14 @@ class CustomFilterController extends BaseController if ($valid) { if ($this->customFilterModel->create($values) !== false) { $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 { $this->flash->failure(t('Unable to create your custom filter.')); } } - return $this->index($values, $errors); + $this->create($values, $errors); } /** diff --git a/app/Template/custom_filter/add.php b/app/Template/custom_filter/create.php similarity index 79% rename from app/Template/custom_filter/add.php rename to app/Template/custom_filter/create.php index 0b91226a4..24e896eef 100644 --- a/app/Template/custom_filter/add.php +++ b/app/Template/custom_filter/create.php @@ -2,12 +2,11 @@

- form->csrf() ?> form->hidden('project_id', $values) ?> form->label(t('Name'), 'name') ?> - form->text('name', $values, $errors, array('required', 'maxlength="100"')) ?> + form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?> form->label(t('Filter'), 'filter') ?> form->text('filter', $values, $errors, array('required', 'maxlength="100"')) ?> @@ -18,7 +17,5 @@ form->checkbox('append', t('Append filter (instead of replacement)'), 1) ?> -
- -
+ modal->submitButtons() ?>
diff --git a/app/Template/custom_filter/index.php b/app/Template/custom_filter/index.php index 95356e646..d8d1c8e0b 100644 --- a/app/Template/custom_filter/index.php +++ b/app/Template/custom_filter/index.php @@ -1,51 +1,53 @@ -
- - - - - - - - - - - - - - + + +
text->e($filter['name']) ?>text->e($filter['filter']) ?> - - - - + + + + + + + + + + + + + + + + + - - - - - -
text->e($filter['name']) ?>text->e($filter['filter']) ?> + + + + + + + + + + + + text->e($filter['owner_name'] ?: $filter['owner_username']) ?> + user->getId() || $this->user->hasProjectAccess('CustomFilterController', 'edit', $project['id'])): ?> + - - - - - - - text->e($filter['owner_name'] ?: $filter['owner_username']) ?> - user->getId() || $this->user->hasProjectAccess('CustomFilterController', 'edit', $project['id'])): ?> - - -
- +
-render('custom_filter/add', array('project' => $project, 'values' => $values, 'errors' => $errors)) ?> diff --git a/app/Template/project_header/dropdown.php b/app/Template/project_header/dropdown.php index 7fcdfb55f..3f11838d0 100644 --- a/app/Template/project_header/dropdown.php +++ b/app/Template/project_header/dropdown.php @@ -32,7 +32,7 @@ user->hasProjectAccess('CustomFilterController', 'index', $project['id'])): ?>
  • - url->icon('filter', t('Custom filters'), 'CustomFilterController', 'index', array('project_id' => $project['id'])) ?> + modal->medium('filter', t('Add custom filters'), 'CustomFilterController', 'create', array('project_id' => $project['id'])) ?>