2019-06-06 11:59:11 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2019-10-09 22:47:29 +00:00
|
|
|
constructor($scope, $http, $state, $translate, vnApp, vnConfig) {
|
2019-06-06 11:59:11 +00:00
|
|
|
this.$ = $scope;
|
|
|
|
this.$http = $http;
|
|
|
|
this.$state = $state;
|
|
|
|
this.$translate = $translate;
|
|
|
|
this.vnApp = vnApp;
|
2019-10-09 22:47:29 +00:00
|
|
|
this.vnConfig = vnConfig;
|
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 ticket() {
|
|
|
|
return this._ticket;
|
|
|
|
}
|
|
|
|
|
|
|
|
set ticket(value) {
|
|
|
|
this._ticket = 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() {
|
|
|
|
this.$http.get('/api/ticketDms/allowedContentTypes').then(res => {
|
|
|
|
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: 'ticket'}
|
|
|
|
}};
|
|
|
|
this.$http.get('/api/DmsTypes/findOne', {params}).then(res => {
|
|
|
|
const dmsTypeId = res.data && res.data.id;
|
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.ticket.id,
|
2019-07-17 13:01:38 +00:00
|
|
|
warehouseId: warehouseId,
|
|
|
|
companyId: companyId,
|
2019-06-06 11:59:11 +00:00
|
|
|
dmsTypeId: dmsTypeId,
|
|
|
|
description: this.$translate.instant('FileDescription', {
|
|
|
|
ticketId: this.ticket.id,
|
|
|
|
clientId: this.ticket.client.id,
|
|
|
|
clientName: this.ticket.client.name
|
|
|
|
}).toUpperCase()
|
|
|
|
};
|
|
|
|
|
|
|
|
this.dms = Object.assign(this.dms, defaultParams);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
const query = `/api/tickets/${this.ticket.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('ticket.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-06-06 11:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 22:47:29 +00:00
|
|
|
Controller.$inject = ['$scope', '$http', '$state', '$translate', 'vnApp', 'vnConfig'];
|
2019-06-06 11:59:11 +00:00
|
|
|
|
|
|
|
ngModule.component('vnTicketDmsCreate', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<'
|
|
|
|
}
|
|
|
|
});
|