From c5ccf8e6da93df274db79145e4c99aa87c6e3d97 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 3 Aug 2015 11:43:49 +0300 Subject: [PATCH] Enum is Sorted --- .../Crm/Resources/metadata/entityDefs/Account.json | 5 +++-- application/Espo/Resources/i18n/en_US/Admin.json | 3 ++- application/Espo/Resources/metadata/fields/enum.json | 4 ++++ frontend/client/src/views/fields/enum.js | 11 +++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json index dc4f4be891..a8cf952ff4 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json @@ -23,8 +23,8 @@ "type": "enum", "options": [ "", - "Agriculture", "Advertising", + "Agriculture", "Apparel & Accessories", "Automotive", "Banking", @@ -52,7 +52,8 @@ "Television", "Transportation", "Venture Capital" - ] + ], + "isSorted": true }, "sicCode": { "type": "varchar", diff --git a/application/Espo/Resources/i18n/en_US/Admin.json b/application/Espo/Resources/i18n/en_US/Admin.json index d96dfc0a1f..b93580adb1 100644 --- a/application/Espo/Resources/i18n/en_US/Admin.json +++ b/application/Espo/Resources/i18n/en_US/Admin.json @@ -106,7 +106,8 @@ "noEmptyString": "No Empty String", "defaultType": "Default Type", "seeMoreDisabled": "Disable Text Cut", - "entityList": "Entity List" + "entityList": "Entity List", + "isSorted": "Is Sorted (alphabetically)" }, "messages": { "upgradeVersion": "Your EspoCRM will be upgraded to version {version}. This can take some time.", diff --git a/application/Espo/Resources/metadata/fields/enum.json b/application/Espo/Resources/metadata/fields/enum.json index b6a0b82ab7..fbe3ecc17b 100644 --- a/application/Espo/Resources/metadata/fields/enum.json +++ b/application/Espo/Resources/metadata/fields/enum.json @@ -14,6 +14,10 @@ "name":"default", "type":"varchar" }, + { + "name":"isSorted", + "type":"bool" + }, { "name":"translation", "type":"varchar", diff --git a/frontend/client/src/views/fields/enum.js b/frontend/client/src/views/fields/enum.js index c53d9e6fb5..fb815530ca 100644 --- a/frontend/client/src/views/fields/enum.js +++ b/frontend/client/src/views/fields/enum.js @@ -77,6 +77,17 @@ Espo.define('Views.Fields.Enum', ['Views.Fields.Base', 'lib!Selectize'], functio this.translatedOptions = translatedOptions; } } + + if (this.translatedOptions === null) { + this.translatedOptions = this.getLanguage().get(this.model.name, 'options', this.name) || {}; + } + + if (this.params.isSorted && this.translatedOptions) { + this.params.options = Espo.Utils.clone(this.params.options); + this.params.options = this.params.options.sort(function (v1, v2) { + return (this.translatedOptions[v1] || v1).localeCompare(this.translatedOptions[v2] || v2); + }.bind(this)); + } }, afterRender: function () {