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

92 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-03-26 13:27:08 +00:00
import ngModule from '../module';
class Controller {
constructor($scope, vnToken, vnApp, $state, $translate, $http, aclService) {
this.$scope = $scope;
2019-04-18 09:47:31 +00:00
this.accessToken = vnToken.token;
this.vnApp = vnApp;
this.$state = $state;
this.$translate = $translate;
this.$http = $http;
this.aclService = aclService;
2019-04-18 09:47:31 +00:00
this.moreOptions = [
{callback: this.showInvoiceOutPdf, name: 'Show invoice out PDF'},
{callback: this.showDeleteInvoiceOutDialog, name: 'Delete InvoiceOut', 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() {
let url = `api/InvoiceOuts/${this.invoiceOut.id}/download?access_token=${this.accessToken}`;
window.open(url, '_blank');
}
showDeleteInvoiceOutDialog() {
this.$scope.deleteConfirmation.show();
}
deleteInvoiceOut(response) {
if (response === 'ACCEPT') {
const query = `/invoiceOut/api/InvoiceOuts/${this.invoiceOut.id}/delete`;
this.$http.post(query).then(() => {
this.vnApp.showSuccess(this.$translate.instant('InvoiceOut deleted'));
this.$state.go('invoiceOut.index');
});
}
}
2019-03-26 13:27:08 +00:00
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
}
Controller.$inject = ['$scope', 'vnToken', 'vnApp', '$state', '$translate', '$http', 'aclService'];
2019-03-26 13:27:08 +00:00
ngModule.component('vnInvoiceOutDescriptor', {
template: require('./index.html'),
bindings: {
invoiceOut: '<',
quicklinks: '<'
},
controller: Controller
});