Merge pull request #308 from transloadit/fix/submit-filecard-on-enter

Submit FileCard on enter key
This commit is contained in:
Artur Paikin 2017-09-01 13:10:20 +03:00 committed by GitHub
commit 8baf64ebf7
3 changed files with 20 additions and 23 deletions

View file

@ -72,6 +72,7 @@ class Uppy {
this.initSocket = this.initSocket.bind(this)
this.log = this.log.bind(this)
this.addFile = this.addFile.bind(this)
this.removeFile = this.removeFile.bind(this)
this.calculateProgress = this.calculateProgress.bind(this)
this.resetProgress = this.resetProgress.bind(this)

View file

@ -6,7 +6,11 @@ module.exports = function fileCard (props) {
const file = props.fileCardFor ? props.files[props.fileCardFor] : false
const meta = {}
function tempStoreMeta (ev) {
const tempStoreMetaOrSubmit = (ev) => {
if (ev.keyCode === 13) {
props.done(meta, file.id)
}
const value = ev.target.value
const name = ev.target.dataset.name
meta[name] = value
@ -22,7 +26,7 @@ module.exports = function fileCard (props) {
data-name="${field.id}"
value="${file.meta[field.id]}"
placeholder="${field.placeholder || ''}"
onkeyup=${tempStoreMeta} /></fieldset>`
onkeyup=${tempStoreMetaOrSubmit} /></fieldset>`
})
}
@ -46,8 +50,8 @@ module.exports = function fileCard (props) {
<div class="UppyDashboardFileCard-info">
<fieldset class="UppyDashboardFileCard-fieldset">
<label class="UppyDashboardFileCard-label">Name</label>
<input class="UppyDashboardFileCard-input" name="name" type="text" value="${file.meta.name}"
onkeyup=${tempStoreMeta} />
<input class="UppyDashboardFileCard-input" data-name="name" type="text" value="${file.meta.name}"
onkeyup=${tempStoreMetaOrSubmit} />
</fieldset>
${renderMetaFields(file)}
</div>
@ -60,5 +64,5 @@ module.exports = function fileCard (props) {
title="Finish editing file"
onclick=${() => props.done(meta, file.id)}>${checkIcon()}</button>
</div>
</div>`
</div>`
}

View file

@ -249,7 +249,7 @@ module.exports = class DashboardUI extends Plugin {
}
handleFileCard (fileId) {
const modal = this.core.getState().modal
const modal = this.core.state.modal
this.core.setState({
modal: Object.assign({}, modal, {
@ -318,44 +318,36 @@ module.exports = class DashboardUI extends Plugin {
return target.type === 'progressindicator'
})
// const addFile = (file) => {
// this.core.emitter.emit('core:file-add', file)
// }
const removeFile = (fileID) => {
this.core.emitter.emit('core:file-remove', fileID)
}
const startUpload = (ev) => {
this.core.upload().catch((err) => {
// Log error.
console.error(err.stack || err.message || err)
this.core.log(err.stack || err.message || err)
})
}
const pauseUpload = (fileID) => {
this.core.emitter.emit('core:upload-pause', fileID)
this.core.emit.emit('core:upload-pause', fileID)
}
const cancelUpload = (fileID) => {
this.core.emitter.emit('core:upload-cancel', fileID)
this.core.emitter.emit('core:file-remove', fileID)
this.core.emit('core:upload-cancel', fileID)
this.core.emit('core:file-remove', fileID)
}
const showFileCard = (fileID) => {
this.core.emitter.emit('dashboard:file-card', fileID)
this.core.emit('dashboard:file-card', fileID)
}
const fileCardDone = (meta, fileID) => {
this.core.emitter.emit('core:update-meta', meta, fileID)
this.core.emitter.emit('dashboard:file-card')
this.core.emit('core:update-meta', meta, fileID)
this.core.emit('dashboard:file-card')
}
const info = (text, type, duration) => {
this.core.info(text, type, duration)
}
const resumableUploads = this.core.getState().capabilities.resumableUploads || false
const resumableUploads = this.core.state.capabilities.resumableUploads || false
return Dashboard({
state: state,
@ -382,7 +374,7 @@ module.exports = class DashboardUI extends Plugin {
pauseAll: this.pauseAll,
resumeAll: this.resumeAll,
addFile: this.core.addFile,
removeFile: removeFile,
removeFile: this.core.removeFile,
info: info,
note: this.opts.note,
metaFields: state.metaFields,