2019-07-30 06:51:38 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
constructor($stateParams, $scope, $http, $translate, vnToken, vnApp) {
|
|
|
|
this.$stateParams = $stateParams;
|
|
|
|
this.$ = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.accessToken = vnToken.token;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
showWorkerDescriptor(event, workerFk) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
this.$.workerDescriptor.parent = event.target;
|
|
|
|
this.$.workerDescriptor.workerFk = workerFk;
|
|
|
|
this.$.workerDescriptor.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
showDeleteConfirm(index) {
|
|
|
|
this.dmsIndex = index;
|
|
|
|
this.$.confirm.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteDms(response) {
|
|
|
|
if (response === 'ACCEPT') {
|
2019-09-30 12:57:54 +00:00
|
|
|
const dmsFk = this.photos[this.dmsIndex].dmsFk;
|
2019-07-30 06:51:38 +00:00
|
|
|
const query = `/api/claimDms/${dmsFk}/removeFile`;
|
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.$.model.remove(this.dmsIndex);
|
2019-09-30 12:57:54 +00:00
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Photo deleted'));
|
2019-07-30 06:51:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-09-30 12:57:54 +00:00
|
|
|
|
|
|
|
onDrop(event) {
|
|
|
|
const files = event.dataTransfer.files;
|
|
|
|
this.setDefaultParams().then(() => {
|
|
|
|
this.dms.files = files;
|
|
|
|
this.create();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'claim'}
|
|
|
|
}};
|
|
|
|
return this.$http.get('/api/DmsTypes/findOne', {params}).then(res => {
|
|
|
|
const dmsTypeId = res.data && res.data.id;
|
|
|
|
const companyId = window.localStorage.defaultCompanyFk;
|
|
|
|
const warehouseId = window.localStorage.defaultWarehouseFk;
|
|
|
|
this.dms = {
|
|
|
|
hasFile: false,
|
|
|
|
hasFileAttached: false,
|
|
|
|
reference: this.claim.id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: companyId,
|
|
|
|
dmsTypeId: dmsTypeId,
|
|
|
|
description: this.$translate.instant('FileDescription', {
|
|
|
|
claimId: this.claim.id,
|
|
|
|
clientId: this.claim.client.id,
|
|
|
|
clientName: this.claim.client.name
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
create() {
|
|
|
|
const query = `/api/claims/${this.claim.id}/uploadFile`;
|
|
|
|
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(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Photo uploaded!'));
|
|
|
|
this.$.model.refresh();
|
|
|
|
});
|
|
|
|
}
|
2019-07-30 06:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnToken', 'vnApp'];
|
|
|
|
|
|
|
|
ngModule.component('vnClaimDmsIndex', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
2019-09-30 12:57:54 +00:00
|
|
|
bindings: {
|
|
|
|
claim: '<'
|
|
|
|
}
|
2019-07-30 06:51:38 +00:00
|
|
|
});
|