ability to edit translated options

This commit is contained in:
Yuri Kuznetsov
2014-11-04 12:24:52 +02:00
parent 426dc4592e
commit 44c4ae7d28
13 changed files with 118 additions and 30 deletions
@@ -94,6 +94,12 @@ class FieldManager
$res &= $this->setLabel($name, $fieldDef['label'], $scope);
}
if (isset($fieldDef['type']) && $fieldDef['type'] == 'enum') {
if (isset($fieldDef['translatedOptions'])) {
$res &= $this->setTranslatedOptions($name, $fieldDef['translatedOptions'], $scope);
}
}
if ($this->isDefsChanged($name, $fieldDef, $scope)) {
$res &= $this->setEntityDefs($name, $fieldDef, $scope);
}
@@ -129,6 +135,11 @@ class FieldManager
return $res;
}
protected function setTranslatedOptions($name, $value, $scope)
{
return $this->getLanguage()->set($name, $value, 'options', $scope);
}
protected function setLabel($name, $value, $scope)
{
return $this->getLanguage()->set($name, $value, 'fields', $scope);
@@ -74,7 +74,7 @@
"required": "Erforderlich",
"default": "Standard",
"maxLength": "Maximallänge",
"options": "Optionen (Datenbank Werte, nicht übersetzt)",
"options": "Optionen",
"after": "Nach (Feld)",
"before": "Vor (Feld)",
"link": "Link",
@@ -88,7 +88,7 @@
"required": "Required",
"default": "Default",
"maxLength": "Max Length",
"options": "Options (raw values, not translated)",
"options": "Options",
"after": "After (field)",
"before": "Before (field)",
"link": "Link",
@@ -71,7 +71,7 @@
"required": "Requerido",
"default": "Por Defecto",
"maxLength": "Longitud máxima",
"options": "Options (raw values, not translated)",
"options": "Options",
"after": "After (field)",
"before": "Before (field)",
"link": "Enlace",
@@ -73,7 +73,7 @@
"required": "Requis",
"default": "Standard",
"maxLength": "Taille Maximum",
"options": "Options (raw values, not translated)",
"options": "Options",
"after": "After (field)",
"before": "Before (field)",
"link": "Lien",
@@ -87,7 +87,7 @@
"required": "Verplicht",
"default": "Standaard",
"maxLength": "Max Lengte",
"options": "Opties (ruwe waarden, niet vertaald)",
"options": "Opties",
"after": "Achter (veld)",
"before": "Voor (veld)",
"link": "Link",
@@ -78,7 +78,7 @@
"required": "Obrigatório",
"default": "Padrão",
"maxLength": "Tamanho máximo",
"options": "Opções (valores raw, não traduzíveis)",
"options": "Opções",
"after": "Antes (field)",
"before": "Após (field)",
"link": "Link",
@@ -74,7 +74,7 @@
"required": "Required",
"default": "Default",
"maxLength": "Max Length",
"options": "Options (raw values, not translated)",
"options": "Options",
"after": "After (field)",
"before": "Before (field)",
"link": "Link",
@@ -7,7 +7,8 @@
},
{
"name":"options",
"type":"array"
"type":"array",
"view": "Admin.FieldManager.Fields.Options"
},
{
"name":"default",
@@ -1,13 +1,6 @@
<div class="link-container list-group">
{{#each selected}}
<div class="list-group-item" data-value="{{./this}}">
{{#if ../translatedOptions}}
{{prop ../../translatedOptions this}}&nbsp;
{{else}}
{{./this}}&nbsp;
{{/if}}
<a href="javascript:" class="pull-right" data-value="{{./this}}" data-action="removeValue"><span class="glyphicon glyphicon-remove"></a>
</div>
{{#each itemHtmlList}}
{{{./this}}}
{{/each}}
</div>
{{#if hasOptions}}
@@ -133,7 +133,8 @@ Espo.define('Views.Admin.FieldManager.Edit', 'View', function (Dep) {
},
createFieldView: function (type, name, readOnly, params) {
this.createView(name, this.getFieldManager().getViewName(type), {
var viewName = (params || {}).view || this.getFieldManager().getViewName(type);
this.createView(name, viewName, {
model: this.model,
el: this.options.el + ' .field-' + name,
defs: {
@@ -142,6 +143,8 @@ Espo.define('Views.Admin.FieldManager.Edit', 'View', function (Dep) {
},
mode: readOnly ? 'detail' : 'edit',
readOnly: readOnly,
scope: this.scope,
field: this.field,
});
this.fieldList.push(name);
},
@@ -175,6 +178,14 @@ Espo.define('Views.Admin.FieldManager.Edit', 'View', function (Dep) {
data[this.scope]['fields'] = {};
}
data[this.scope]['fields'][this.model.get('name')] = this.model.get('label');
if (this.model.get('type') == 'enum' && this.model.get('translatedOptions')) {
if (!('options' in data[this.scope])) {
data[this.scope]['options'] = {};
}
data[this.scope]['options'][this.model.get('name')] = this.model.get('translatedOptions') || {};
}
}
this.getRouter().navigate('#Admin/fieldManager/scope=' + this.scope + '&field=' + this.model.get('name'), {trigger: true});
@@ -0,0 +1,61 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.Admin.FieldManager.Fields.Options', 'Views.Fields.Array', function (Dep) {
return Dep.extend({
setup: function () {
Dep.prototype.setup.call(this);
this.translatedOptions = this.getLanguage().get(this.options.scope, 'options', this.options.field) || {};
},
getItemHtml: function (value) {
var translatedValue = this.translatedOptions[value] || value;
var html = '' +
'<div class="list-group-item link-with-role form-inline" data-value="' + value + '">' +
'<div class="pull-left" style="width: 92%; display: inline-block;">' +
'<input name="translatedValue" data-value="' + value + '" class="role form-control input-sm pull-right" value="'+translatedValue+'">' +
'<div>' + value + '</div>' +
'</div>' +
'<div style="width: 8%; display: inline-block; vertical-align: top;">' +
'<a href="javascript:" class="pull-right" data-value="' + value + '" data-action="removeValue"><span class="glyphicon glyphicon-remove"></a>' +
'</div><br style="clear: both;" />' +
'</div>';
return html;
},
fetch: function () {
var data = Dep.prototype.fetch.call(this);
data.translatedOptions = {};
(data[this.name] || []).forEach(function (value) {
data.translatedOptions[value] = this.$el.find('input[name="translatedValue"][data-value="'+value+'"]').val() || value;
}, this);
return data;
},
});
});
+23 -12
View File
@@ -32,10 +32,16 @@ Espo.define('Views.Fields.Array', 'Views.Fields.Enum', function (Dep) {
editTemplate: 'fields.array.edit',
data: function () {
var itemHtmlList = [];
(this.selected || []).forEach(function (value) {
itemHtmlList.push(this.getItemHtml(value));
}, this);
return _.extend({
selected: this.selected,
translatedOptions: this.translatedOptions,
hasOptions: this.params.options ? true : false
hasOptions: this.params.options ? true : false,
itemHtmlList: itemHtmlList
}, Dep.prototype.data.call(this));
},
@@ -143,8 +149,8 @@ Espo.define('Views.Fields.Array', 'Views.Fields.Enum', function (Dep) {
return item;
}, this).join(', ');
},
addValue: function (value) {
getItemHtml: function (value) {
if (this.translatedOptions != null) {
for (var item in this.translatedOptions) {
if (this.translatedOptions[item] == value) {
@@ -153,16 +159,21 @@ Espo.define('Views.Fields.Array', 'Views.Fields.Enum', function (Dep) {
}
}
}
if (this.selected.indexOf(value) == -1) {
var label = value;
if (this.translatedOptions) {
label = ((value in this.translatedOptions) ? this.translatedOptions [value]: value);
}
var html = '<div class="list-group-item" data-value="' + value + '">' + label +
'&nbsp;<a href="javascript:" class="pull-right" data-value="' + value + '" data-action="removeValue"><span class="glyphicon glyphicon-remove"></a>' +
'</div>';
var label = value;
if (this.translatedOptions) {
label = ((value in this.translatedOptions) ? this.translatedOptions [value]: value);
}
var html = '<div class="list-group-item" data-value="' + value + '">' + label +
'&nbsp;<a href="javascript:" class="pull-right" data-value="' + value + '" data-action="removeValue"><span class="glyphicon glyphicon-remove"></a>' +
'</div>';
return html;
},
addValue: function (value) {
if (this.selected.indexOf(value) == -1) {
var html = this.getItemHtml(value);
this.$list.append(html);
this.selected.push(value);
this.trigger('change');