TT#136551 Send FAX - Content/File not working properly

Change-Id: I0d7b9d3d97aa96b4c460f1d4789c867b2561c773
mr10.1.1
Carlo Venusino 4 years ago
parent c25ef97fe9
commit 6ab354454a

@ -1,21 +1,17 @@
import { post } from 'src/api/common'
import _ from 'lodash' import _ from 'lodash'
import Vue from 'vue'
export function createFax (options) { export async function createFax (options) {
return new Promise((resolve, reject) => { const formData = new FormData()
var formData = new FormData() const fields = _.clone(options)
var fields = _.clone(options) delete fields.faxfile
delete fields.file const json = JSON.stringify(fields)
var json = JSON.stringify(fields)
formData.append('json', json) formData.append('json', json)
if (options.file) { if (options.faxfile) {
formData.append('faxfile', options.file) formData.append('faxfile', options.faxfile)
} }
Vue.http.post('api/faxes/', formData).then(() => { return await post({
resolve() resource: 'faxes',
}).catch((err) => { body: formData
reject(err)
})
}) })
} }

@ -51,7 +51,7 @@
/> />
<csc-input-file <csc-input-file
accept=".pdf,.tiff,.txt,.ps" accept=".pdf,.tiff,.txt,.ps"
@isFileSelected="toggleFileSelected" @file-selected="toggleFileSelected"
/> />
</q-card-section> </q-card-section>
<q-card-actions> <q-card-actions>
@ -61,6 +61,7 @@
icon="clear" icon="clear"
color="default" color="default"
:label="$t('Cancel')" :label="$t('Cancel')"
@click="resetFormData"
/> />
<q-btn <q-btn
flat flat
@ -101,14 +102,7 @@ export default {
}, },
data () { data () {
return { return {
selectedFile: false, form: {},
form: {
destination: '',
pageHeader: null,
data: null,
quality: this.$faxQualityOptionsDefault.value,
file: {}
},
isMobile: this.$q.platform.is.mobile, isMobile: this.$q.platform.is.mobile,
destinationError: false destinationError: false
} }
@ -121,7 +115,7 @@ export default {
}), }),
maxLength: maxLength(3600) maxLength: maxLength(3600)
}, },
file: { faxfile: {
required: requiredUnless(function () { required: requiredUnless(function () {
return this.hasContentToSend return this.hasContentToSend
}) })
@ -134,7 +128,7 @@ export default {
}, },
computed: { computed: {
hasContentToSend () { hasContentToSend () {
return !!this.form.data || this.selectedFile return (this.form.data && this.form.data.length > 0) || this.form.faxfile
}, },
formDisabled () { formDisabled () {
return !this.$v.form.$anyDirty || return !this.$v.form.$anyDirty ||
@ -172,9 +166,12 @@ export default {
}) })
} }
}, },
mounted () {
this.resetFormData()
},
methods: { methods: {
toggleFileSelected (value) { toggleFileSelected (value) {
this.selectedFile = value this.form.faxfile = value
}, },
sendFax () { sendFax () {
if (this.$v.form.$error || if (this.$v.form.$error ||
@ -182,10 +179,21 @@ export default {
showGlobalError(this.$t('You have invalid form input. Please check and try again.')) showGlobalError(this.$t('You have invalid form input. Please check and try again.'))
} else { } else {
this.$store.dispatch('communication/createFax', this.form) this.$store.dispatch('communication/createFax', this.form)
this.resetFormData()
} }
}, },
error (state) { error (state) {
this.destinationError = state this.destinationError = state
},
resetFormData () {
this.form = {
destination: '',
pageHeader: null,
data: null,
quality: this.$faxQualityOptionsDefault.value,
faxfile: null
}
this.$v.$reset()
} }
} }
} }

@ -32,11 +32,12 @@
size="sm" size="sm"
unelevated unelevated
:label="$t('Reset')" :label="$t('Reset')"
@click="selectedFile = null; $refs.fileInput.$el.value = null" @click="resetFile"
/> />
</template> </template>
</q-input> </q-input>
<q-input <q-input
:value="selectedFile"
v-show="false" v-show="false"
ref="fileInput" ref="fileInput"
type="file" type="file"
@ -62,9 +63,17 @@ export default {
return this.$t('No file') return this.$t('No file')
} }
}, },
watch: {
selectedFile () {
this.$emit('file-selected', this.selectedFile)
}
},
methods: { methods: {
fileInput (fileList) { fileInput (fileList) {
this.selectedFile = fileList[0] this.selectedFile = fileList[0]
},
resetFile () {
this.selectedFile = null
} }
} }
} }

@ -1,4 +1,3 @@
import _ from 'lodash' import _ from 'lodash'
import { import {
Loading, Loading,
@ -10,9 +9,13 @@ import {
import { import {
i18n i18n
} from 'src/boot/i18n' } from 'src/boot/i18n'
import CscSpinner from 'components/CscSpinner'
export function startLoading () { export function startLoading () {
Loading.show({ delay: 0 }) Loading.show({
delay: 0,
spinner: CscSpinner
})
} }
export function stopLoading () { export function stopLoading () {

Loading…
Cancel
Save