2019-07-15 09:40: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.$stateParams = $state.params;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
get client() {
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
|
|
|
|
set client(value) {
|
|
|
|
this._client = value;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
this.setDefaultParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefaultParams() {
|
|
|
|
const path = `/api/Dms/${this.$stateParams.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,
|
2019-07-16 12:12:58 +00:00
|
|
|
hasFileAttached: false,
|
2019-07-15 09:40:11 +00:00
|
|
|
files: []
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
const query = `/api/dms/${this.$stateParams.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.$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-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-07-15 09:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp'];
|
|
|
|
|
|
|
|
ngModule.component('vnClientDmsEdit', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
|
|
|
});
|