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

100 lines
2.2 KiB
JavaScript

import ngModule from '../module';
import Summary from 'salix/components/summary';
import './style.scss';
class Controller extends Summary {
constructor($element, $, vnFile) {
super($element, $);
this.vnFile = vnFile;
}
$onChanges() {
if (this.claim && this.claim.id)
this.getSummary();
}
loadData() {
this.getSummary();
}
reload() {
if (this.card) {
console.log('CARD');
this.card.reload();
}
if (this.parentReload)
this.parentReload();
}
get isSalesPerson() {
return this.aclService.hasAny(['salesPerson']);
}
get isClaimManager() {
return this.aclService.hasAny(['claimManager']);
}
get claim() {
return this._claim;
}
set claim(value) {
this._claim = value;
// Get DMS on summary load
if (value) {
this.$.$applyAsync(() => this.loadDms());
this.loadData();
}
}
loadDms() {
this.$.model.where = {
claimFk: this.claim.id
};
this.$.model.refresh();
}
getSummary() {
this.$http.get(`Claims/${this.claim.id}/getSummary`).then(response => {
this.summary = response.data;
});
this.$http.get(`Claims/${this.claim.id}/isEditable`).then(response => {
this.isEditable = response.data;
});
}
getImagePath(dmsId) {
return this.vnFile.getPath(`/api/dms/${dmsId}/downloadFile`);
}
changeState(value) {
const params = {
id: this.claim.id,
claimStateFk: value
};
this.$http.patch(`Claims/updateClaim/${this.claim.id}`, params)
.then(() => {
this.reload();
})
.then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
Controller.$inject = ['$element', '$scope', 'vnFile'];
ngModule.vnComponent('vnClaimSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
claim: '<',
model: '<?',
parentReload: '&'
},
require: {
card: '?^vnClaimCard'
}
});