[enh] Be able to delete source file

This commit is contained in:
ljf 2021-08-31 04:21:10 +02:00
parent 358e6978a4
commit 5e554bb4a2
4 changed files with 30 additions and 11 deletions

View file

@ -1,15 +1,15 @@
<template> <template>
<b-button-group class="w-100"> <b-button-group class="w-100">
<b-button @click="clearFiles" variant="danger" v-if="!required && file"> <b-button @click="clearFiles" variant="danger" v-if="!this.required && this.value !== null && !this.value._removed">
<icon iname="trash" /> <icon iname="trash" />
</b-button> </b-button>
<b-form-file <b-form-file
v-model="file" v-model="file"
ref="file-input" ref="input-file"
:id="id" :id="id"
:required="required"
v-on="$listeners" v-on="$listeners"
:placeholder="placeholder_" :required="required"
:placeholder="_placeholder"
:accept="accept" :accept="accept"
@blur="$parent.$emit('touch', name)" @blur="$parent.$emit('touch', name)"
/> />
@ -22,8 +22,7 @@ export default {
data () { data () {
return { return {
file: this.value, file: this.value
placeholder_: (this.value) ? this.value.name : this.placeholder
} }
}, },
@ -36,12 +35,24 @@ export default {
name: { type: String, default: null } name: { type: String, default: null }
}, },
computed: {
_placeholder: function () {
return (this.value === null) ? this.placeholder : this.value.name
}
},
methods: { methods: {
clearFiles () { clearFiles () {
this.file = null const f = new File([''], this.placeholder)
this.placeholder_ = this.placeholder f._removed = true
this.$refs['file-input'].reset() if (this.value && this.value.currentfile) {
this.$refs['input-file'].reset()
this.$emit('input', f)
} else {
this.$refs['input-file'].setFiles([f])
this.file = f
this.$emit('input', f)
}
} }
} }
} }

View file

@ -10,7 +10,7 @@ export default {
name: 'ReadOnlyAlertItem', name: 'ReadOnlyAlertItem',
data () { data () {
let icons = { const icons = {
success: 'thumbs-up', success: 'thumbs-up',
info: 'info', info: 'info',
warning: 'warning', warning: 'warning',

View file

@ -130,7 +130,8 @@ export function formatYunoHostArgument (arg) {
props: defaultProps.concat(['accept']), props: defaultProps.concat(['accept']),
callback: function () { callback: function () {
if (value) { if (value) {
value = new File([''], value.replace(/^.*[/]/, '')) value = new File([''], value)
value.currentfile = true
} }
} }
}, },
@ -337,6 +338,12 @@ export async function formatFormData (
} else if (removeNull && (value === null || value === undefined)) { } else if (removeNull && (value === null || value === undefined)) {
continue continue
} else if (value instanceof File) { } else if (value instanceof File) {
if (value.currentfile) {
continue
} else if (value._removed) {
output[type][key] = ''
continue
}
promises.push(pFileReader(value, output[type], key)) promises.push(pFileReader(value, output[type], key))
} else if (flatten && isObjectLiteral(value)) { } else if (flatten && isObjectLiteral(value)) {
flattenObjectLiteral(value, output[type]) flattenObjectLiteral(value, output[type])

View file

@ -110,6 +110,7 @@ export default {
}, },
applyConfig (id_) { applyConfig (id_) {
console.debug(this.forms[id_])
formatFormData(this.forms[id_], { promise: true, removeEmpty: false, removeNull: true }).then((formatedData) => { formatFormData(this.forms[id_], { promise: true, removeEmpty: false, removeNull: true }).then((formatedData) => {
console.debug(formatedData) console.debug(formatedData)
const args = objectToParams(formatedData) const args = objectToParams(formatedData)