2019-06-06 11:59:11 +00:00
|
|
|
import ngModule from '../../module';
|
2020-03-17 10:17:50 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-06-06 11:59:11 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2019-06-06 11:59:11 +00:00
|
|
|
this.dms = {
|
|
|
|
files: [],
|
2019-07-16 11:37:25 +00:00
|
|
|
hasFile: false,
|
2019-07-16 12:12:58 +00:00
|
|
|
hasFileAttached: false
|
2019-06-06 11:59:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get client() {
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
|
|
|
|
set client(value) {
|
|
|
|
this._client = value;
|
|
|
|
|
2019-08-08 06:37:03 +00:00
|
|
|
if (value) {
|
2019-06-06 11:59:11 +00:00
|
|
|
this.setDefaultParams();
|
2019-08-08 06:37:03 +00:00
|
|
|
this.getAllowedContentTypes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllowedContentTypes() {
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.get('clientDms/allowedContentTypes').then(res => {
|
2019-08-08 06:37:03 +00:00
|
|
|
const contentTypes = res.data.join(', ');
|
|
|
|
this.allowedContentTypes = contentTypes;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get contentTypesInfo() {
|
|
|
|
return this.$translate.instant('ContentTypesInfo', {
|
|
|
|
allowedContentTypes: this.allowedContentTypes
|
|
|
|
});
|
2019-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'paymentsLaw'}
|
|
|
|
}};
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.get('DmsTypes/findOne', {params}).then(res => {
|
2019-06-06 11:59:11 +00:00
|
|
|
const dmsType = res.data && res.data;
|
2019-10-09 22:47:29 +00:00
|
|
|
const companyId = this.vnConfig.companyFk;
|
|
|
|
const warehouseId = this.vnConfig.warehouseFk;
|
2019-06-06 11:59:11 +00:00
|
|
|
const defaultParams = {
|
|
|
|
reference: this.client.id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: companyId,
|
|
|
|
dmsTypeId: dmsType.id,
|
|
|
|
description: this.$translate.instant('ClientFileDescription', {
|
|
|
|
dmsTypeName: dmsType.name,
|
|
|
|
clientId: this.client.id,
|
|
|
|
clientName: this.client.name
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
|
|
|
|
|
|
|
this.dms = Object.assign(this.dms, defaultParams);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
2019-10-24 22:53:53 +00:00
|
|
|
const query = `clients/${this.client.id}/uploadFile`;
|
2019-06-06 11:59:11 +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();
|
|
|
|
this.$state.go('client.card.dms.index');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileChange(files) {
|
2019-07-16 12:12:58 +00:00
|
|
|
let hasFileAttached = false;
|
2019-10-28 20:40:24 +00:00
|
|
|
|
2019-07-16 11:37:25 +00:00
|
|
|
if (files.length > 0)
|
2019-07-16 12:12:58 +00:00
|
|
|
hasFileAttached = true;
|
2019-07-16 11:37:25 +00:00
|
|
|
|
|
|
|
this.$.$applyAsync(() => {
|
2019-07-16 12:12:58 +00:00
|
|
|
this.dms.hasFileAttached = hasFileAttached;
|
2019-07-16 11:37:25 +00:00
|
|
|
});
|
2019-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2019-06-06 11:59:11 +00:00
|
|
|
|
|
|
|
ngModule.component('vnClientDmsCreate', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
|
|
|
});
|