2019-11-22 09:42:05 +00:00
|
|
|
import ngModule from '../../module';
|
2020-03-18 11:55:22 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-11-22 09:42:05 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-18 11:55:22 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
2019-11-22 12:46:38 +00:00
|
|
|
super($element, $);
|
2019-11-22 09:42:05 +00:00
|
|
|
this.dms = {
|
|
|
|
files: [],
|
|
|
|
hasFile: false,
|
|
|
|
hasFileAttached: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get worker() {
|
|
|
|
return this._worker;
|
|
|
|
}
|
|
|
|
|
|
|
|
set worker(value) {
|
|
|
|
this._worker = value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
this.setDefaultParams();
|
|
|
|
this.getAllowedContentTypes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllowedContentTypes() {
|
2020-12-18 16:23:04 +00:00
|
|
|
this.$http.get('DmsContainers/allowedContentTypes').then(res => {
|
2019-11-22 09:42:05 +00:00
|
|
|
const contentTypes = res.data.join(', ');
|
|
|
|
this.allowedContentTypes = contentTypes;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get contentTypesInfo() {
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.$t('ContentTypesInfo', {
|
2019-11-22 09:42:05 +00:00
|
|
|
allowedContentTypes: this.allowedContentTypes
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'hhrrData'}
|
|
|
|
}};
|
|
|
|
this.$http.get('DmsTypes/findOne', {params}).then(res => {
|
|
|
|
const dmsType = res.data && res.data;
|
|
|
|
const companyId = this.vnConfig.companyFk;
|
|
|
|
const warehouseId = this.vnConfig.warehouseFk;
|
|
|
|
const defaultParams = {
|
|
|
|
reference: this.worker.id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: companyId,
|
|
|
|
dmsTypeId: dmsType.id,
|
2020-07-23 14:07:08 +00:00
|
|
|
description: this.$t('WorkerFileDescription', {
|
2019-11-22 09:42:05 +00:00
|
|
|
dmsTypeName: dmsType.name,
|
|
|
|
workerId: this.worker.id,
|
|
|
|
workerName: this.worker.name
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
|
|
|
|
|
|
|
this.dms = Object.assign(this.dms, defaultParams);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
const query = `Workers/${this.worker.id}/uploadFile`;
|
|
|
|
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) {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
2019-11-22 09:42:05 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 09:50:04 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2019-11-22 09:42:05 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnWorkerDmsCreate', {
|
2019-11-22 09:42:05 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
worker: '<'
|
|
|
|
}
|
|
|
|
});
|