2020-01-17 07:43:10 +00:00
|
|
|
import ngModule from '../../module';
|
2020-03-18 11:55:22 +00:00
|
|
|
import Section from 'salix/components/section';
|
2020-01-17 07:43:10 +00:00
|
|
|
|
2020-03-18 11:55:22 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2020-02-28 06:17:19 +00:00
|
|
|
this.dms = {files: [], state: 'Ok'};
|
2020-01-17 07:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get travel() {
|
|
|
|
return this._travel;
|
|
|
|
}
|
|
|
|
|
|
|
|
set travel(value) {
|
|
|
|
this._travel = value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
this.setDefaultParams();
|
|
|
|
this.getAllowedContentTypes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllowedContentTypes() {
|
2020-01-22 08:04:26 +00:00
|
|
|
this.$http.get('TravelThermographs/allowedContentTypes').then(res => {
|
2020-01-17 07:43:10 +00:00
|
|
|
const contentTypes = res.data.join(', ');
|
|
|
|
this.allowedContentTypes = contentTypes;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get contentTypesInfo() {
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.$t('ContentTypesInfo', {
|
2020-01-17 07:43:10 +00:00
|
|
|
allowedContentTypes: this.allowedContentTypes
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'miscellaneous'}
|
|
|
|
}};
|
|
|
|
this.$http.get('DmsTypes/findOne', {params}).then(res => {
|
|
|
|
const dmsTypeId = res.data && res.data.id;
|
|
|
|
const companyId = this.vnConfig.companyFk;
|
|
|
|
const warehouseId = this.vnConfig.warehouseFk;
|
|
|
|
const defaultParams = {
|
|
|
|
reference: this.travel.id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: companyId,
|
|
|
|
dmsTypeId: dmsTypeId,
|
2020-07-23 14:07:08 +00:00
|
|
|
description: this.$t('FileDescription', {
|
2020-01-17 07:43:10 +00:00
|
|
|
travelId: this.travel.id
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
|
|
|
|
|
|
|
this.dms = Object.assign(this.dms, defaultParams);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:11:41 +00:00
|
|
|
onAddThermographClick(event) {
|
2020-05-27 12:34:34 +00:00
|
|
|
const defaultTemperature = 'COOL';
|
|
|
|
const defaultModel = 'DISPOSABLE';
|
|
|
|
|
2020-05-27 11:11:41 +00:00
|
|
|
event.preventDefault();
|
|
|
|
this.newThermograph = {
|
|
|
|
thermographId: this.thermographId,
|
|
|
|
warehouseId: this.warehouseId,
|
2020-05-27 12:34:34 +00:00
|
|
|
temperature: defaultTemperature,
|
|
|
|
model: defaultModel
|
2020-05-27 11:11:41 +00:00
|
|
|
};
|
2020-05-27 12:34:34 +00:00
|
|
|
|
|
|
|
this.$.modelsModel.refresh();
|
|
|
|
this.$.temperaturesModel.refresh();
|
2020-05-27 11:11:41 +00:00
|
|
|
this.$.newThermographDialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
onNewThermographAccept() {
|
|
|
|
return this.$http.post(`Thermographs/createThermograph`, this.newThermograph)
|
|
|
|
.then(res => this.dms.thermographId = res.data.id);
|
|
|
|
}
|
|
|
|
|
2020-01-17 07:43:10 +00:00
|
|
|
onSubmit() {
|
2020-01-21 11:21:53 +00:00
|
|
|
const query = `Travels/${this.travel.id}/createThermograph`;
|
2020-01-17 07:43:10 +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 => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2020-01-22 08:04:26 +00:00
|
|
|
this.$.watcher.updateOriginalData();
|
|
|
|
this.$state.go('travel.card.thermograph.index');
|
2020-01-17 07:43:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTravelThermographCreate', {
|
2020-01-17 07:43:10 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
travel: '<'
|
|
|
|
}
|
|
|
|
});
|