select filter search
This commit is contained in:
@@ -40,7 +40,6 @@
|
||||
"Views.Fields.Bool",
|
||||
"Views.Fields.Datetime",
|
||||
"Views.Fields.Email",
|
||||
"Views.Fields.Enum",
|
||||
"Views.Fields.Float",
|
||||
"Views.Fields.LinkMultiple",
|
||||
"Views.Fields.LinkParent",
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
<select name="{{name}}" class="form-control input-sm" multiple>
|
||||
{{options params.options searchParams.value scope=scope field=name translatedOptions=translatedOptions}}
|
||||
</select>
|
||||
|
||||
<input name="{{name}}" type="hidden">
|
||||
<input name="{{name}}" type="text">
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
(function (Espo, _, $) {
|
||||
|
||||
@@ -85,8 +85,8 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
var loadClasses = function () {
|
||||
data.classes.forEach(function (name) {
|
||||
var loadClasses = function () {
|
||||
data.classes.forEach(function (name) {
|
||||
Espo.loader.load(name, function () {
|
||||
classesLoaded++;
|
||||
countLoaded++;
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Views.Fields.EnumFloat', 'Views.Fields.EnumInt', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
type: 'enumFloat',
|
||||
type: 'enumFloat',
|
||||
|
||||
fetch: function () {
|
||||
var value = parseFloat(this.$el.find('[name="' + this.name + '"]').val());
|
||||
@@ -33,13 +33,23 @@ Espo.define('Views.Fields.EnumFloat', 'Views.Fields.EnumInt', function (Dep) {
|
||||
},
|
||||
|
||||
fetchSearch: function () {
|
||||
var arr = [];
|
||||
$.each(this.$el.find('[name="' + this.name + '"]').find('option:selected'), function (i, el) {
|
||||
arr.push(parseFloat($(el).val()));
|
||||
});
|
||||
var list = this.$element.val().split(':,:');
|
||||
|
||||
list.forEach(function (item, i) {
|
||||
list[i] = parseFloat(list[i]);
|
||||
}, this);
|
||||
|
||||
if (list.length == 1 && list[0] == '') {
|
||||
list = [];
|
||||
}
|
||||
|
||||
if (list.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = {
|
||||
type: 'in',
|
||||
value: arr
|
||||
value: list
|
||||
};
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Views.Fields.EnumInt', 'Views.Fields.Enum', function (Dep) {
|
||||
|
||||
@@ -32,7 +32,7 @@ Espo.define('Views.Fields.EnumInt', 'Views.Fields.Enum', function (Dep) {
|
||||
editTemplate: 'fields.enum.edit',
|
||||
|
||||
searchTemplate: 'fields.enum.search',
|
||||
|
||||
|
||||
validations: [],
|
||||
|
||||
fetch: function () {
|
||||
@@ -43,16 +43,27 @@ Espo.define('Views.Fields.EnumInt', 'Views.Fields.Enum', function (Dep) {
|
||||
},
|
||||
|
||||
fetchSearch: function () {
|
||||
var arr = [];
|
||||
$.each(this.$el.find('[name="' + this.name + '"]').find('option:selected'), function (i, el) {
|
||||
arr.push(parseInt($(el).val()));
|
||||
});
|
||||
var list = this.$element.val().split(':,:');
|
||||
|
||||
list.forEach(function (item, i) {
|
||||
list[i] = parseInt(list[i]);
|
||||
}, this);
|
||||
|
||||
if (list.length == 1 && list[0] == '') {
|
||||
list = [];
|
||||
}
|
||||
|
||||
if (list.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = {
|
||||
type: 'in',
|
||||
value: arr
|
||||
value: list
|
||||
};
|
||||
return data;
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Views.Fields.EnumStyled', 'Views.Fields.Enum', function (Dep) {
|
||||
|
||||
@@ -26,10 +26,10 @@ Espo.define('Views.Fields.EnumStyled', 'Views.Fields.Enum', function (Dep) {
|
||||
listTemplate: 'fields.enum-styled.detail',
|
||||
|
||||
detailTemplate: 'fields.enum-styled.detail',
|
||||
|
||||
data: function () {
|
||||
var value = this.model.get(this.name);
|
||||
var style = 'default';
|
||||
|
||||
data: function () {
|
||||
var value = this.model.get(this.name);
|
||||
var style = 'default';
|
||||
if (value in this.styleHash) {
|
||||
style = this.styleHash[value];
|
||||
}
|
||||
@@ -37,10 +37,10 @@ Espo.define('Views.Fields.EnumStyled', 'Views.Fields.Enum', function (Dep) {
|
||||
style: style,
|
||||
}, Dep.prototype.data.call(this));
|
||||
},
|
||||
|
||||
|
||||
setup: function () {
|
||||
Dep.prototype.setup.call(this);
|
||||
|
||||
|
||||
this.styleHash = this.model.getFieldParam(this.name, 'style') || {};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('Views.Fields.Enum', ['Views.Fields.Base'], function (Dep) {
|
||||
Espo.define('Views.Fields.Enum', ['Views.Fields.Base', 'lib!Selectize'], function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
@@ -79,6 +79,51 @@ Espo.define('Views.Fields.Enum', ['Views.Fields.Base'], function (Dep) {
|
||||
}
|
||||
},
|
||||
|
||||
afterRender: function () {
|
||||
Dep.prototype.afterRender.call(this);
|
||||
|
||||
if (this.mode == 'search') {
|
||||
var $element = this.$element = this.$el.find('[name="' + this.name + '"]');
|
||||
|
||||
var valueList = this.searchParams.value || [];
|
||||
this.$element.val(valueList.join(':,:'));
|
||||
|
||||
var data = [];
|
||||
(this.params.options || []).forEach(function (value) {
|
||||
var label = this.getLanguage().translateOption(value, this.name, this.scope);
|
||||
if (this.translatedOptions) {
|
||||
if (value in this.translatedOptions) {
|
||||
label = this.translatedOptions[value];
|
||||
}
|
||||
}
|
||||
data.push({
|
||||
value: value,
|
||||
label: label
|
||||
});
|
||||
}, this);
|
||||
|
||||
this.$element.selectize({
|
||||
options: data,
|
||||
delimiter: ':,:',
|
||||
labelField: 'label',
|
||||
valueField: 'value',
|
||||
highlight: false,
|
||||
searchField: ['label'],
|
||||
plugins: ['remove_button'],
|
||||
score: function (search) {
|
||||
var score = this.getScoreFunction(search);
|
||||
search = search.toLowerCase();
|
||||
return function (item) {
|
||||
if (item.label.toLowerCase().indexOf(search) === 0) {
|
||||
return score(item);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
validateRequired: function () {
|
||||
if (this.params.required || this.model.isRequired(this.name)) {
|
||||
if (!this.model.get(this.name)) {
|
||||
@@ -97,18 +142,18 @@ Espo.define('Views.Fields.Enum', ['Views.Fields.Base'], function (Dep) {
|
||||
},
|
||||
|
||||
fetchSearch: function () {
|
||||
var arr = [];
|
||||
$.each(this.$el.find('[name="' + this.name + '"]').find('option:selected'), function (i, el) {
|
||||
arr.push($(el).val());
|
||||
});
|
||||
var list = this.$element.val().split(':,:');
|
||||
if (list.length == 1 && list[0] == '') {
|
||||
list = [];
|
||||
}
|
||||
|
||||
if (arr.length == 0) {
|
||||
if (list.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var data = {
|
||||
type: 'in',
|
||||
value: arr
|
||||
value: list
|
||||
};
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -64,9 +64,9 @@ Espo.define('Views.Fields.MultiEnum', ['Views.Fields.Array', 'lib!Selectize'], f
|
||||
|
||||
var data = [];
|
||||
(this.params.options || []).forEach(function (value) {
|
||||
var label = this.getLanguage().translateOption(value, this.name, this.scope);
|
||||
if (this.translatedOptions) {
|
||||
var label = value;
|
||||
if (value in this.translatedOptions) {
|
||||
if (value in this.translatedOptions) {
|
||||
label = this.translatedOptions[value];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user