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

99 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-02-28 07:19:20 +00:00
import ngModule from '../../module';
2020-03-18 11:55:22 +00:00
import Section from 'salix/components/section';
2020-02-28 07:19:20 +00:00
import './style.scss';
2020-03-18 11:55:22 +00:00
class Controller extends Section {
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() {
2020-02-28 13:18:55 +00:00
const filterObj = {include: {relation: 'dms'}};
const filter = encodeURIComponent(JSON.stringify(filterObj));
const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`;
2020-02-28 07:19:20 +00:00
this.$http.get(path).then(res => {
2020-02-28 13:18:55 +00:00
const thermograph = res.data && res.data;
this.thermograph = {
thermographId: thermograph.thermographFk,
state: thermograph.result,
reference: thermograph.dms.reference,
warehouseId: thermograph.dms.warehouseFk,
companyId: thermograph.dms.companyFk,
dmsTypeId: thermograph.dms.dmsTypeFk,
description: thermograph.dms.description,
hasFile: thermograph.dms.hasFile,
2020-02-28 07:19:20 +00:00
hasFileAttached: false,
files: []
};
});
}
onSubmit() {
2020-02-28 13:18:55 +00:00
const query = `travels/${this.$params.id}/updateThermograph`;
2020-02-28 07:19:20 +00:00
const options = {
method: 'POST',
url: query,
2020-02-28 13:18:55 +00:00
params: this.thermograph,
2020-02-28 07:19:20 +00:00
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;
},
2020-02-28 13:18:55 +00:00
data: this.thermograph.files
2020-02-28 07:19:20 +00:00
};
this.$http(options).then(res => {
if (res) {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.$.watcher.updateOriginalData();
2020-02-28 13:18:55 +00:00
this.$state.go('travel.card.thermograph.index');
2020-02-28 07:19:20 +00:00
}
});
}
2020-02-28 13:18:55 +00:00
onFileChange(files) {
let hasFileAttached = false;
if (files.length > 0)
hasFileAttached = true;
this.$.$applyAsync(() => {
this.thermograph.hasFileAttached = hasFileAttached;
});
}
2020-02-28 07:19:20 +00:00
}
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
}
});