2019-11-22 09:42:05 +00:00
|
|
|
import ngModule from '../../module';
|
2019-11-22 12:46:38 +00:00
|
|
|
import Component from 'core/lib/component';
|
2019-11-22 09:42:05 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2019-11-22 12:46:38 +00:00
|
|
|
class Controller extends Component {
|
|
|
|
get worker() {
|
|
|
|
return this._worker;
|
2019-11-22 09:42:05 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:46:38 +00:00
|
|
|
set worker(value) {
|
|
|
|
this._worker = value;
|
2019-11-22 09:42:05 +00:00
|
|
|
|
|
|
|
if (value) {
|
|
|
|
this.setDefaultParams();
|
|
|
|
this.getAllowedContentTypes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllowedContentTypes() {
|
2019-11-22 12:46:38 +00:00
|
|
|
this.$http.get('WorkerDms/allowedContentTypes').then(res => {
|
2019-11-22 09:42:05 +00:00
|
|
|
const contentTypes = res.data.join(', ');
|
|
|
|
this.allowedContentTypes = contentTypes;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get contentTypesInfo() {
|
|
|
|
return this.$translate.instant('ContentTypesInfo', {
|
|
|
|
allowedContentTypes: this.allowedContentTypes
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
2019-11-22 12:46:38 +00:00
|
|
|
const path = `Dms/${this.$params.dmsId}`;
|
2019-11-22 09:42:05 +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,
|
|
|
|
hasFileAttached: false,
|
|
|
|
files: []
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
2019-11-22 12:46:38 +00:00
|
|
|
const query = `dms/${this.$params.dmsId}/updateFile`;
|
2019-11-22 09:42:05 +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.$translate.instant('Data saved!'));
|
|
|
|
this.$.watcher.updateOriginalData();
|
2019-11-22 12:46:38 +00:00
|
|
|
this.$state.go('worker.card.dms.index');
|
2019-11-22 09:42:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileChange(files) {
|
|
|
|
let hasFileAttached = false;
|
|
|
|
if (files.length > 0)
|
|
|
|
hasFileAttached = true;
|
|
|
|
|
|
|
|
this.$.$applyAsync(() => {
|
|
|
|
this.dms.hasFileAttached = hasFileAttached;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:46:38 +00:00
|
|
|
ngModule.component('vnWorkerDmsEdit', {
|
2019-11-22 09:42:05 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
2019-11-22 12:46:38 +00:00
|
|
|
worker: '<'
|
2019-11-22 09:42:05 +00:00
|
|
|
}
|
|
|
|
});
|