2016-11-07 05:28:37 +11:00
|
|
|
/* eslint-env browser */
|
|
|
|
import statusPosterService from '../../services/status_poster/status_poster.service.js'
|
|
|
|
|
|
|
|
const mediaUpload = {
|
|
|
|
mounted () {
|
|
|
|
const input = this.$el.querySelector('input')
|
|
|
|
|
|
|
|
input.addEventListener('change', ({target}) => {
|
2016-11-08 01:04:27 +11:00
|
|
|
const file = target.files[0]
|
2017-02-22 00:13:19 +11:00
|
|
|
this.uploadFile(file)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
uploading: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
uploadFile(file) {
|
|
|
|
const self = this
|
|
|
|
const store = this.$store
|
2016-11-08 01:04:27 +11:00
|
|
|
const formData = new FormData()
|
|
|
|
formData.append('media', file)
|
2016-11-14 04:26:10 +11:00
|
|
|
|
|
|
|
self.$emit('uploading')
|
|
|
|
self.uploading = true
|
|
|
|
|
2016-11-07 05:28:37 +11:00
|
|
|
statusPosterService.uploadMedia({ store, formData })
|
|
|
|
.then((fileData) => {
|
|
|
|
self.$emit('uploaded', fileData)
|
2016-11-14 04:26:10 +11:00
|
|
|
self.uploading = false
|
|
|
|
}, (error) => {
|
|
|
|
self.$emit('upload-failed')
|
|
|
|
self.uploading = false
|
2016-11-07 05:28:37 +11:00
|
|
|
})
|
2017-02-22 00:13:19 +11:00
|
|
|
}
|
2016-11-14 04:26:10 +11:00
|
|
|
},
|
2017-02-22 00:13:19 +11:00
|
|
|
props: [
|
|
|
|
'dropFiles'
|
|
|
|
],
|
|
|
|
watch: {
|
|
|
|
'dropFiles': function (fileInfos) {
|
|
|
|
if (!this.uploading)
|
|
|
|
this.uploadFile(fileInfos[0])
|
2016-11-14 04:26:10 +11:00
|
|
|
}
|
2016-11-07 05:28:37 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default mediaUpload
|