95 lines
2.5 KiB
JavaScript
95 lines
2.5 KiB
JavaScript
import ngModule from '../../module';
|
|
import Section from 'salix/components/section';
|
|
import './style.scss';
|
|
|
|
class Controller extends Section {
|
|
get worker() {
|
|
return this._worker;
|
|
}
|
|
|
|
set worker(value) {
|
|
this._worker = value;
|
|
|
|
if (value) {
|
|
this.setDefaultParams();
|
|
this.getAllowedContentTypes();
|
|
}
|
|
}
|
|
|
|
getAllowedContentTypes() {
|
|
this.$http.get('DmsContainers/allowedContentTypes').then(res => {
|
|
const contentTypes = res.data.join(', ');
|
|
this.allowedContentTypes = contentTypes;
|
|
});
|
|
}
|
|
|
|
get contentTypesInfo() {
|
|
return this.$t('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.$t('Data saved!'));
|
|
this.$.watcher.updateOriginalData();
|
|
this.$state.go('worker.card.dms.index');
|
|
}
|
|
});
|
|
}
|
|
|
|
onFileChange(files) {
|
|
let hasFileAttached = false;
|
|
if (files.length > 0)
|
|
hasFileAttached = true;
|
|
|
|
this.$.$applyAsync(() => {
|
|
this.dms.hasFileAttached = hasFileAttached;
|
|
});
|
|
}
|
|
}
|
|
|
|
ngModule.vnComponent('vnWorkerDmsEdit', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
worker: '<'
|
|
}
|
|
});
|