import ngModule from '../module'; import Component from 'core/lib/component'; import './style.scss'; class Controller extends Component { constructor($element, $scope) { super($element, $scope); this.ticket = null; this._quicklinks = {}; } set ticketFk(id) { if (id == this._ticketFk) return; this._ticketFk = id; this.ticket = null; this.getCard(); } set ticket(value) { this._ticket = value; this.$timeout(() => this.$.popover.relocate()); } get ticket() { return this._ticket; } 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(); } getCard() { if (this.canceler) this.canceler.resolve(); this.canceler = this.$q.defer(); let options = {timeout: this.canceler.promise}; let filter = { include: [ { relation: 'warehouse', scope: { fields: ['name'] } }, { relation: 'agencyMode', scope: { fields: ['name'] } }, { relation: 'client', scope: { fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], include: { relation: 'salesPerson', scope: { fields: ['userFk'], include: { relation: 'user', scope: { fields: ['nickname'] } } } } } }, { relation: 'state', scope: { fields: ['stateFk'], include: { relation: 'state', fields: ['id', 'name'], } } } ] }; let json = encodeURIComponent(JSON.stringify(filter)); let query = `Tickets/${this._ticketFk}?filter=${json}`; this.$http.get(query, options).then( response => { this.ticket = response.data; this.canceler = null; } ); } } ngModule.component('vnTicketDescriptorPopover', { template: require('./index.html'), controller: Controller, bindings: { ticketFk: '<', quicklinks: '<' } });