textFilter

This commit is contained in:
Yuri Kuznetsov
2014-07-29 17:19:00 +03:00
parent 71e4c2fca0
commit 149fa41e2b
12 changed files with 47 additions and 58 deletions

View File

@@ -82,6 +82,11 @@ class Base
}
}
}
protected function getTextFilterFields()
{
return $this->metadata->get("entityDefs.{$this->entityName}.collection.textFilterFields", array('name'));
}
protected function where($params, &$result)
{
@@ -96,6 +101,18 @@ class Base
$params['where'][] = $p;
}
}
} else if ($item['type'] == 'textFilter' && !empty($item['value'])) {
if (!empty($item['value'])) {
if (empty($result['whereClause'])) {
$result['whereClause'] = array();
}
$fieldList = $this->getTextFilterFields();
$d = array();
foreach ($fieldList as $field) {
$d[$field . '*'] = $item['value'] . '%';
}
$where['OR'] = $d;
}
}
}

View File

@@ -155,7 +155,6 @@
},
"collection": {
"sortBy": "name",
"asc": true,
"boolFilters": ["onlyMy"]
"asc": true
}
}

View File

@@ -148,7 +148,6 @@
},
"collection": {
"sortBy": "dateStart",
"asc": false,
"boolFilters": ["onlyMy"]
"asc": false
}
}

View File

@@ -183,7 +183,6 @@
},
"collection": {
"sortBy": "name",
"asc": true,
"boolFilters": ["onlyMy"]
"asc": true
}
}

View File

@@ -189,7 +189,6 @@
},
"collection": {
"sortBy": "createdAt",
"asc": false,
"boolFilters": ["onlyMy"]
"asc": false
}
}

View File

@@ -143,7 +143,6 @@
},
"collection": {
"sortBy": "dateStart",
"asc": false,
"boolFilters": ["onlyMy"]
"asc": false
}
}

View File

@@ -125,7 +125,6 @@
},
"collection": {
"sortBy": "createdAt",
"asc": false,
"boolFilters": ["onlyMy"]
"asc": false
}
}

View File

@@ -108,7 +108,6 @@
},
"collection": {
"sortBy": "createdAt",
"asc": false,
"boolFilters": ["onlyMy"]
"asc": false
}
}

View File

@@ -87,7 +87,6 @@
},
"collection": {
"sortBy": "createdAt",
"asc": false,
"boolFilters": ["onlyMy"]
"asc": false
}
}

View File

@@ -7,7 +7,7 @@
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" tabindex="-1">
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-left basic-filter-menu">
<ul class="dropdown-menu pull-left filter-menu">
{{#if presetFilters.length}}
<li><a class="preset" tabindex="-1" href="javascript:" data-name="" data-action="selectPreset">{{translate 'All'}}</a></li>
{{#each ../presetFilters}}
@@ -22,7 +22,7 @@
</ul>
</div>
{{/if}}
<input type="text" class="form-control filter" name="filter" value="{{filter}}">
<input type="text" class="form-control text-filter" name="textFilter" value="{{textFilter}}">
<div class="input-group-btn">
<button type="button" class="btn btn-primary search btn-icon" data-action="search">
<span class="glyphicon glyphicon-search"></span>

View File

@@ -28,7 +28,7 @@
this.dateTime = dateTime;
this.data = this.default = defaultData || {
filter: '',
textFilter: '',
bool: {},
basic: {name: true},
advanced: {},
@@ -39,25 +39,14 @@
data: null,
getWhere: function () {
getWhere: function () {
var where = [];
var where = [];
if (this.data.filter != '' && this.data.basic) {
var o = {
type: 'or',
value: [],
};
for (var field in this.data.basic) {
if (this.data.basic[field]) {
o.value.push({
field: field,
type: 'like',
value: this.data.filter + '%'
});
}
};
where.push(o);
if (this.data.textFilter && this.data.textFilter != '') {
where.push({
type: 'textFilter',
value: this.data.textFilter
});
}
if (this.data.bool) {
@@ -70,7 +59,9 @@
o.value.push(name);
}
}
where.push(o);
if (o.value.length) {
where.push(o);
}
}
if (this.data.advanced) {

View File

@@ -31,9 +31,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
fields: ['name'],
filter: '',
basic: null,
textFilter: '',
advanced: null,
@@ -44,7 +42,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
data: function () {
return {
scope: this.scope,
filter: this.filter,
textFilter: this.textFilter,
bool: this.bool || {},
boolFilters: this.boolFilters,
advancedFields: this.getAdvancedDefs(),
@@ -110,7 +108,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
},
events: {
'keypress input[name="filter"]': function (e) {
'keypress input[name="textFilter"]': function (e) {
if (e.keyCode == 13) {
this.search();
}
@@ -206,7 +204,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
this.removePreset(id);
}
},
'change .search-row ul.basic-filter-menu input[data-role="boolFilterCheckbox"]': function (e) {
'change .search-row ul.filter-menu input[data-role="boolFilterCheckbox"]': function (e) {
e.stopPropagation();
this.search();
}
@@ -308,9 +306,6 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
},
afterRender: function () {
/*this.$el.find('ul.basic-filter-menu li.checkbox').on('click', function (e) {
e.stopPropagation();
}.bind(this));*/
this.updateAddFilterButton();
this.$advancedFiltersBar = this.$el.find('.advanced-filters-bar');
@@ -323,7 +318,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
var name = this.presetName || null;
var data = this.getPresetData();
this.$el.find('ul.basic-filter-menu a.preset span').remove();
this.$el.find('ul.filter-menu a.preset span').remove();
if (name) {
this.$advancedFiltersPanel.addClass('hidden');
@@ -365,7 +360,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
name = name || '';
this.$el.find('ul.basic-filter-menu a.preset[data-name="'+name+'"]').prepend('<span class="glyphicon glyphicon-ok pull-right"></span>');
this.$el.find('ul.filter-menu a.preset[data-name="'+name+'"]').prepend('<span class="glyphicon glyphicon-ok pull-right"></span>');
},
search: function () {
@@ -406,8 +401,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
loadSearchData: function () {
var searchData = this.searchManager.get();
this.filter = searchData.filter;
this.basic = _.clone(searchData.basic);
this.textFilter = searchData.textFilter;
if ('presetName' in searchData) {
this.presetName = searchData.presetName;
@@ -448,11 +442,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
},
fetch: function () {
this.filter = this.$el.find('input[name="filter"]').val();
this.basic = {
name: true
};
this.textFilter = this.$el.find('input[name="textFilter"]').val();
this.bool = {};
@@ -470,8 +460,7 @@ Espo.define('Views.Record.Search', 'View', function (Dep) {
updateSearch: function () {
this.searchManager.set({
filter: this.filter,
basic: this.basic,
textFilter: this.textFilter,
advanced: this.advanced,
bool: this.bool,
presetName: this.presetName