'use strict'; import React from 'react'; import UserStore from '../../stores/user_store'; import UserActions from '../../actions/user_actions'; import Form from './form'; import Property from './property'; import InputFineUploader from './input_fineuploader'; import FormSubmitButton from '../ascribe_buttons/form_submit_button'; import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button'; import AscribeSpinner from '../ascribe_spinner'; import ApiUrls from '../../constants/api_urls'; import AppConstants from '../../constants/application_constants'; import { validationParts, validationTypes } from '../../constants/uploader_constants'; import { getLangText } from '../../utils/lang_utils'; import { mergeOptions } from '../../utils/general_utils'; import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils'; let RegisterPieceForm = React.createClass({ propTypes: { headerMessage: React.PropTypes.string, submitMessage: React.PropTypes.string, handleSuccess: React.PropTypes.func, isFineUploaderActive: React.PropTypes.bool, isFineUploaderEditable: React.PropTypes.bool, enableLocalHashing: React.PropTypes.bool, enableSeparateThumbnail: React.PropTypes.bool, // For this form to work with SlideContainer, we sometimes have to disable it disabled: React.PropTypes.bool, location: React.PropTypes.object, children: React.PropTypes.oneOfType([ React.PropTypes.arrayOf(React.PropTypes.element), React.PropTypes.element ]) }, getDefaultProps() { return { headerMessage: getLangText('Register your work'), submitMessage: getLangText('Register work'), enableLocalHashing: true, enableSeparateThumbnail: true }; }, getInitialState(){ return mergeOptions( { digitalWorkFile: null }, UserStore.getState() ); }, componentDidMount() { UserStore.listen(this.onChange); UserActions.fetchCurrentUser(); }, componentWillUnmount() { UserStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); }, /** * This method is overloaded so that we can track the ready-state * of each uploader in the component * @param {string} uploaderKey Name of the uploader's key to track */ setIsUploadReady(uploaderKey) { return (isUploadReady) => { // See documentation of `FormSubmitButton` for more detailed information // on this. this.refs.submitButton.setReadyStateForKey(uploaderKey, isUploadReady); }; }, handleChangedDigitalWork(digitalWorkFile) { if (digitalWorkFile && (digitalWorkFile.status === 'deleted' || digitalWorkFile.status === 'canceled')) { this.refs.form.refs.thumbnail_file.reset(); // Manually we need to set the ready state for `thumbnailKeyReady` back // to `true` as `ReactS3Fineuploader`'s `reset` method triggers // `setIsUploadReady` with `false` this.refs.submitButton.setReadyStateForKey('thumbnailKeyReady', true); this.setState({ digitalWorkFile: null }); } else { this.setState({ digitalWorkFile }); } }, handleChangedThumbnail(thumbnailFile) { const { digitalWorkFile } = this.state; const { fineuploader } = this.refs.digitalWorkFineUploader.refs; fineuploader.setThumbnailForFileId( digitalWorkFile.id, // if thumbnail was delete, we delete it from the display as well thumbnailFile.status !== 'deleted' ? thumbnailFile.url : null ); }, handleThumbnailValidationFailed(thumbnailFile) { // If the validation fails, set the thumbnail as submittable since its optional this.refs.submitButton.setReadyStateForKey('thumbnailKeyReady', true); }, isThumbnailDialogExpanded() { const { enableSeparateThumbnail } = this.props; const { digitalWorkFile } = this.state; if(digitalWorkFile && enableSeparateThumbnail) { const { type: mimeType } = digitalWorkFile; const mimeSubType = mimeType && mimeType.split('/').length ? mimeType.split('/')[1] : 'unknown'; return AppConstants.supportedThumbnailFileFormats.indexOf(mimeSubType) === -1; } else { return false; } }, render() { const { disabled, handleSuccess, submitMessage, headerMessage, isFineUploaderActive, isFineUploaderEditable, location, children, enableLocalHashing } = this.props; const { currentUser} = this.state; const profileHashLocally = currentUser && currentUser.profile ? currentUser.profile.hash_locally : false; const hashLocally = profileHashLocally && enableLocalHashing; return (
); } }); export default RegisterPieceForm;