Dropdown ahora acepta traducciones CR Juan
This commit is contained in:
parent
1ecb3f3d2b
commit
f2596af6b8
|
@ -1,12 +1,14 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
import Component from '../../lib/component';
|
import Component from '../../lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
//import './model-proxy/model-proxy';
|
||||||
|
|
||||||
export default class DropDown extends Component {
|
export default class DropDown extends Component {
|
||||||
constructor($element, $scope, $transclude, $timeout, $http) {
|
constructor($element, $scope, $transclude, $timeout, $http, $translate) {
|
||||||
super($element, $scope);
|
super($element, $scope);
|
||||||
this.$transclude = $transclude;
|
this.$transclude = $transclude;
|
||||||
this.$timeout = $timeout;
|
this.$timeout = $timeout;
|
||||||
|
this.$translate = $translate;
|
||||||
|
|
||||||
this.valueField = 'id';
|
this.valueField = 'id';
|
||||||
this.showField = 'name';
|
this.showField = 'name';
|
||||||
|
@ -284,13 +286,20 @@ export default class DropDown extends Component {
|
||||||
buildList() {
|
buildList() {
|
||||||
this.destroyList();
|
this.destroyList();
|
||||||
|
|
||||||
let hasTemplate = this.$transclude &&
|
let hasTemplate = this.$transclude && this.$transclude.isSlotFilled('tplItem');
|
||||||
this.$transclude.isSlotFilled('tplItem');
|
|
||||||
let fragment = this.document.createDocumentFragment();
|
let fragment = this.document.createDocumentFragment();
|
||||||
let data = this.$.model.data;
|
let data = this.$.model.data;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
for (let i = 0; i < data.length; i++) {
|
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');
|
let li = this.document.createElement('li');
|
||||||
fragment.appendChild(li);
|
fragment.appendChild(li);
|
||||||
|
|
||||||
|
@ -299,18 +308,18 @@ export default class DropDown extends Component {
|
||||||
check.type = 'checkbox';
|
check.type = 'checkbox';
|
||||||
li.appendChild(check);
|
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;
|
check.checked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasTemplate) {
|
if (hasTemplate) {
|
||||||
this.$transclude((clone, scope) => {
|
this.$transclude((clone, scope) => {
|
||||||
Object.assign(scope, data[i]);
|
Object.assign(scope, option);
|
||||||
li.appendChild(clone[0]);
|
li.appendChild(clone[0]);
|
||||||
this.scopes[i] = scope;
|
this.scopes[i] = scope;
|
||||||
}, null, 'tplItem');
|
}, null, 'tplItem');
|
||||||
} else {
|
} else {
|
||||||
let text = this.document.createTextNode(data[i][this.showField]);
|
let text = this.document.createTextNode(option[this.showField]);
|
||||||
li.appendChild(text);
|
li.appendChild(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +344,7 @@ export default class DropDown extends Component {
|
||||||
this.destroyList();
|
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.
|
* Gets the position of an event element relative to a parent.
|
||||||
|
@ -365,19 +374,16 @@ ngModule.component('vnDropDown', {
|
||||||
template: require('./drop-down.html'),
|
template: require('./drop-down.html'),
|
||||||
controller: DropDown,
|
controller: DropDown,
|
||||||
bindings: {
|
bindings: {
|
||||||
showField: '@?',
|
|
||||||
valueField: '@?',
|
|
||||||
where: '@?',
|
|
||||||
order: '@?',
|
|
||||||
limit: '<?',
|
|
||||||
showFilter: '<?',
|
|
||||||
multiple: '<?',
|
|
||||||
field: '=?',
|
field: '=?',
|
||||||
data: '<?',
|
data: '<?',
|
||||||
selection: '=?',
|
selection: '=?',
|
||||||
search: '<?',
|
search: '<?',
|
||||||
|
limit: '<?',
|
||||||
|
showFilter: '<?',
|
||||||
parent: '<?',
|
parent: '<?',
|
||||||
onSelect: '&?'
|
multiple: '<?',
|
||||||
|
onSelect: '&?',
|
||||||
|
translateFields: '<?'
|
||||||
},
|
},
|
||||||
transclude: {
|
transclude: {
|
||||||
tplItem: '?tplItem'
|
tplItem: '?tplItem'
|
||||||
|
|
Loading…
Reference in New Issue