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

102 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-08-24 11:16:11 +00:00
import ngModule from '../module';
class Controller {
constructor($scope, $state, $http, $translate, vnApp, aclService) {
2019-01-25 14:08:11 +00:00
this.$scope = $scope;
2018-08-24 11:16:11 +00:00
this.$state = $state;
2019-01-25 14:08:11 +00:00
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
this.aclService = aclService;
2019-01-25 14:08:11 +00:00
this.moreOptions = [
2019-02-12 06:42:19 +00:00
{callback: this.showPickupOrder, name: 'Show Pickup order'},
{callback: this.confirmPickupOrder, name: 'Send Pickup order'},
{callback: this.confirmDeleteClaim, name: 'Delete claim', acl: 'salesAssistant'}
2019-01-25 14:08:11 +00:00
];
2018-10-03 06:00:19 +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;
}
onMoreChange(callback) {
callback.call(this);
}
2018-10-03 06:00:19 +00:00
get claim() {
return this._claim;
}
set claim(value) {
this._claim = value;
if (!value) return;
this._quicklinks = {
btnOne: {
icon: 'person',
state: `client.card.summary({id: ${value.clientFk}})`,
tooltip: 'Client card'
2019-01-30 07:44:15 +00:00
},
btnTwo: {
icon: 'icon-ticket',
state: `ticket.card.summary({id: ${this.claim.ticketFk}})`,
tooltip: 'Claimed ticket'
2018-10-03 06:00:19 +00:00
}
};
2018-08-24 11:16:11 +00:00
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
2019-01-25 14:08:11 +00:00
2019-02-12 06:42:19 +00:00
showPickupOrder() {
let url = `/api/report/rpt-claim-pickup-order?claimFk=${this.claim.id}`;
window.open(url);
2019-01-25 14:08:11 +00:00
}
2019-02-12 06:42:19 +00:00
confirmPickupOrder() {
this.$scope.confirmPickupOrder.show();
}
confirmDeleteClaim() {
this.$scope.confirmDeleteClaim.show();
}
2019-02-12 06:42:19 +00:00
sendPickupOrder(response) {
if (response === 'ACCEPT') {
2019-01-28 11:28:22 +00:00
this.$http.post(`/api/email/claim-pickup-order`, {claimFk: this.claim.id}).then(
2019-01-25 14:08:11 +00:00
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
);
}
}
deleteClaim(response) {
if (response === 'ACCEPT') {
this.$http.delete(`/claim/api/Claims/${this.claim.id}`).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Claim deleted!'));
this.$state.go('claim.index');
});
}
}
2018-08-24 11:16:11 +00:00
}
Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp', 'aclService'];
2018-08-24 11:16:11 +00:00
ngModule.component('vnClaimDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
claim: '<',
tags: '<',
quicklinks: '<'
}
});