2019-06-06 11:59:11 +00:00
|
|
|
import ngModule from '../../module';
|
2023-12-12 14:03:00 +00:00
|
|
|
import SectionDms from 'salix/components/section-dms';
|
2019-06-06 11:59:11 +00:00
|
|
|
|
2023-12-12 14:03:00 +00:00
|
|
|
class Controller extends SectionDms {
|
2020-03-18 07:35:59 +00:00
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2019-06-06 11:59:11 +00:00
|
|
|
this.dms = {
|
|
|
|
files: [],
|
2019-07-16 11:37:25 +00:00
|
|
|
hasFile: false,
|
2019-07-16 12:12:58 +00:00
|
|
|
hasFileAttached: false
|
2019-06-06 11:59:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = value;
|
|
|
|
|
2019-08-08 06:37:03 +00:00
|
|
|
if (value) {
|
2023-12-12 14:03:00 +00:00
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'ticket'}
|
|
|
|
}};
|
|
|
|
this.getDmsTypes(params).then(res => this.handleDefaultParams(res));
|
|
|
|
this.getAllowedContentTypes().then(data => this.allowedContentTypes = data);
|
2019-08-08 06:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get contentTypesInfo() {
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.$t('ContentTypesInfo', {
|
2019-08-08 06:37:03 +00:00
|
|
|
allowedContentTypes: this.allowedContentTypes
|
|
|
|
});
|
2019-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
2023-12-12 14:03:00 +00:00
|
|
|
handleDefaultParams(data) {
|
|
|
|
const dmsTypeId = res?.data?.id;
|
|
|
|
const warehouseId = this.vnConfig.warehouseFk;
|
|
|
|
const defaultParams = {
|
|
|
|
reference: this.ticket.id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: this.ticket.companyFk,
|
|
|
|
dmsTypeId: dmsTypeId,
|
|
|
|
description: this.$t('FileDescription', {
|
|
|
|
ticketId: this.ticket.id,
|
|
|
|
clientId: this.ticket.client.id,
|
|
|
|
clientName: this.ticket.client.name
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
2019-06-06 11:59:11 +00:00
|
|
|
|
2023-12-12 14:03:00 +00:00
|
|
|
this.dms = Object.assign(this.dms, defaultParams);
|
2019-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `tickets/${this.ticket.id}/uploadFile`;
|
2019-06-06 11:59:11 +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(res => {
|
|
|
|
if (res) {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-06-06 11:59:11 +00:00
|
|
|
this.$.watcher.updateOriginalData();
|
|
|
|
this.$state.go('ticket.card.dms.index');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileChange(files) {
|
2019-07-16 12:12:58 +00:00
|
|
|
let hasFileAttached = false;
|
2019-07-16 11:37:25 +00:00
|
|
|
if (files.length > 0)
|
2019-07-16 12:12:58 +00:00
|
|
|
hasFileAttached = true;
|
2019-07-16 11:37:25 +00:00
|
|
|
|
|
|
|
this.$.$applyAsync(() => {
|
2019-07-16 12:12:58 +00:00
|
|
|
this.dms.hasFileAttached = hasFileAttached;
|
2019-07-16 11:37:25 +00:00
|
|
|
});
|
2019-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTicketDmsCreate', {
|
2019-06-06 11:59:11 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<'
|
|
|
|
}
|
|
|
|
});
|