90 lines
2.3 KiB
JavaScript
90 lines
2.3 KiB
JavaScript
|
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 claim() {
|
||
|
return this._claim;
|
||
|
}
|
||
|
|
||
|
set claim(value) {
|
||
|
this._claim = 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,
|
||
|
hasFileAttached: false,
|
||
|
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('claim.card.dms.index');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
onFileChange(files) {
|
||
|
let hasFileAttached = false;
|
||
|
if (files.length > 0)
|
||
|
hasFileAttached = true;
|
||
|
|
||
|
this.$.$applyAsync(() => {
|
||
|
this.dms.hasFileAttached = hasFileAttached;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp'];
|
||
|
|
||
|
ngModule.component('vnClaimDmsEdit', {
|
||
|
template: require('./index.html'),
|
||
|
controller: Controller,
|
||
|
bindings: {
|
||
|
claim: '<'
|
||
|
}
|
||
|
});
|