diff --git a/frontend/client/cfg/pre-load.json b/frontend/client/cfg/pre-load.json
index c283f96e3b..75d7b18950 100644
--- a/frontend/client/cfg/pre-load.json
+++ b/frontend/client/cfg/pre-load.json
@@ -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",
diff --git a/frontend/client/res/templates/fields/enum/search.tpl b/frontend/client/res/templates/fields/enum/search.tpl
index 07fa5f6397..93309657d6 100644
--- a/frontend/client/res/templates/fields/enum/search.tpl
+++ b/frontend/client/res/templates/fields/enum/search.tpl
@@ -1,6 +1,3 @@
-
-
+
diff --git a/frontend/client/src/pre-loader.js b/frontend/client/src/pre-loader.js
index 9069bac004..3add337694 100644
--- a/frontend/client/src/pre-loader.js
+++ b/frontend/client/src/pre-loader.js
@@ -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++;
diff --git a/frontend/client/src/views/fields/enum-float.js b/frontend/client/src/views/fields/enum-float.js
index 8a3b6a2f7f..358a9ceaa2 100644
--- a/frontend/client/src/views/fields/enum-float.js
+++ b/frontend/client/src/views/fields/enum-float.js
@@ -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;
},
diff --git a/frontend/client/src/views/fields/enum-int.js b/frontend/client/src/views/fields/enum-int.js
index 3614a90b62..030a10d9df 100644
--- a/frontend/client/src/views/fields/enum-int.js
+++ b/frontend/client/src/views/fields/enum-int.js
@@ -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;
},
+
});
});
diff --git a/frontend/client/src/views/fields/enum-styled.js b/frontend/client/src/views/fields/enum-styled.js
index 954816b22b..9a24b4eae9 100644
--- a/frontend/client/src/views/fields/enum-styled.js
+++ b/frontend/client/src/views/fields/enum-styled.js
@@ -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') || {};
},
});
diff --git a/frontend/client/src/views/fields/enum.js b/frontend/client/src/views/fields/enum.js
index 7de656b7bd..c53d9e6fb5 100644
--- a/frontend/client/src/views/fields/enum.js
+++ b/frontend/client/src/views/fields/enum.js
@@ -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;
},
diff --git a/frontend/client/src/views/fields/multi-enum.js b/frontend/client/src/views/fields/multi-enum.js
index 8c1d0565c0..41d7ff53a5 100644
--- a/frontend/client/src/views/fields/multi-enum.js
+++ b/frontend/client/src/views/fields/multi-enum.js
@@ -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];
}
}