1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 10:25:08 +01:00

Clean up components using the uploader in preparation for move to ascribe/react-components

This commit is contained in:
Brett Sun 2016-02-15 15:48:49 +01:00
parent 4a860364d3
commit 8650b0497c
11 changed files with 57 additions and 55 deletions

View File

@ -1,8 +1,8 @@
.
server.js
gulpfile.js
node_modules
node_modules/*
js/**/__tests__
server.js
js/components/ascribe_uploader/vendor
js/components/ascribe_uploader/vendor

View File

@ -45,13 +45,13 @@ let FurtherDetails = React.createClass({
GlobalNotificationActions.appendGlobalNotification(notification);
},
submitFile(file) {
onSubmitFile(file) {
this.setState({
otherDataKey: file.key
});
},
setIsUploadReady(isReady) {
setIsUploaderValidated(isReady) {
this.setState({
isUploadReady: isReady
});
@ -87,8 +87,8 @@ let FurtherDetails = React.createClass({
pieceId={pieceId} />
<Form>
<FurtherDetailsFileuploader
submitFile={this.submitFile}
setIsUploadReady={this.setIsUploadReady}
onSubmitFile={this.onSubmitFile}
setIsUploaderValidated={this.setIsUploaderValidated}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
editable={editable}
overrideForm={true}

View File

@ -27,10 +27,10 @@ let FurtherDetailsFileuploader = React.createClass({
// Props for ReactS3FineUploader
areAssetsDownloadable: bool,
isReadyForFormSubmission: func,
submitFile: func, // TODO: rename to onSubmitFile
onSubmitFile: func,
onValidationFailed: func,
multiple: bool,
setIsUploadReady: func, //TODO: rename to setIsUploaderValidated
setIsUploaderValidated: func,
showErrorPrompt: bool,
validation: ReactS3FineUploader.propTypes.validation
},
@ -51,9 +51,9 @@ let FurtherDetailsFileuploader = React.createClass({
onValidationFailed,
otherData,
pieceId,
setIsUploadReady,
setIsUploaderValidated,
showErrorPrompt,
submitFile,
onSubmitFile,
validation } = this.props;
// Essentially there a three cases important to the fileuploader
@ -94,7 +94,7 @@ let FurtherDetailsFileuploader = React.createClass({
}}
multiple={multiple}
onValidationFailed={onValidationFailed}
setIsUploadReady={setIsUploadReady}
setIsUploaderValidated={setIsUploaderValidated}
session={{
endpoint: AppConstants.serverUrl + 'api/blob/otherdatas/fineuploader_session/',
customHeaders: {
@ -114,7 +114,7 @@ let FurtherDetailsFileuploader = React.createClass({
'X-CSRFToken': getCookie(AppConstants.csrftoken)
}
}}
submitFile={submitFile}
onSubmitFile={onSubmitFile}
showErrorPrompt={showErrorPrompt}
validation={validation} />
</Property>

View File

@ -39,7 +39,7 @@ let CreateContractForm = React.createClass({
};
},
setIsUploadReady(isReady) {
setIsUploaderValidated(isReady) {
this.setState({
isUploadReady: isReady
});
@ -52,7 +52,7 @@ let CreateContractForm = React.createClass({
this.refs.form.reset();
},
submitFile({ originalName }) {
onSubmitFile({ originalName }) {
this.setState({
contractName: originalName
});
@ -70,7 +70,7 @@ let CreateContractForm = React.createClass({
name="blob"
label={getLangText('Contract file (*.pdf only, max. 50MB per contract)')}>
<InputFineUploader
submitFile={this.submitFile}
onSubmitFile={this.onSubmitFile}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'contract'
@ -85,7 +85,7 @@ let CreateContractForm = React.createClass({
}}
areAssetsDownloadable={true}
areAssetsEditable={true}
setIsUploadReady={this.setIsUploadReady}
setIsUploaderValidated={this.setIsUploaderValidated}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
fileClassToUpload={this.props.fileClassToUpload} />
</Property>

View File

@ -63,7 +63,7 @@ let RegisterPieceForm = React.createClass({
* of each uploader in the component
* @param {string} uploaderKey Name of the uploader's key to track
*/
setIsUploadReady(uploaderKey) {
setIsUploaderValidated(uploaderKey) {
return (isUploadReady) => {
// See documentation of `FormSubmitButton` for more detailed information
// on this.
@ -78,7 +78,7 @@ let RegisterPieceForm = React.createClass({
// Manually we need to set the ready state for `thumbnailKeyReady` back
// to `true` as `ReactS3Fineuploader`'s `reset` method triggers
// `setIsUploadReady` with `false`
// `setIsUploaderValidated` with `false`
this.refs.submitButton.setReadyStateForKey('thumbnailKeyReady', true);
this.setState({ digitalWorkFile: null });
} else {
@ -97,9 +97,11 @@ let RegisterPieceForm = React.createClass({
);
},
handleThumbnailValidationFailed(thumbnailFile) {
// If the validation fails, set the thumbnail as submittable since its optional
this.refs.submitButton.setReadyStateForKey('thumbnailKeyReady', true);
handleThumbnailValidationFailed(thumbnailFile, error) {
if (error.type !== ValidationErrors.EXTRA_FILES) {
// If the validation fails, set the thumbnail as submittable since its optional
this.refs.submitButton.setReadyStateForKey('thumbnailKeyReady', true);
}
},
isThumbnailDialogExpanded() {
@ -169,13 +171,13 @@ let RegisterPieceForm = React.createClass({
url: ApiUrls.blob_digitalworks
}}
validation={validationTypes.registerWork}
setIsUploadReady={this.setIsUploadReady('digitalWorkKeyReady')}
setIsUploaderValidated={this.setIsUploaderValidated('digitalWorkKeyReady')}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
isFineUploaderActive={isFineUploaderActive}
disabled={!isFineUploaderEditable}
enableLocalHashing={hashLocally}
uploadMethod={location.query.method}
handleChangedFile={this.handleChangedDigitalWork}
onStatusChange={this.handleChangedDigitalWork}
showErrorPrompt />
</Property>
<Property
@ -187,7 +189,7 @@ let RegisterPieceForm = React.createClass({
createBlobRoutine={{
url: ApiUrls.blob_thumbnails
}}
handleChangedFile={this.handleChangedThumbnail}
onStatusChange={this.handleChangedThumbnail}
onValidationFailed={this.handleThumbnailValidationFailed}
isReadyForFormSubmission={formSubmissionValidation.fileOptional}
keyRoutine={{
@ -199,7 +201,7 @@ let RegisterPieceForm = React.createClass({
sizeLimit: validationTypes.workThumbnail.sizeLimit,
allowedExtensions: validationParts.allowedExtensions.images
}}
setIsUploadReady={this.setIsUploadReady('thumbnailKeyReady')}
setIsUploaderValidated={this.setIsUploaderValidated('thumbnailKeyReady')}
fileClassToUpload={{
singular: getLangText('Select representative image'),
plural: getLangText('Select representative images')

View File

@ -31,10 +31,10 @@ const InputFineUploader = React.createClass({
fileInputElement: ReactS3FineUploader.propTypes.fileInputElement,
isReadyForFormSubmission: func,
keyRoutine: ReactS3FineUploader.propTypes.keyRoutine,
handleChangedFile: func, // TODO: rename to onChangedFile
submitFile: func, // TODO: rename to onSubmitFile
onStatusChange: func,
onSubmitFile: func,
onValidationFailed: func,
setIsUploadReady: func, //TODO: rename to setIsUploaderValidated
setIsUploaderValidated: func,
setWarning: func,
showErrorPrompt: bool,
uploadMethod: oneOf(['hash', 'upload']),
@ -54,7 +54,7 @@ const InputFineUploader = React.createClass({
};
},
submitFile(file) {
onSubmitFile(file) {
this.setState({
file,
value: file.key
@ -64,8 +64,8 @@ const InputFineUploader = React.createClass({
this.props.onChange({ target: { value: this.state.value } });
}
if (typeof this.props.submitFile === 'function') {
this.props.submitFile(file);
if (typeof this.props.onSubmitFile === 'function') {
this.props.onSubmitFile(file);
}
},
@ -87,12 +87,12 @@ const InputFineUploader = React.createClass({
disabled,
fileClassToUpload,
fileInputElement,
handleChangedFile,
onStatusChange,
isFineUploaderActive,
isReadyForFormSubmission,
keyRoutine,
onValidationFailed,
setIsUploadReady,
setIsUploaderValidated,
setWarning,
showErrorPrompt,
uploadMethod,
@ -112,9 +112,9 @@ const InputFineUploader = React.createClass({
keyRoutine={keyRoutine}
createBlobRoutine={createBlobRoutine}
validation={validation}
submitFile={this.submitFile}
onSubmitFile={this.onSubmitFile}
onValidationFailed={onValidationFailed}
setIsUploadReady={setIsUploadReady}
setIsUploaderValidated={setIsUploaderValidated}
isReadyForFormSubmission={isReadyForFormSubmission}
areAssetsDownloadable={areAssetsDownloadable}
areAssetsEditable={editable}
@ -137,7 +137,7 @@ const InputFineUploader = React.createClass({
enableLocalHashing={enableLocalHashing}
uploadMethod={uploadMethod}
fileClassToUpload={fileClassToUpload}
handleChangedFile={handleChangedFile} />
onStatusChange={onStatusChange} />
);
}
});

View File

@ -24,7 +24,7 @@ let ContractSettingsUpdateButton = React.createClass({
contract: React.PropTypes.object
},
submitFile(file) {
onSubmitFile(file) {
// override the blob with the key's value
const contract = Object.assign(this.props.contract, { blob: file.key });
@ -45,13 +45,13 @@ let ContractSettingsUpdateButton = React.createClass({
const notification = new GlobalNotificationModel(getLangText('Latest contract failed to load'), 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
return Promise.reject(err);
throw err;
});
}, (err) => {
const notification = new GlobalNotificationModel(getLangText('Contract could not be updated'), 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
return Promise.reject(err);
throw err;
})
.catch(console.logGlobal);
},
@ -73,7 +73,7 @@ let ContractSettingsUpdateButton = React.createClass({
sizeLimit: validationTypes.additionalData.sizeLimit,
allowedExtensions: ['pdf']
}}
setIsUploadReady={() =>{/* So that ReactS3FineUploader is not complaining */}}
setIsUploaderValidated={() =>{/* So that ReactS3FineUploader is not complaining */}}
signature={{
endpoint: AppConstants.serverUrl + 's3/signature/',
customHeaders: {
@ -93,7 +93,7 @@ let ContractSettingsUpdateButton = React.createClass({
plural: getLangText('UPDATE')
}}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
submitFile={this.submitFile} />
onSubmitFile={this.onSubmitFile} />
);
}
});

View File

@ -150,7 +150,7 @@ const PRRegisterPieceForm = React.createClass({
* of each uploader in the component
* @param {string} uploaderKey Name of the uploader's key to track
*/
setIsUploadReady(uploaderKey) {
setIsUploaderValidated(uploaderKey) {
return (isUploadReady) => {
this.setState({
[uploaderKey]: isUploadReady
@ -297,7 +297,7 @@ const PRRegisterPieceForm = React.createClass({
<InputFineuploader
fileInputElement={UploadButton()}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
setIsUploadReady={this.setIsUploadReady('digitalWorkKeyReady')}
setIsUploaderValidated={this.setIsUploaderValidated('digitalWorkKeyReady')}
createBlobRoutine={{
url: ApiUrls.blob_digitalworks
}}
@ -326,7 +326,7 @@ const PRRegisterPieceForm = React.createClass({
url: ApiUrls.blob_thumbnails
}}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
setIsUploadReady={this.setIsUploadReady('thumbnailKeyReady')}
setIsUploaderValidated={this.setIsUploaderValidated('thumbnailKeyReady')}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'thumbnail'
@ -349,7 +349,7 @@ const PRRegisterPieceForm = React.createClass({
<InputFineuploader
fileInputElement={UploadButton()}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
setIsUploadReady={this.setIsUploadReady('supportingMaterialsReady')}
setIsUploaderValidated={this.setIsUploaderValidated('supportingMaterialsReady')}
onValidationFailed={this.handleOptionalFileValidationFailed('supportingMaterialsReady')}
createBlobRoutine={this.getCreateBlobRoutine()}
keyRoutine={{
@ -372,7 +372,7 @@ const PRRegisterPieceForm = React.createClass({
<InputFineuploader
fileInputElement={UploadButton()}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
setIsUploadReady={this.setIsUploadReady('proofOfPaymentReady')}
setIsUploaderValidated={this.setIsUploaderValidated('proofOfPaymentReady')}
createBlobRoutine={this.getCreateBlobRoutine()}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',

View File

@ -475,8 +475,8 @@ let PrizePieceDetails = React.createClass({
})
}
<FurtherDetailsFileuploader
submitFile={() => {}}
setIsUploadReady={() => {}}
onSubmitFile={() => {}}
setIsUploaderValidated={() => {}}
isReadyForFormSubmission={() => {}}
editable={false}
overrideForm={true}

View File

@ -65,7 +65,7 @@ let CylandAdditionalDataForm = React.createClass({
},
setIsUploadReady(isReady) {
setIsUploaderValidated(isReady) {
this.setState({
isUploadReady: isReady
});
@ -185,8 +185,8 @@ let CylandAdditionalDataForm = React.createClass({
</Property>
<FurtherDetailsFileuploader
label={getLangText('Additional files (e.g. still images, pdf)')}
submitFile={function () {}}
setIsUploadReady={this.setIsUploadReady}
onSubmitFile={function () {}}
setIsUploaderValidated={this.setIsUploaderValidated}
isReadyForFormSubmission={formSubmissionValidation.fileOptional}
pieceId={piece.id}
otherData={piece.other_data}

View File

@ -100,7 +100,7 @@ let MarketAdditionalDataForm = React.createClass({
GlobalNotificationActions.appendGlobalNotification(notification);
},
setIsUploadReady(isReady) {
setIsUploaderValidated(isReady) {
this.setState({
isUploadReady: isReady
});
@ -168,8 +168,8 @@ let MarketAdditionalDataForm = React.createClass({
label={getLangText('Marketplace Thumbnail Image')}
otherData={otherData}
pieceId={pieceId}
setIsUploadReady={this.setIsUploadReady}
submitFile={function () {}}
setIsUploaderValidated={this.setIsUploaderValidated}
onSubmitFile={function () {}}
validation={{
itemLimit: validationTypes.workThumbnail.itemLimit,
sizeLimit: validationTypes.workThumbnail.sizeLimit,