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

117 lines
3.4 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, $httpParamSerializer) {
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;
this.$httpParamSerializer = $httpParamSerializer;
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() {
const params = {
clientId: this.claim.clientFk,
claimId: this.claim.id
};
const serializedParams = this.$httpParamSerializer(params);
let url = `api/report/claim-pickup-order?${serializedParams}`;
2019-02-12 06:42:19 +00:00
window.open(url);
2019-01-25 14:08:11 +00:00
}
2019-02-12 06:42:19 +00:00
confirmPickupOrder() {
this.$scope.confirmPickupOrder.show();
}
sendPickupOrder(response) {
2019-10-30 15:57:14 +00:00
if (response === 'accept') {
const params = {
recipient: this.claim.client.email,
clientId: this.claim.clientFk,
claimId: this.claim.id
};
const serializedParams = this.$httpParamSerializer(params);
const url = `email/claim-pickup-order?${serializedParams}`;
this.$http.get(url).then(
2019-01-25 14:08:11 +00:00
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
);
}
}
2019-09-06 09:06:44 +00:00
confirmDeleteClaim() {
this.$scope.confirmDeleteClaim.show();
}
deleteClaim(response) {
2019-10-30 15:57:14 +00:00
if (response === 'accept') {
this.$http.delete(`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', '$httpParamSerializer'];
2018-08-24 11:16:11 +00:00
ngModule.component('vnClaimDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
claim: '<',
tags: '<',
quicklinks: '<'
}
});