salix/modules/ticket/front/dms/edit/index.js

94 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2019-07-15 09:40:11 +00:00
import ngModule from '../../module';
2020-03-18 07:35:59 +00:00
import Section from 'salix/components/section';
2019-07-15 09:40:11 +00:00
2020-03-18 07:35:59 +00:00
class Controller extends Section {
2019-07-15 09:40:11 +00:00
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (value) {
2019-07-15 09:40:11 +00:00
this.setDefaultParams();
this.getAllowedContentTypes();
}
}
getAllowedContentTypes() {
2020-12-18 16:23:04 +00:00
this.$http.get('DmsContainers/allowedContentTypes').then(res => {
const contentTypes = res.data.join(', ');
this.allowedContentTypes = contentTypes;
});
}
get contentTypesInfo() {
return this.$t('ContentTypesInfo', {
allowedContentTypes: this.allowedContentTypes
});
2019-07-15 09:40:11 +00:00
}
setDefaultParams() {
2020-03-18 07:35:59 +00:00
const path = `Dms/${this.$params.dmsId}`;
2019-07-15 09:40:11 +00:00
this.$http.get(path).then(res => {
const dms = res.data && res.data;
this.dms = {
reference: dms.reference,
warehouseId: dms.warehouseFk,
companyId: dms.companyFk,
dmsTypeId: dms.dmsTypeFk,
description: dms.description,
hasFile: dms.hasFile,
2019-07-16 12:12:58 +00:00
hasFileAttached: false,
2019-07-15 09:40:11 +00:00
files: []
};
});
}
onSubmit() {
2020-03-18 07:35:59 +00:00
const query = `dms/${this.$params.dmsId}/updateFile`;
2019-07-15 09:40: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) {
this.vnApp.showSuccess(this.$t('Data saved!'));
2019-07-15 09:40: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-07-15 09:40:11 +00:00
}
}
ngModule.vnComponent('vnTicketDmsEdit', {
2019-07-15 09:40:11 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
}
});