2019-03-29 18:58:20 -07:00
|
|
|
const Importer = {
|
2019-03-30 02:10:57 -07:00
|
|
|
props: {
|
|
|
|
submitHandler: {
|
|
|
|
type: Function,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
submitButtonLabel: {
|
|
|
|
type: String,
|
|
|
|
default () {
|
|
|
|
return this.$t('importer.submit')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
successMessage: {
|
|
|
|
type: String,
|
|
|
|
default () {
|
|
|
|
return this.$t('importer.success')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
errorMessage: {
|
|
|
|
type: String,
|
|
|
|
default () {
|
|
|
|
return this.$t('importer.error')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-03-29 18:58:20 -07:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
file: null,
|
|
|
|
error: false,
|
|
|
|
success: false,
|
2019-03-30 02:10:57 -07:00
|
|
|
submitting: false
|
2019-03-29 18:58:20 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
change () {
|
|
|
|
this.file = this.$refs.input.files[0]
|
|
|
|
},
|
|
|
|
submit () {
|
2019-03-30 02:10:57 -07:00
|
|
|
this.dismiss()
|
|
|
|
this.submitting = true
|
|
|
|
this.submitHandler(this.file)
|
|
|
|
.then(() => { this.success = true })
|
|
|
|
.catch(() => { this.error = true })
|
|
|
|
.finally(() => { this.submitting = false })
|
2019-03-29 18:58:20 -07:00
|
|
|
},
|
|
|
|
dismiss () {
|
|
|
|
this.success = false
|
|
|
|
this.error = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Importer
|