From 345f2e55a5345f18597eadd08f04564da142e898 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 24 May 2017 13:24:32 +0200 Subject: [PATCH] vnAutocomplete: Acepta plantillas --- client/client/src/basic-data/index.html | 4 ++ client/client/src/index/index.js | 6 +-- client/core/src/autocomplete/index.js | 48 ++++++++++++++++++--- services/client/common/models/Employee.json | 4 ++ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/client/client/src/basic-data/index.html b/client/client/src/basic-data/index.html index 9fad9255b..8829d89b2 100644 --- a/client/client/src/basic-data/index.html +++ b/client/client/src/basic-data/index.html @@ -27,7 +27,11 @@ url="/client/api/Employees" show-field="name" value-field="id" + select-fields="surname" label="Comercial"> + + {{::i.name}} {{::i.surname}} + { + scope[this.itemAs] = data[i]; + li.appendChild(clone[0]); + this.scopes[i] = scope; + }, null, 'itemTemplate'); + } else { + let text = this.document.createTextNode(data[i][this.showField]); + li.appendChild(text); + } } if (this.moreData) { @@ -189,6 +211,7 @@ export default class Autocomplete extends Component { if (!this.popover) return; this.activeOption = -1; this.vnPopover.hide(); + this.destroyScopes(); this.popover = null; } selectPopoverOption(index) { @@ -200,9 +223,17 @@ export default class Autocomplete extends Component { this.requestData(this.lastRequest, true); } onPopoverClick(event) { + let target = event.target; let childs = this.popover.childNodes; + + if (target === this.popover) + return; + + while (target.parentNode !== this.popover) + target = target.parentNode; + for (let i = 0; i < childs.length; i++) - if (childs[i] === event.target) { + if (childs[i] === target) { this.selectPopoverOption(i); break; } @@ -362,8 +393,11 @@ export default class Autocomplete extends Component { this.item = item; this.mdlUpdate(); } + $onDestroy() { + this.destroyScopes(); + } } -Autocomplete.$inject = ['$element', '$scope', '$http', 'vnPopover']; +Autocomplete.$inject = ['$element', '$scope', '$http', 'vnPopover', '$transclude']; module.component('vnAutocomplete', { template: require('./index.html'), @@ -373,8 +407,12 @@ module.component('vnAutocomplete', { valueField: '@?', selectFields: '@?', initialData: '