Skip to content

EspoCRM – Open Source CRM Application

multi-enum option style

Yuri Kuznetsov2e13d485187b
diff --git a/client/src/ui/multi-select.js b/client/src/ui/multi-select.js
index ffb62867c8..50458b04e5 100644
--- a/client/src/ui/multi-select.js
+++ b/client/src/ui/multi-select.js
@@ -33,7 +33,7 @@ import Selectize from 'lib!selectize';
/**
* @typedef module:ui/multi-select~Options
* @type {Object}
- * @property {{value: string, text: string}[]} items
+ * @property {{value: string, text: string, style?: string}[]} items
* @property {string} [delimiter=':,:']
* @property {boolean} [restoreOnBackspace=false]
* @property {boolean} [removeButton=true]
@@ -68,23 +68,25 @@ const MultiSelect = {
options = MultiSelect.applyDefaultOptions(options);
- const plugins = [];
+ const plugins = {};
if (options.removeButton) {
- plugins.push('remove_button');
+ plugins.remove_button = {title: ''};
}
if (options.draggable) {
- plugins.push('drag_drop');
+ plugins.drag_drop = {};
}
if (options.restoreOnBackspace) {
MultiSelect.loadRestoreOnBackspacePlugin();
- plugins.push('restore_on_backspace_espo')
+
+ plugins.restore_on_backspace_espo = {};
}
MultiSelect.loadBypassCtrlEnterPlugin();
- plugins.push('bypass_ctrl_enter');
+
+ plugins.bypass_ctrl_enter = {};
const selectizeOptions = {
options: options.items,
@@ -139,25 +141,37 @@ const MultiSelect = {
};
}
+ selectizeOptions.render = {};
+
if (options.allowCustomOptions) {
selectizeOptions.persist = false;
selectizeOptions.create = options.create;
- // noinspection JSUnusedGlobalSymbols
- selectizeOptions.render = {
- option_create: data => {
- return $('<div>')
- .addClass('create')
- .append(
- $('<span>')
- .text(data.input)
- .addClass('text-bold')
- )
- .append('&hellip;')
- .get(0).outerHTML;
- },
- };
+
+ selectizeOptions.render.option_create = data => {
+ return $('<div>')
+ .addClass('create')
+ .append(
+ $('<span>')
+ .text(data.input)
+ .addClass('text-bold')
+ )
+ .append('&hellip;')
+ .get(0).outerHTML;
+ }
}
+ const styleMap = (options.items || []).reduce((o, it) => ({
+ [it.value]: it.style,
+ ...o,
+ }), {});
+
+ selectizeOptions.render.item = (/** {text: string, value: string} */data, escape) => {
+ const text = escape(data.text);
+ const style = styleMap[data.value] || '';
+
+ return `<div class="${style}"><span>${text}</span> <a href="javascript:" class="remove">&times;</a></div>`;
+ };
+
$el.selectize(selectizeOptions);
},
diff --git a/client/src/views/fields/array.js b/client/src/views/fields/array.js
index 5d05937739..b00f41dc76 100644
--- a/client/src/views/fields/array.js
+++ b/client/src/views/fields/array.js
@@ -485,6 +485,7 @@ class ArrayFieldView extends BaseFieldView {
items.push({
value: value,
text: label,
+ style: this.styleMap[value] || undefined,
});
});
diff --git a/client/src/views/fields/multi-enum.js b/client/src/views/fields/multi-enum.js
index ae4dff55f7..91ce0ddebf 100644
--- a/client/src/views/fields/multi-enum.js
+++ b/client/src/views/fields/multi-enum.js
@@ -181,6 +181,7 @@ class MultiEnumFieldView extends ArrayFieldView {
items.push({
value: value,
text: this.translateValueToEditLabel(originalValue),
+ style: this.styleMap[value] || undefined,
});
});
diff --git a/frontend/less/espo/misc/selectize/custom.less b/frontend/less/espo/misc/selectize/custom.less
index 4e6bc94130..f2d2d2defd 100644
--- a/frontend/less/espo/misc/selectize/custom.less
+++ b/frontend/less/espo/misc/selectize/custom.less
@@ -70,9 +70,43 @@
}
}
-.selectize-control.multi .selectize-input > div {
- border-radius: var(--border-radius);
- padding: var(--1px) var(--4px);
+.selectize-control.multi .selectize-input {
+ > div {
+ border-radius: var(--border-radius);
+ padding: var(--1px) var(--4px);
+
+ &:not(.active) {
+ &.primary {
+ > span {
+ color: var(--state-primary-text);
+ }
+ }
+
+ &.warning {
+ > span {
+ color: var(--state-warning-text);
+ }
+ }
+
+ &.danger {
+ > span {
+ color: var(--state-danger-text);
+ }
+ }
+
+ &.info {
+ > span {
+ color: var(--state-info-text);
+ }
+ }
+
+ &.success {
+ > span {
+ color: var(--state-success-text);
+ }
+ }
+ }
+ }
}
.selectize-control.single {