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

103 lines
2.8 KiB
JavaScript

import ngModule from '../module';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.moreOptions = [
{
name: 'Show invoice PDF',
callback: this.showInvoiceOutPdf
}, {
name: 'Delete Invoice',
callback: this.showDeleteInvoiceOutDialog,
acl: 'invoicing'
}, {
name: 'Book invoice',
callback: this.showBookInvoiceOutDialog,
acl: 'invoicing'
}
];
}
onMoreOpen() {
let options = this.moreOptions.filter(option => {
const hasAclProperty = Object.hasOwnProperty.call(option, 'acl');
return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
});
this.$.moreButton.data = options;
}
onMoreChange(callback) {
callback.call(this);
}
set invoiceOut(value) {
this._invoiceOut = value;
if (value) {
this._quicklinks = {
btnOne: {
icon: 'icon-person',
state: `client.card.summary({id: ${value.clientFk}})`,
tooltip: 'Client card'
},
btnTwo: {
icon: 'icon-ticket',
state: `ticket.index({q: '{"refFk": "${value.ref}"}'})`,
tooltip: 'Invoice ticket list'
}
};
}
}
get invoiceOut() {
return this._invoiceOut;
}
showInvoiceOutPdf() {
let url = `api/InvoiceOuts/${this.invoiceOut.id}/download?access_token=${this.accessToken}`;
window.open(url, '_blank');
}
showDeleteInvoiceOutDialog() {
this.$.deleteConfirmation.show();
}
showBookInvoiceOutDialog() {
this.$.bookConfirmation.show();
}
deleteInvoiceOut() {
const query = `InvoiceOuts/${this.invoiceOut.id}/delete`;
return this.$http.post(query)
.then(() => this.$state.go('invoiceOut.index'))
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
}
bookInvoiceOut() {
const query = `InvoiceOuts/${this.invoiceOut.ref}/book`;
return this.$http.post(query)
.then(() => this.$state.reload())
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked')));
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
}
ngModule.component('vnInvoiceOutDescriptor', {
template: require('./index.html'),
bindings: {
invoiceOut: '<',
quicklinks: '<'
},
controller: Controller
});