salix/modules/invoiceOut/front/descriptor-popover/index.js

82 lines
1.9 KiB
JavaScript

import ngModule from '../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
constructor($element, $scope, $http, $timeout, $q) {
super($element, $scope);
this.$timeout = $timeout;
this.$http = $http;
this.$q = $q;
this.worker = null;
this._quicklinks = {};
}
set invoiceOutId(id) {
if (id == this._invoiceOutId) return;
this._invoiceOutId = id;
this.invoiceOut = null;
this.loadData();
}
get invoiceOutId() {
return this._invoiceOutId;
}
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 = `InvoiceOuts/findOne`;
let filter = {
where: {
id: this._invoiceOutId
},
include: [
{
relation: 'company',
scope: {
fields: ['id', 'code']
}
},
{
relation: 'client',
scope: {
fields: ['id', 'name']
}
}
]
};
this.$http.get(query, {params: {filter}}).then(res => {
this.invoiceOut = res.data;
this.$.$applyAsync(() => {
this.$.popover.relocate();
});
});
}
}
Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q'];
ngModule.component('vnInvoiceOutDescriptorPopover', {
template: require('./index.html'),
controller: Controller,
bindings: {
invoiceOutId: '<',
quicklinks: '<'
}
});