From f2596af6b82dc83bb76d341a3048bc1535c0823b Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 19 Jun 2018 09:06:04 +0200 Subject: [PATCH] Dropdown ahora acepta traducciones CR Juan --- .../src/components/drop-down/drop-down.js | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/client/core/src/components/drop-down/drop-down.js b/client/core/src/components/drop-down/drop-down.js index 12b07b586..67ea8f511 100755 --- a/client/core/src/components/drop-down/drop-down.js +++ b/client/core/src/components/drop-down/drop-down.js @@ -1,12 +1,14 @@ import ngModule from '../../module'; import Component from '../../lib/component'; import './style.scss'; +//import './model-proxy/model-proxy'; export default class DropDown extends Component { - constructor($element, $scope, $transclude, $timeout, $http) { + constructor($element, $scope, $transclude, $timeout, $http, $translate) { super($element, $scope); this.$transclude = $transclude; this.$timeout = $timeout; + this.$translate = $translate; this.valueField = 'id'; this.showField = 'name'; @@ -284,13 +286,20 @@ export default class DropDown extends Component { buildList() { this.destroyList(); - let hasTemplate = this.$transclude && - this.$transclude.isSlotFilled('tplItem'); + let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem'); let fragment = this.document.createDocumentFragment(); let data = this.$.model.data; if (data) { for (let i = 0; i < data.length; i++) { + let option = data[i]; + + if (this.translateFields) { + option = Object.assign({}, option); + for (let field of this.translateFields) + option[field] = this.$translate.instant(option[field]); + } + let li = this.document.createElement('li'); fragment.appendChild(li); @@ -299,18 +308,18 @@ export default class DropDown extends Component { check.type = 'checkbox'; li.appendChild(check); - if (this.field && this.field.indexOf(data[i][this.valueField]) != -1) + if (this.field && this.field.indexOf(option[this.valueField]) != -1) check.checked = true; } if (hasTemplate) { this.$transclude((clone, scope) => { - Object.assign(scope, data[i]); + Object.assign(scope, option); li.appendChild(clone[0]); this.scopes[i] = scope; }, null, 'tplItem'); } else { - let text = this.document.createTextNode(data[i][this.showField]); + let text = this.document.createTextNode(option[this.showField]); li.appendChild(text); } } @@ -335,7 +344,7 @@ export default class DropDown extends Component { this.destroyList(); } } -DropDown.$inject = ['$element', '$scope', '$transclude', '$timeout', '$http']; +DropDown.$inject = ['$element', '$scope', '$transclude', '$timeout', '$http', '$translate']; /** * Gets the position of an event element relative to a parent. @@ -365,19 +374,16 @@ ngModule.component('vnDropDown', { template: require('./drop-down.html'), controller: DropDown, bindings: { - showField: '@?', - valueField: '@?', - where: '@?', - order: '@?', - limit: '