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

104 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-08-24 11:16:11 +00:00
import ngModule from '../module';
2020-04-25 09:50:04 +00:00
import Descriptor from 'salix/components/descriptor';
2018-08-24 11:16:11 +00:00
2020-04-25 09:50:04 +00:00
class Controller extends Descriptor {
2020-03-18 13:08:04 +00:00
constructor($element, $, $httpParamSerializer) {
super($element, $);
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.$.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
}
2019-02-12 06:42:19 +00:00
showPickupOrder() {
const params = {
clientId: this.claim.clientFk,
claimId: this.claim.id,
authorization: this.vnToken.token
};
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.$.confirmPickupOrder.show();
2019-02-12 06:42:19 +00:00
}
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
};
this.$http.get(`email/claim-pickup-order`, {params}).then(
2020-04-25 09:50:04 +00:00
() => this.vnApp.showMessage(this.$t('Notification sent!'))
2019-01-25 14:08:11 +00:00
);
}
}
2019-09-06 09:06:44 +00:00
confirmDeleteClaim() {
this.$.confirmDeleteClaim.show();
2019-09-06 09:06:44 +00:00
}
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 = ['$element', '$scope', '$httpParamSerializer'];
2018-08-24 11:16:11 +00:00
2020-04-25 09:50:04 +00:00
ngModule.vnComponent('vnClaimDescriptor', {
2018-08-24 11:16:11 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
claim: '<',
2020-04-25 09:50:04 +00:00
tags: '<'
2018-08-24 11:16:11 +00:00
}
});