2021-04-15 08:47:39 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
2022-11-22 08:29:25 +00:00
|
|
|
import UserError from 'core/lib/user-error';
|
|
|
|
|
|
|
|
class Controller extends Section {
|
|
|
|
constructor($element, $, vnFile) {
|
|
|
|
super($element, $, vnFile);
|
2022-11-23 10:09:32 +00:00
|
|
|
this.dms = {
|
|
|
|
files: [],
|
|
|
|
hasFile: false,
|
|
|
|
hasFileAttached: false
|
|
|
|
};
|
2022-11-22 08:29:25 +00:00
|
|
|
this.vnFile = vnFile;
|
|
|
|
this.getAllowedContentTypes();
|
2022-11-23 10:09:32 +00:00
|
|
|
this._editDownloadDisabled = false;
|
2022-11-22 08:29:25 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 10:09:32 +00:00
|
|
|
get contentTypesInfo() {
|
|
|
|
return this.$t('ContentTypesInfo', {
|
|
|
|
allowedContentTypes: this.allowedContentTypes
|
|
|
|
});
|
2022-11-22 08:29:25 +00:00
|
|
|
}
|
|
|
|
|
2022-11-23 10:09:32 +00:00
|
|
|
get editDownloadDisabled() {
|
|
|
|
return this._editDownloadDisabled;
|
2022-11-22 08:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async checkFileExists(dmsId) {
|
|
|
|
if (!dmsId) return;
|
|
|
|
let filter = {
|
|
|
|
fields: ['id']
|
|
|
|
};
|
|
|
|
await this.$http.get(`Dms/${dmsId}`, {filter})
|
2022-11-23 10:09:32 +00:00
|
|
|
.then(() => this._editDownloadDisabled = false)
|
|
|
|
.catch(() => this._editDownloadDisabled = true);
|
2022-11-22 08:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async getFile(dmsId) {
|
|
|
|
const path = `Dms/${dmsId}`;
|
|
|
|
await this.$http.get(path).then(res => {
|
|
|
|
const dms = res.data && res.data;
|
|
|
|
this.dms = {
|
|
|
|
dmsId: dms.id,
|
|
|
|
reference: dms.reference,
|
|
|
|
warehouseId: dms.warehouseFk,
|
|
|
|
companyId: dms.companyFk,
|
|
|
|
dmsTypeId: dms.dmsTypeFk,
|
|
|
|
description: dms.description,
|
|
|
|
hasFile: dms.hasFile,
|
|
|
|
hasFileAttached: false,
|
|
|
|
files: []
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-23 10:09:32 +00:00
|
|
|
getAllowedContentTypes() {
|
|
|
|
this.$http.get('DmsContainers/allowedContentTypes').then(res => {
|
|
|
|
if (res.data.length > 0) {
|
|
|
|
const contentTypes = res.data.join(', ');
|
|
|
|
this.allowedContentTypes = contentTypes;
|
|
|
|
}
|
2022-11-22 08:29:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-23 10:09:32 +00:00
|
|
|
openEditDialog(dmsId) {
|
|
|
|
this.getFile(dmsId).then(() => this.$.dmsEditDialog.show());
|
|
|
|
}
|
|
|
|
|
|
|
|
openCreateDialog() {
|
|
|
|
this.dms = {
|
|
|
|
reference: null,
|
|
|
|
warehouseId: null,
|
|
|
|
companyId: null,
|
|
|
|
dmsTypeId: null,
|
|
|
|
description: null,
|
|
|
|
hasFile: true,
|
|
|
|
hasFileAttached: true,
|
|
|
|
files: null
|
|
|
|
};
|
|
|
|
this.$.dmsCreateDialog.show();
|
|
|
|
}
|
|
|
|
|
2022-11-22 08:29:25 +00:00
|
|
|
downloadFile(dmsId) {
|
|
|
|
this.vnFile.download(`api/dms/${dmsId}/downloadFile`);
|
|
|
|
}
|
|
|
|
|
|
|
|
onFileChange(files) {
|
|
|
|
let hasFileAttached = false;
|
|
|
|
if (files.length > 0)
|
|
|
|
hasFileAttached = true;
|
|
|
|
|
|
|
|
this.$.$applyAsync(() => {
|
|
|
|
this.dms.hasFileAttached = hasFileAttached;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onEdit() {
|
|
|
|
if (!this.dms.companyId)
|
|
|
|
throw new UserError(`The company can't be empty`);
|
|
|
|
if (!this.dms.warehouseId)
|
|
|
|
throw new UserError(`The warehouse can't be empty`);
|
|
|
|
if (!this.dms.dmsTypeId)
|
|
|
|
throw new UserError(`The DMS Type can't be empty`);
|
|
|
|
if (!this.dms.description)
|
|
|
|
throw new UserError(`The description can't be empty`);
|
|
|
|
|
|
|
|
const query = `dms/${this.dms.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.$t('Data saved!'));
|
2022-11-23 10:09:32 +00:00
|
|
|
if (res.data.length > 0) this.invoiceIn.dmsFk = res.data[0].id;
|
2022-11-22 08:29:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreate() {
|
|
|
|
if (!this.dms.companyId)
|
|
|
|
throw new UserError(`The company can't be empty`);
|
|
|
|
if (!this.dms.warehouseId)
|
|
|
|
throw new UserError(`The warehouse can't be empty`);
|
|
|
|
if (!this.dms.dmsTypeId)
|
|
|
|
throw new UserError(`The DMS Type can't be empty`);
|
|
|
|
if (!this.dms.description)
|
|
|
|
throw new UserError(`The description can't be empty`);
|
|
|
|
if (!this.dms.files)
|
|
|
|
throw new UserError(`The files can't be empty`);
|
|
|
|
|
|
|
|
const query = `Dms/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.$t('Data saved!'));
|
2022-11-23 10:09:32 +00:00
|
|
|
if (res.data.length > 0) this.invoiceIn.dmsFk = res.data[0].id;
|
2022-11-22 08:29:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope', 'vnFile'];
|
2021-04-15 08:47:39 +00:00
|
|
|
|
|
|
|
ngModule.vnComponent('vnInvoiceInBasicData', {
|
|
|
|
template: require('./index.html'),
|
2022-11-22 08:29:25 +00:00
|
|
|
controller: Controller,
|
2021-04-15 08:47:39 +00:00
|
|
|
bindings: {
|
|
|
|
invoiceIn: '<'
|
|
|
|
}
|
|
|
|
});
|