1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

reset method for react s3 fineuploader

This commit is contained in:
Tim Daubenschütz 2015-09-10 11:22:42 +02:00
parent c3b71b5398
commit 1d184973f4
3 changed files with 28 additions and 5 deletions

View File

@ -30,7 +30,6 @@ let InputFileUploader = React.createClass({
getInitialState() {
return {
value: null
};
},
@ -40,8 +39,11 @@ let InputFileUploader = React.createClass({
});
},
render() {
reset() {
this.refs.fineuploader.reset();
},
render() {
let editable = this.props.isFineUploaderActive;
// if disabled is actually set by property, we want to override
@ -50,9 +52,9 @@ let InputFileUploader = React.createClass({
editable = !this.props.disabled;
}
return (
<ReactS3FineUploader
ref="fineuploader"
onClick={this.props.onClick}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',

View File

@ -96,6 +96,14 @@ let Property = React.createClass({
// resets the value of a plain HTML5 input
this.refs.input.getDOMNode().value = this.state.initialValue;
// For some inputs, reseting state.value is not enough to visually reset the
// component.
//
// So if the input actually needs a visual reset, it needs to implement
// a dedicated reset method.
if(this.refs.input.reset && typeof this.refs.input.reset === 'function') {
this.refs.input.reset();
}
},
handleChange(event) {

View File

@ -235,6 +235,21 @@ var ReactS3FineUploader = React.createClass({
};
},
// Resets the whole react fineuploader component to its initial state
reset() {
// Cancel all currently ongoing uploads
this.state.uploader.cancelAll();
// and reset component in general
this.state.uploader.reset();
// proclaim that upload is not ready
this.props.setIsUploadReady(false);
// reset internal data structures of component
this.setState(this.getInitialState());
},
requestKey(fileId) {
let filename = this.state.uploader.getName(fileId);
let uuid = this.state.uploader.getUuid(fileId);
@ -439,7 +454,6 @@ var ReactS3FineUploader = React.createClass({
},
onCancel(id) {
// when a upload is canceled, we need to update this components file array
this.setStatusOfFile(id, 'canceled');
@ -461,7 +475,6 @@ var ReactS3FineUploader = React.createClass({
},
onProgress(id, name, uploadedBytes, totalBytes) {
let newState = React.addons.update(this.state, {
filesToUpload: { [id]: {
progress: { $set: (uploadedBytes / totalBytes) * 100} }