1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01:00

Add static version of thumbnail uploader in register piece form

This commit is contained in:
Tim Daubenschütz 2015-11-17 10:38:10 +01:00
parent efde22270c
commit 4f0c0fe65a
2 changed files with 79 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import UserActions from '../../actions/user_actions';
import Form from './form'; import Form from './form';
import Property from './property'; import Property from './property';
import InputFineUploader from './input_fineuploader'; import InputFineUploader from './input_fineuploader';
import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button';
import ApiUrls from '../../constants/api_urls'; import ApiUrls from '../../constants/api_urls';
import AppConstants from '../../constants/application_constants'; import AppConstants from '../../constants/application_constants';
@ -48,7 +49,8 @@ let RegisterPieceForm = React.createClass({
getInitialState(){ getInitialState(){
return mergeOptions( return mergeOptions(
{ {
isUploadReady: false digitalWorkKeyReady: false,
thumbnailKeyReady: true
}, },
UserStore.getState() UserStore.getState()
); );
@ -67,30 +69,49 @@ let RegisterPieceForm = React.createClass({
this.setState(state); this.setState(state);
}, },
setIsUploadReady(isReady) { /**
this.setState({ * This method is overloaded so that we can track the ready-state
isUploadReady: isReady * of each uploader in the component
}); * @param {string} uploaderKey Name of the uploader's key to track
*/
setIsUploadReady(uploaderKey) {
return (isUploadReady) => {
this.setState({
[uploaderKey]: isUploadReady
});
};
}, },
render() { render() {
let currentUser = this.state.currentUser; const { disabled,
let enableLocalHashing = currentUser && currentUser.profile ? currentUser.profile.hash_locally : false; handleSuccess,
enableLocalHashing = enableLocalHashing && this.props.enableLocalHashing; submitMessage,
headerMessage,
isFineUploaderActive,
onLoggedOut,
isFineUploaderEditable,
location,
children,
enableLocalHashing } = this.props;
const { currentUser,
isUploadReady } = this.state;
const profileHashLocally = currentUser && currentUser.profile ? currentUser.profile.hash_locally : false;
const hashLocally = profileHashLocally && enableLocalHashing;
return ( return (
<Form <Form
disabled={this.props.disabled} disabled={disabled}
className="ascribe-form-bordered" className="ascribe-form-bordered"
ref='form' ref='form'
url={ApiUrls.pieces_list} url={ApiUrls.pieces_list}
handleSuccess={this.props.handleSuccess} handleSuccess={handleSuccess}
buttons={ buttons={
<button <button
type="submit" type="submit"
className="btn btn-default btn-wide" className="btn btn-default btn-wide"
disabled={!this.state.isUploadReady || this.props.disabled}> disabled={!isUploadReady || disabled}>
{this.props.submitMessage} {submitMessage}
</button> </button>
} }
spinner={ spinner={
@ -99,7 +120,7 @@ let RegisterPieceForm = React.createClass({
</span> </span>
}> }>
<div className="ascribe-form-header"> <div className="ascribe-form-header">
<h3>{this.props.headerMessage}</h3> <h3>{headerMessage}</h3>
</div> </div>
<Property <Property
name="digital_work_key" name="digital_work_key"
@ -113,13 +134,37 @@ let RegisterPieceForm = React.createClass({
url: ApiUrls.blob_digitalworks url: ApiUrls.blob_digitalworks
}} }}
validation={AppConstants.fineUploader.validation.registerWork} validation={AppConstants.fineUploader.validation.registerWork}
setIsUploadReady={this.setIsUploadReady} setIsUploadReady={this.setIsUploadReady('digitalWorkKeyReady')}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile} isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
isFineUploaderActive={this.props.isFineUploaderActive} isFineUploaderActive={isFineUploaderActive}
onLoggedOut={this.props.onLoggedOut} onLoggedOut={onLoggedOut}
disabled={!this.props.isFineUploaderEditable} disabled={!isFineUploaderEditable}
enableLocalHashing={enableLocalHashing} enableLocalHashing={hashLocally}
uploadMethod={this.props.location.query.method} /> uploadMethod={location.query.method} />
</Property>
<Property
name="thumbnail_file">
<InputFineUploader
fileInputElement={UploadButton}
createBlobRoutine={{
url: ApiUrls.blob_thumbnails
}}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'thumbnail'
}}
validation={{
itemLimit: AppConstants.fineUploader.validation.registerWork.itemLimit,
sizeLimit: AppConstants.fineUploader.validation.additionalData.sizeLimit,
allowedExtensions: ['png', 'jpg', 'jpeg', 'gif']
}}
setIsUploadReady={this.setIsUploadReady('thumbnailKeyReady')}
location={location}
fileClassToUpload={{
singular: getLangText('Select representative image'),
plural: getLangText('Select representative images')
}}/>
</Property> </Property>
<Property <Property
name='artist_name' name='artist_name'
@ -146,7 +191,7 @@ let RegisterPieceForm = React.createClass({
min={1} min={1}
required/> required/>
</Property> </Property>
{this.props.children} {children}
</Form> </Form>
); );
} }

View File

@ -220,6 +220,19 @@ let Property = React.createClass({
}); });
}, },
getLabelAndErrors() {
if(this.props.label || this.state.errors) {
return (
<p>
<span className="pull-left">{this.props.label}</span>
<span className="pull-right">{this.state.errors}</span>
</p>
);
} else {
return null;
}
},
render() { render() {
let footer = null; let footer = null;
let tooltip = <span/>; let tooltip = <span/>;
@ -253,10 +266,7 @@ let Property = React.createClass({
placement="top" placement="top"
overlay={tooltip}> overlay={tooltip}>
<div className={'ascribe-property ' + this.props.className}> <div className={'ascribe-property ' + this.props.className}>
<p> {this.getLabelAndErrors()}
<span className="pull-left">{this.props.label}</span>
<span className="pull-right">{this.state.errors}</span>
</p>
{this.renderChildren(style)} {this.renderChildren(style)}
{footer} {footer}
</div> </div>