2020-01-10 10:29:11 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-16 10:58:14 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-07-30 06:51:38 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-16 10:58:14 +00:00
|
|
|
class Controller extends Section {
|
2020-04-28 12:26:02 +00:00
|
|
|
deleteDms(index) {
|
|
|
|
const dmsFk = this.photos[index].dmsFk;
|
|
|
|
return this.$http.post(`ClaimDms/${dmsFk}/removeFile`)
|
|
|
|
.then(() => {
|
|
|
|
this.$.model.remove(index);
|
|
|
|
this.vnApp.showSuccess(this.$t('Photo deleted'));
|
2019-07-30 06:51:38 +00:00
|
|
|
});
|
|
|
|
}
|
2019-09-30 12:57:54 +00:00
|
|
|
|
2019-10-16 06:56:13 +00:00
|
|
|
onDrop($event) {
|
|
|
|
const files = $event.dataTransfer.files;
|
2019-09-30 12:57:54 +00:00
|
|
|
this.setDefaultParams().then(() => {
|
|
|
|
this.dms.files = files;
|
|
|
|
this.create();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
2020-04-28 12:26:02 +00:00
|
|
|
const filter = {
|
2019-09-30 12:57:54 +00:00
|
|
|
where: {code: 'claim'}
|
2020-04-28 12:26:02 +00:00
|
|
|
};
|
|
|
|
return this.$http.get('DmsTypes/findOne', {filter}).then(res => {
|
2019-09-30 12:57:54 +00:00
|
|
|
const dmsTypeId = res.data && res.data.id;
|
2019-10-09 22:47:29 +00:00
|
|
|
const companyId = this.vnConfig.companyFk;
|
|
|
|
const warehouseId = this.vnConfig.warehouseFk;
|
2019-09-30 12:57:54 +00:00
|
|
|
this.dms = {
|
|
|
|
hasFile: false,
|
|
|
|
hasFileAttached: false,
|
|
|
|
reference: this.claim.id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: companyId,
|
|
|
|
dmsTypeId: dmsTypeId,
|
2020-04-28 12:26:02 +00:00
|
|
|
description: this.$t('FileDescription', {
|
2019-09-30 12:57:54 +00:00
|
|
|
claimId: this.claim.id,
|
|
|
|
clientId: this.claim.client.id,
|
|
|
|
clientName: this.claim.client.name
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:03:08 +00:00
|
|
|
openUploadDialog() {
|
|
|
|
const element = document.createElement('input');
|
|
|
|
element.setAttribute('type', 'file');
|
|
|
|
element.setAttribute('multiple', true);
|
|
|
|
element.click();
|
|
|
|
|
|
|
|
element.addEventListener('change', () =>
|
|
|
|
this.setDefaultParams().then(() => {
|
|
|
|
this.dms.files = element.files;
|
|
|
|
this.create();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-30 12:57:54 +00:00
|
|
|
|
|
|
|
create() {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `claims/${this.claim.id}/uploadFile`;
|
2019-09-30 12:57:54 +00:00
|
|
|
const options = {
|
|
|
|
method: 'POST',
|
|
|
|
url: query,
|
|
|
|
params: this.dms,
|
|
|
|
headers: {'Content-Type': undefined},
|
|
|
|
transformRequest: files => {
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
|
|
for (let i = 0; i < files.length; i++)
|
|
|
|
formData.append(files[i].name, files[i]);
|
|
|
|
|
|
|
|
return formData;
|
|
|
|
},
|
|
|
|
data: this.dms.files
|
|
|
|
};
|
|
|
|
this.$http(options).then(() => {
|
2020-04-28 12:26:02 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Photo uploaded!'));
|
2019-09-30 12:57:54 +00:00
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
2019-07-30 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 10:29:11 +00:00
|
|
|
ngModule.component('vnClaimPhotos', {
|
2019-07-30 06:51:38 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
2019-09-30 12:57:54 +00:00
|
|
|
bindings: {
|
|
|
|
claim: '<'
|
|
|
|
}
|
2019-07-30 06:51:38 +00:00
|
|
|
});
|