Dropdown ahora acepta traducciones CR Juan
This commit is contained in:
parent
1ecb3f3d2b
commit
f2596af6b8
|
@ -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: '<?',
|
||||
showFilter: '<?',
|
||||
multiple: '<?',
|
||||
field: '=?',
|
||||
data: '<?',
|
||||
selection: '=?',
|
||||
search: '<?',
|
||||
limit: '<?',
|
||||
showFilter: '<?',
|
||||
parent: '<?',
|
||||
onSelect: '&?'
|
||||
multiple: '<?',
|
||||
onSelect: '&?',
|
||||
translateFields: '<?'
|
||||
},
|
||||
transclude: {
|
||||
tplItem: '?tplItem'
|
||||
|
|
Loading…
Reference in New Issue