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

102 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-03-26 13:27:08 +00:00
import ngModule from '../module';
2020-03-17 13:43:46 +00:00
import Component from 'core/lib/component';
2019-03-26 13:27:08 +00:00
2020-03-17 13:43:46 +00:00
class Controller extends Component {
constructor($element, $) {
super($element, $);
2019-04-18 09:47:31 +00:00
this.moreOptions = [
{callback: this.showInvoiceOutPdf, name: 'Show invoice PDF'},
{callback: this.showDeleteInvoiceOutDialog, name: 'Delete Invoice', acl: 'invoicing'},
{callback: this.showBookInvoiceOutDialog, name: 'Book invoice', acl: 'invoicing'}
2019-04-18 09:47:31 +00:00
];
}
onMoreOpen() {
let options = this.moreOptions.filter(option => {
const hasAclProperty = Object.hasOwnProperty.call(option, 'acl');
return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl]));
});
this.$scope.moreButton.data = options;
}
2019-04-18 09:47:31 +00:00
onMoreChange(callback) {
callback.call(this);
}
2019-03-26 13:27:08 +00:00
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;
}
2019-04-18 09:47:31 +00:00
showInvoiceOutPdf() {
2019-12-24 09:17:41 +00:00
let url = `api/InvoiceOuts/${this.invoiceOut.id}/download?access_token=${this.accessToken}`;
2019-04-18 09:47:31 +00:00
window.open(url, '_blank');
}
showDeleteInvoiceOutDialog() {
2020-03-17 13:43:46 +00:00
this.$.deleteConfirmation.show();
}
showBookInvoiceOutDialog() {
2020-03-17 13:43:46 +00:00
this.$.bookConfirmation.show();
}
deleteInvoiceOut(response) {
2019-10-30 15:57:14 +00:00
if (response === 'accept') {
const query = `InvoiceOuts/${this.invoiceOut.id}/delete`;
this.$http.post(query).then(() => {
this.vnApp.showSuccess(this.$translate.instant('InvoiceOut deleted'));
this.$state.go('invoiceOut.index');
});
}
}
bookInvoiceOut(response) {
2019-10-30 15:57:14 +00:00
if (response === 'accept') {
const query = `InvoiceOuts/${this.invoiceOut.ref}/book`;
this.$http.post(query).then(() => {
this.vnApp.showSuccess(this.$translate.instant('InvoiceOut booked'));
this.$state.reload();
});
}
}
2019-03-26 13:27:08 +00:00
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
}
2020-03-17 13:43:46 +00:00
Controller.$inject = ['$element', '$scope'];
2019-03-26 13:27:08 +00:00
ngModule.component('vnInvoiceOutDescriptor', {
template: require('./index.html'),
bindings: {
invoiceOut: '<',
quicklinks: '<'
},
controller: Controller
});