Skip to content

EspoCRM – Open Source CRM Application

varcha field: any of, none of filters

Yuri Kuznetsovb242119e0037
diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json
index 0c0666c239..a05a720b07 100644
--- a/application/Espo/Resources/i18n/en_US/Global.json
+++ b/application/Espo/Resources/i18n/en_US/Global.json
@@ -774,7 +774,9 @@
"notContains": "Not Contains",
"isEmpty": "Is Empty",
"isNotEmpty": "Is Not Empty",
- "notEquals": "Not Equals"
+ "notEquals": "Not Equals",
+ "anyOf": "Any Of",
+ "noneOf": "None Of"
},
"intSearchRanges": {
"equals": "Equals",
diff --git a/client/res/templates/fields/varchar/search.tpl b/client/res/templates/fields/varchar/search.tpl
index 3d494d4705..3d953e6454 100644
--- a/client/res/templates/fields/varchar/search.tpl
+++ b/client/res/templates/fields/varchar/search.tpl
@@ -14,3 +14,6 @@
spellcheck="false"
{{/if}}
>
+<div data-role="multi-select-container" class="hidden">
+ <input data-role="multi-select-input">
+</div>
diff --git a/client/src/ui/multi-select.js b/client/src/ui/multi-select.js
index bee50cd6fd..ffb62867c8 100644
--- a/client/src/ui/multi-select.js
+++ b/client/src/ui/multi-select.js
@@ -42,12 +42,19 @@ import Selectize from 'lib!selectize';
* @property {boolean} [matchAnyWord=false]
* @property {boolean} [allowCustomOptions=false]
* @property {function (string): {value: string, text: string}|null} [create]
+ * @property {string[]} [values] Values. As of v9.1.0.
*/
/**
* @module ui/multi-select
*/
const MultiSelect = {
+
+ /**
+ * @const
+ */
+ defaultDelimiter: ':,:',
+
/**
* @param {Element|JQuery} element An element.
* @param {module:ui/multi-select~Options} options Options.
@@ -55,6 +62,10 @@ const MultiSelect = {
init: function (element, options) {
const $el = $(element);
+ if (options.values) {
+ $el.val(options.values.join(this.itemDelimiter));
+ }
+
options = MultiSelect.applyDefaultOptions(options);
const plugins = [];
@@ -182,7 +193,7 @@ const MultiSelect = {
removeButton: true,
draggable: false,
selectOnTab: false,
- delimiter: ':,:',
+ delimiter: MultiSelect.defaultDelimiter,
matchAnyWord: false,
allowCustomOptions: false,
};
diff --git a/client/src/views/fields/varchar.js b/client/src/views/fields/varchar.js
index 0944a4fd2a..2432e3f834 100644
--- a/client/src/views/fields/varchar.js
+++ b/client/src/views/fields/varchar.js
@@ -31,6 +31,7 @@
import BaseFieldView from 'views/fields/base';
import RegExpPattern from 'helpers/reg-exp-pattern';
import Autocomplete from 'ui/autocomplete';
+import MultiSelect from 'ui/multi-select';
/**
* A varchar field.
@@ -84,6 +85,8 @@ class VarcharFieldView extends BaseFieldView {
'notContains',
'notEquals',
'notLike',
+ 'anyOf',
+ 'noneOf',
'isEmpty',
'isNotEmpty',
]
@@ -113,6 +116,12 @@ class VarcharFieldView extends BaseFieldView {
*/
noSpellCheck = false
+ /**
+ * @private
+ * @type {HTMLInputElement}
+ */
+ searchMultiSelectInputElement
+
setup() {
this.setupOptions();
@@ -216,11 +225,9 @@ class VarcharFieldView extends BaseFieldView {
}
setupSearch() {
- this.events['change select.search-type'] = e => {
- const type = $(e.currentTarget).val();
-
- this.handleSearchType(type);
- };
+ this.addHandler('change', 'select.search-type', (e, /** HTMLSelectElement */target) => {
+ this.handleSearchType(target.value);
+ });
}
data() {
@@ -257,14 +264,30 @@ class VarcharFieldView extends BaseFieldView {
return data;
}
+ /**
+ * @protected
+ * @param {string} type
+ */
handleSearchType(type) {
- if (~['isEmpty', 'isNotEmpty'].indexOf(type)) {
- this.$el.find('input.main-element').addClass('hidden');
-
+ if (!this.element) {
+ // @todo Remove when handled by bullbone.
return;
}
- this.$el.find('input.main-element').removeClass('hidden');
+ const mainElement = this.element.querySelector('input.main-element');
+ const multiSelectContainer = this.element.querySelector('div[data-role="multi-select-container"]');
+
+ if (['isEmpty', 'isNotEmpty', 'anyOf', 'noneOf'].includes(type)) {
+ mainElement.classList.add('hidden');
+ } else {
+ mainElement.classList.remove('hidden');
+ }
+
+ if (['anyOf', 'noneOf'].includes(type)) {
+ multiSelectContainer.classList.remove('hidden');
+ } else {
+ multiSelectContainer.classList.add('hidden');
+ }
}
afterRender() {
@@ -274,6 +297,7 @@ class VarcharFieldView extends BaseFieldView {
const type = this.$el.find('select.search-type').val();
this.handleSearchType(type);
+ this.initSearchMultiSelect();
}
if (
@@ -415,6 +439,66 @@ class VarcharFieldView extends BaseFieldView {
};
}
+ if (type === 'anyOf' || type === 'noneOf') {
+ let list = this.searchMultiSelectInputElement ?
+ this.searchMultiSelectInputElement.value.split(MultiSelect.defaultDelimiter) : [];
+
+ if (list.length === 1 && list[0] === '') {
+ list = [];
+ }
+
+ if (type === 'anyOf') {
+ if (list.length === 0) {
+ return {
+ type: 'any',
+ data: {
+ type: 'anyOf',
+ valueList: list,
+ },
+ };
+ }
+
+ return {
+ type: 'in',
+ value: list,
+ data: {
+ type: 'anyOf',
+ valueList: list,
+ },
+ };
+ }
+
+ if (list.length === 0) {
+ return {
+ type: 'any',
+ data: {
+ type: 'noneOf',
+ valueList: list,
+ },
+ };
+ }
+
+ return {
+ type: 'or',
+ value: [
+ // Don't change order.
+ {
+ type: 'notIn',
+ value: list,
+ attribute: this.name,
+ },
+ {
+ type: 'isNull',
+ attribute: this.name,
+ },
+ ],
+ data: {
+ type: 'noneOf',
+ valueList: list,
+ },
+ };
+ }
+
const value = this.$element.val().toString().trim();
if (!value) {
@@ -444,6 +528,34 @@ class VarcharFieldView extends BaseFieldView {
getAutocompleteLookupFunction() {
return undefined;
}
+
+ /**
+ * @private
+ */
+ initSearchMultiSelect() {
+ if (!this.element) {
+ this.searchMultiSelectInputElement = undefined;
+
+ return;
+ }
+
+ this.searchMultiSelectInputElement = this.element.querySelector('input[data-role="multi-select-input"]');
+
+ MultiSelect.init(this.searchMultiSelectInputElement, {
+ items: (this.params.options || []).map(it => ({value: it, text: it})),
+ allowCustomOptions: true,
+ create: input => {
+ return {
+ value: input,
+ text: input,
+ };
+ },
+ values: this.getSearchParamsData().valueList || [],
+ });
+
+ this.element.querySelector('.selectize-dropdown-content')
+ .classList.add('small');
+ }
}
export default VarcharFieldView;