diff --git a/client/src/views/fields/array.js b/client/src/views/fields/array.js index 6c5301de5d..a9edd2dff1 100644 --- a/client/src/views/fields/array.js +++ b/client/src/views/fields/array.js @@ -64,7 +64,7 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D isEmpty: (this.selected || []).length === 0, valueIsSet: this.model.has(this.name), maxItemLength: this.maxItemLength, - allowCustomOptions: this.allowCustomOptions + allowCustomOptions: this.allowCustomOptions, }, Dep.prototype.data.call(this)); }, @@ -146,22 +146,30 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D setupTranslation: function () { var t = {}; + if (this.params.translation) { - var data = this.getLanguage().data; var arr = this.params.translation.split('.'); + var pointer = this.getLanguage().data; + arr.forEach(function (key) { if (key in pointer) { pointer = pointer[key]; + t = pointer; } }, this); - } else { + } + else { t = this.translate(this.name, 'options', this.model.name); } + this.translatedOptions = null; + var translatedOptions = {}; + if (this.params.options) { + this.params.options.forEach(function (o) { if (typeof t === 'object' && o in t) { translatedOptions[o] = t[o]; @@ -169,6 +177,7 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D translatedOptions[o] = o; } }.bind(this)); + this.translatedOptions = translatedOptions; } }, @@ -181,21 +190,26 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D if (!this.originalOptionList) { this.originalOptionList = this.params.options; } + this.params.options = Espo.Utils.clone(optionList); if (this.mode == 'edit' && !silent) { var selectedOptionList = []; + this.selected.forEach(function (option) { if (~optionList.indexOf(option)) { selectedOptionList.push(option); } }, this); + this.selected = selectedOptionList; if (this.isRendered()) { this.reRender(); + this.trigger('change'); - } else { + } + else { this.once('after:render', function () { this.trigger('change'); }, this); @@ -212,7 +226,7 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D this.params.options = Espo.Utils.clone(this.originalOptionList); } - if (this.mode == 'edit') { + if (this.mode === 'edit') { if (this.isRendered()) { this.reRender(); } @@ -221,20 +235,29 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D controlAddItemButton: function () { var $select = this.$select; - if (!$select) return; - if (!$select.get(0)) return; + + if (!$select) { + return; + } + + if (!$select.get(0)) { + return; + } var value = $select.val().toString(); + if (!value && this.params.noEmptyString) { this.$addButton.addClass('disabled').attr('disabled', 'disabled'); - } else { + } + else { this.$addButton.removeClass('disabled').removeAttr('disabled'); } }, afterRender: function () { - if (this.mode == 'edit') { + if (this.mode === 'edit') { this.$list = this.$el.find('.list-group'); + var $select = this.$select = this.$el.find('.select'); if (this.allowCustomOptions) { @@ -242,8 +265,11 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D this.$addButton.on('click', function () { var value = this.$select.val().toString(); + this.addValue(value); + $select.val(''); + this.controlAddItemButton(); }.bind(this)); @@ -276,13 +302,13 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D }); } - if (this.mode == 'search') { + if (this.mode === 'search') { this.renderSearch(); } }, renderSearch: function () { - var $element = this.$element = this.$el.find('.main-element'); + this.$element = this.$el.find('.main-element'); var valueList = this.getSearchParamsData().valueList || this.searchParams.valueFront || []; @@ -383,51 +409,66 @@ define('views/fields/array', ['views/fields/base', 'lib!Selectize'], function (D getValueForDisplay: function () { var list = this.selected.map(function (item) { var label = null; + if (this.translatedOptions != null) { if (item in this.translatedOptions) { label = this.translatedOptions[item]; + label = this.escapeValue(label); } } + if (label === null) { label = this.escapeValue(item); } + if (label === '') { label = this.translate('None'); } var style = this.styleMap[item] || 'default'; + if (this.params.displayAsLabel) { label = '' + label + ''; - } else { + } + else { if (style && style != 'default') { label = '' + label + ''; } } + return label; }, this) if (this.displayAsList) { - if (!list.length) return ''; + if (!list.length) { + return ''; + } + var itemClassName = 'multi-enum-item-container'; + if (this.displayAsLabel) { itemClassName += ' multi-enum-item-label-container'; } + return '