salix/modules/travel/front/thermograph/edit/index.js

85 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-02-28 07:19:20 +00:00
import ngModule from '../../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
2020-02-28 08:21:00 +00:00
get travel() {
return this._travel;
2020-02-28 07:19:20 +00:00
}
2020-02-28 08:21:00 +00:00
set travel(value) {
this._travel = value;
2020-02-28 07:19:20 +00:00
if (value) {
this.setDefaultParams();
this.getAllowedContentTypes();
}
}
getAllowedContentTypes() {
2020-02-28 08:21:00 +00:00
this.$http.get('TravelThermographs/allowedContentTypes').then(res => {
2020-02-28 07:19:20 +00:00
const contentTypes = res.data.join(', ');
this.allowedContentTypes = contentTypes;
});
}
get contentTypesInfo() {
return this.$translate.instant('ContentTypesInfo', {
allowedContentTypes: this.allowedContentTypes
});
}
setDefaultParams() {
const path = `Dms/${this.$params.dmsId}`;
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,
hasFileAttached: false,
files: []
};
});
}
onSubmit() {
const query = `dms/${this.$params.dmsId}/updateFile`;
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.$translate.instant('Data saved!'));
this.$.watcher.updateOriginalData();
this.$state.go('worker.card.dms.index');
}
});
}
}
ngModule.component('vnTravelThermographEdit', {
template: require('./index.html'),
controller: Controller,
bindings: {
2020-02-28 08:21:00 +00:00
travel: '<'
2020-02-28 07:19:20 +00:00
}
});