import ngModule from '../../module'; import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { get travel() { return this._travel; } set travel(value) { this._travel = value; if (value) { this.setDefaultParams(); this.getAllowedContentTypes(); } } getAllowedContentTypes() { this.$http.get('DmsContainers/allowedContentTypes').then(res => { const contentTypes = res.data.join(', '); this.allowedContentTypes = contentTypes; }); } get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } setDefaultParams() { const filterObj = {include: {relation: 'dms'}}; const filter = encodeURIComponent(JSON.stringify(filterObj)); const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`; this.$http.get(path).then(res => { const thermograph = res.data && res.data; this.thermograph = { thermographId: thermograph.thermographFk, state: thermograph.result, reference: thermograph.dms.reference, warehouseId: thermograph.dms.warehouseFk, companyId: thermograph.dms.companyFk, dmsTypeId: thermograph.dms.dmsTypeFk, description: thermograph.dms.description, hasFile: thermograph.dms.hasFile, hasFileAttached: false, files: [] }; }); } onSubmit() { const query = `travels/${this.$params.id}/updateThermograph`; const options = { method: 'POST', url: query, params: this.thermograph, 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.thermograph.files }; this.$http(options).then(res => { if (res) { this.vnApp.showSuccess(this.$t('Data saved!')); this.$.watcher.updateOriginalData(); this.$state.go('travel.card.thermograph.index'); } }); } onFileChange(files) { let hasFileAttached = false; if (files.length > 0) hasFileAttached = true; this.$.$applyAsync(() => { this.thermograph.hasFileAttached = hasFileAttached; }); } } ngModule.vnComponent('vnTravelThermographEdit', { template: require('./index.html'), controller: Controller, bindings: { travel: '<' } });