Skip to content

Commit c514539

Browse files
committed
Releasing 1.0.18
2 parents ecf8ecb + fea1fb2 commit c514539

File tree

7 files changed

+139
-2
lines changed

7 files changed

+139
-2
lines changed

js/search-filter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
class SearchFilter {
3+
4+
searchSubmit(domElement) {
5+
var filterForm = jQuery('#filterForm');
6+
if (filterForm.length == 0) {
7+
jQuery('#searchForm').submit();
8+
} else {
9+
jQuery('#filterForm input[name=search]').val(jQuery('#searchForm input[name=search]').val());
10+
filterForm.submit();
11+
}
12+
}
13+
14+
filterSubmit(domElement) {
15+
var searchForm = jQuery('#searchForm');
16+
if (searchForm.length > 0) {
17+
jQuery('#filterForm input[name=search]').val(jQuery('#searchForm input[name=search]').val());
18+
}
19+
jQuery('#filterForm').submit();
20+
}
21+
}
22+
var searchFilter = new SearchFilter();
23+

src/WebApp/BootstrapTheme/BootstrapTheme.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class BootstrapTheme extends \WebApp\DefaultTheme\DefaultTheme {
1515
public const DYNAMICFIELDS = 'dynamicfields';
1616
public const DYNAMICCHECKENABLE = 'dynamiccheckenable';
1717
public const CROPPERJS = 'cropperjs';
18+
public const SEARCH_FILTER = 'search-filter';
19+
1820
public const CSS_URI = 'BootstrapTheme/CssUri';
1921

2022
public function __construct($app) {

src/WebApp/BootstrapTheme/DefaultLayout.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ protected function renderJavascript() {
194194
if ($this->theme->hasFeature(BootstrapTheme::REMOTESEARCH)) {
195195
$rc .= '<script src="'.Utils::getJavascriptPath('remote-search.js', TRUE).'"></script>';
196196
}
197+
if ($this->theme->hasFeature(BootstrapTheme::SEARCH_FILTER)) {
198+
$rc .= '<script src="'.Utils::getJavascriptPath('search-filter.js', TRUE).'"></script>';
199+
}
197200
if ($this->theme->hasFeature(BootstrapTheme::DYNAMICFIELDS)) {
198201
$rc .= '<script src="'.Utils::getJavascriptPath('dynamic-fields.js', TRUE).'"></script>';
199202
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace WebApp\BootstrapTheme;
4+
5+
class FilterPanelRenderer extends \WebApp\DefaultTheme\DivRenderer {
6+
7+
public function __construct($theme, $component) {
8+
parent::__construct($theme, $component);
9+
$this->theme->addFeature(BootstrapTheme::SEARCH_FILTER);
10+
}
11+
12+
}
13+

src/WebApp/BootstrapTheme/SearchFilterBarRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SearchFilterBarRenderer extends \WebApp\DefaultTheme\FormRenderer {
66

77
public function __construct($theme, $component) {
88
parent::__construct($theme, $component);
9-
$this->addClass('mt-sm-4');
9+
$this->theme->addFeature(BootstrapTheme::SEARCH_FILTER);
1010
}
1111

1212
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace WebApp\Component;
4+
5+
use TgI18n\I18N;
6+
use TgUtils\Request;
7+
8+
class FilterPanel extends Div {
9+
10+
protected static $filter;
11+
12+
public function __construct($parent) {
13+
parent::__construct($parent);
14+
$this->addClass('filter-panel');
15+
$this->form = new Form($this, 'filterForm');
16+
$this->form->setAction(Request::getRequest()->originalPath);
17+
$this->addFilterSections();
18+
$this->addButtons();
19+
}
20+
21+
public function addFilterCheckbox($parent, $groupId, $value, $label, $defaultChecked = FALSE) {
22+
$div = new Div($parent);
23+
$div->addClass('form-group');
24+
$cb = new Checkbox($div, 'filter'.ucfirst($groupId).ucfirst($value), $groupId.':'.$value);
25+
$cb->setName('filter[]');
26+
$cb->setLabel($label);
27+
$cb->setAnnotation('webapp/renderer', 'WebApp\\DefaultTheme\\PlainCheckboxRenderer');
28+
if (self::hasFilter($groupId)) {
29+
$cb->setChecked(self::isFilterSet($groupId, $value));
30+
} else {
31+
$cb->setChecked($defaultChecked);
32+
}
33+
return $cb;
34+
}
35+
36+
public function addSection($label, $id) {
37+
$div = new Div($this->form);
38+
$div->addClass('filter-section');
39+
$p = new Paragraph($div);
40+
$p->addClass('section-toggle');
41+
$l = new Link($p, '#'.$id, strtoupper(I18N::_($label)));
42+
$l
43+
->addClass('link-primary')
44+
->setAttribute('data-toggle', 'collapse')
45+
->setAttribute('role', 'button')
46+
->setAttribute('aria-expanded', 'true')
47+
->setAttribute('aria-controls', $id);
48+
49+
$rc = new Div($div);
50+
$rc
51+
->setId($id)
52+
->addClass('section-content', 'collapse', 'show');
53+
return $rc;
54+
}
55+
56+
protected function addButtons() {
57+
$div = new Div($this->form);
58+
$div->addClass('filter-submit');
59+
$request = Request::getRequest();
60+
$search = $request->getParam('search');
61+
new HiddenInput($div, 'search', $search);
62+
$btn = new SubmitButton($div, 'apply_label');
63+
$btn->setAttribute('onclick', 'searchFilter.filterSubmit(this);return false');
64+
}
65+
66+
public static function getFilters($request = NULL) {
67+
if (self::$filter == NULL) {
68+
if ($request == NULL) $request = Request::getRequest();
69+
self::$filter = array();
70+
foreach ($request->getParam('filter', array()) AS $filter) {
71+
list($name, $value) = explode(':', $filter, 2);
72+
self::$filter[$name][] = $value;
73+
}
74+
}
75+
return self::$filter;
76+
}
77+
78+
public static function getFilter($name, $request = NULL) {
79+
$filters = self::getFilters($request);
80+
if (isset($filters[$name])) return $filters[$name];
81+
return array();
82+
}
83+
84+
public static function isFilterSet($name, $value, $request = NULL) {
85+
$filters = self::getFilter($name, $request);
86+
return in_array($value, $filters);
87+
}
88+
89+
public static function hasFilter($name, $request = NULL) {
90+
$filters = self::getFilter($name, $request);
91+
return count($filters) > 0;
92+
}
93+
94+
}
95+

src/WebApp/Component/SearchFilterBar.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
class SearchFilterBar extends Form {
88

99
public function __construct($parent) {
10-
parent::__construct($parent, 'search', Form::INLINE);
10+
parent::__construct($parent, 'searchForm', Form::INLINE);
1111
$this->setMethod('GET');
1212
$this->setAction(Request::getRequest()->originalPath);
1313
$this->searchInput = $this->createSearchInput();
1414
$this->button = $this->createSubmitButton();
15+
$this->button->setAttribute('onclick', 'searchFilter.searchSubmit(this); return false');
1516
$this->createFilters();
1617
}
1718

0 commit comments

Comments
 (0)