2019-06-06 11:59:11 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
constructor($scope, $http, $state, $translate, vnApp) {
|
|
|
|
this.$ = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$state = $state;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
this.dms = {
|
|
|
|
files: [],
|
2019-07-16 11:37:25 +00:00
|
|
|
hasFile: false,
|
|
|
|
hasAttachedFile: false
|
2019-06-06 11:59:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get client() {
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
|
|
|
|
set client(value) {
|
|
|
|
this._client = value;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
this.setDefaultParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'paymentsLaw'}
|
|
|
|
}};
|
|
|
|
this.$http.get('/api/DmsTypes/findOne', {params}).then(res => {
|
|
|
|
const dmsType = res.data && res.data;
|
|
|
|
const companyId = window.localStorage.defaultCompanyFk;
|
|
|
|
const warehouseId = window.localStorage.defaultWarehouseFk;
|
|
|
|
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() {
|
|
|
|
const query = `/api/clients/${this.client.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) {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
|
|
this.$.watcher.updateOriginalData();
|
|
|
|
this.$state.go('client.card.dms.index');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileChange(files) {
|
2019-07-16 11:37:25 +00:00
|
|
|
let hasAttachedFile = false;
|
|
|
|
if (files.length > 0)
|
|
|
|
hasAttachedFile = true;
|
|
|
|
|
|
|
|
this.$.$applyAsync(() => {
|
|
|
|
this.dms.hasAttachedFile = hasAttachedFile;
|
|
|
|
});
|
2019-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp'];
|
|
|
|
|
|
|
|
ngModule.component('vnClientDmsCreate', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
|
|
|
});
|