import ngModule from '../module'; import Component from 'core/lib/component'; class Controller extends Component { constructor($element, $) { super($element, $); this.travel = null; this._quicklinks = {}; } set travelId(travelId) { if (travelId == this._travelId) return; this._travelId = travelId; this.travel = null; this.loadData(); } get travelId() { return this._travelId; } get quicklinks() { return this._quicklinks; } set quicklinks(value = {}) { Object.keys(value).forEach(key => { this._quicklinks[key] = value[key]; }); } show() { this.$.popover.parent = this.parent; this.$.popover.show(); } loadData() { let query = `Travels/findOne`; let filter = { fields: [ 'id', 'ref', 'shipped', 'landed', 'totalEntries', 'warehouseInFk', 'warehouseOutFk' ], where: { id: this._travelId }, include: [ { relation: 'warehouseIn', scope: { fields: ['name'] } }, { relation: 'warehouseOut', scope: { fields: ['name'] } } ] }; this.$http.get(query, {params: {filter}}).then(res => { this.travel = res.data; this.$.$applyAsync(() => { this.$.popover.relocate(); }); }); } } ngModule.component('vnTravelDescriptorPopover', { template: require('./index.html'), controller: Controller, bindings: { travelId: '<', quicklinks: '<' } });