Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-05-23 16:22:16 +00:00
commit ac56028578

View File

@ -17,20 +17,24 @@ class MultipleFilesWidget {
paramName: 'file', paramName: 'file',
done: function (e, data) { done: function (e, data) {
// process server response // process server response
if (!data.result.is_valid) { if (data.result.is_valid) {
throw new Error('Server sent us invalid data!')
}
self.fileFinished.bind(self)(data.result) self.fileFinished.bind(self)(data.result)
} else {
self.fileFailed.bind(self)(data)
}
}, },
add: function (e, data) { add: function (e, data) {
$.each(data.files, (index, file) => { $.each(data.files, (index, file) => {
self.addFile.bind(self)(null, file.name, self.setFileInProgress.bind(self)) self.addFile.bind(self)(null, file.name, self.setFileInProgress.bind(self))
}); })
data.process().done(function () { data.process().done(function () {
data.submit() data.submit()
}) })
},
progress: function(e, data) {
console.log('progress event')
console.log(e, data)
} }
}) })
@ -45,8 +49,6 @@ class MultipleFilesWidget {
} }
addFile(id, name, stateFunc) { addFile(id, name, stateFunc) {
console.log('addfile here!')
let li = document.createElement('li') let li = document.createElement('li')
li.className = 'filewidget--file' li.className = 'filewidget--file'
li.innerHTML = li.innerHTML =
@ -93,13 +95,25 @@ class MultipleFilesWidget {
this.updateFormField() this.updateFormField()
} }
fileFailed(serverResponse) {
let errors = Object.values(serverResponse.result.errors).join(' ')
console.error('File upload failed: ' + errors)
console.error(serverResponse)
// Using data, find the file
let file = this.fileList.filter(file => file.name === serverResponse.files[0].name)[0]
// Set the file state now it's finished
this.setFileFailed(file, errors)
this.viewFileList()
}
// //
// Update the field that keeps track of file IDs // Update the field that keeps track of file IDs
// //
updateFormField() { updateFormField() {
console.log("updateFormField", this)
let oldVal = this.element.field.value let oldVal = this.element.field.value
this.element.field.value = this.fileList.filter(f => f.id != null) this.element.field.value = this.fileList.filter(f => f.id != null)
.map(f => f.id) .map(f => f.id)
@ -121,6 +135,13 @@ class MultipleFilesWidget {
file.element.actions.innerHTML = state.actions || '' file.element.actions.innerHTML = state.actions || ''
} }
setFileFailed(file, errors) {
this.setFileState(file, {
iconClassList: 'fa fa-exclamation-triangle',
fileName: `FAILED: ${errors} ('${file.name}')`
})
}
setFileInProgress(file) { setFileInProgress(file) {
this.setFileState(file, { this.setFileState(file, {
iconClassList: 'fa fa-spinner fa-spin', iconClassList: 'fa fa-spinner fa-spin',
@ -143,8 +164,6 @@ class MultipleFilesWidget {
} }
setFileDone(file) { setFileDone(file) {
console.log("setFileDone", file)
this.setFileState(file, { this.setFileState(file, {
iconClassList: 'fa fa-file-o', iconClassList: 'fa fa-file-o',
fileName: `${file.name}`, fileName: `${file.name}`,
@ -175,8 +194,6 @@ class MultipleFilesWidget {
// //
viewFileList() { viewFileList() {
console.log("viewFileList", this)
for (let file of this.fileList) { for (let file of this.fileList) {
// Check if it's appended to the list // Check if it's appended to the list
if (!this.element.list.contains(file.root)) { if (!this.element.list.contains(file.root)) {