From c3b71b5398fab9841a9aefb4ab114f9499f19b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 10 Sep 2015 10:51:47 +0200 Subject: [PATCH 1/5] WIP: make fineuploader an input --- .../further_details_fileuploader.js | 2 +- js/components/ascribe_forms/form.js | 17 +-- .../ascribe_forms/form_register_piece.js | 105 +++--------------- .../ascribe_forms/input_fineuploader.js | 93 ++++++++++++++++ 4 files changed, 118 insertions(+), 99 deletions(-) create mode 100644 js/components/ascribe_forms/input_fineuploader.js diff --git a/js/components/ascribe_detail/further_details_fileuploader.js b/js/components/ascribe_detail/further_details_fileuploader.js index fa1df933..f03339a5 100644 --- a/js/components/ascribe_detail/further_details_fileuploader.js +++ b/js/components/ascribe_detail/further_details_fileuploader.js @@ -39,7 +39,7 @@ let FurtherDetailsFileuploader = React.createClass({ return null; } - let otherDataIds = this.props.otherData ? this.props.otherData.map((data)=>{return data.id; }).join() : null; + let otherDataIds = this.props.otherData ? this.props.otherData.map((data) => data.id).join() : null; return ( { + return ReactAddons.Children.map(this.props.children, (child, i) => { if (child) { return ReactAddons.addons.cloneWithProps(child, { handleChange: this.handleChangeChild, @@ -251,6 +253,7 @@ let Form = React.createClass({ role="form" className={className} onSubmit={this.submit} + onReset={this.reset} autoComplete={this.props.autoComplete}> {this.getFakeAutocompletableInputs()} {this.getErrors()} diff --git a/js/components/ascribe_forms/form_register_piece.js b/js/components/ascribe_forms/form_register_piece.js index 3519c976..e9b3df57 100644 --- a/js/components/ascribe_forms/form_register_piece.js +++ b/js/components/ascribe_forms/form_register_piece.js @@ -7,13 +7,10 @@ import UserActions from '../../actions/user_actions'; import Form from './form'; import Property from './property'; +import InputFineUploader from './input_fineuploader'; -import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader'; - -import AppConstants from '../../constants/application_constants'; import ApiUrls from '../../constants/api_urls'; -import { getCookie } from '../../utils/fetch_api_utils'; import { getLangText } from '../../utils/lang_utils'; import { mergeOptions } from '../../utils/general_utils'; import { isReadyForFormSubmission } from '../ascribe_uploader/react_s3_fine_uploader_utils'; @@ -45,7 +42,6 @@ let RegisterPieceForm = React.createClass({ getInitialState(){ return mergeOptions( { - digitalWorkKey: null, isUploadReady: false }, UserStore.getState() @@ -65,18 +61,6 @@ let RegisterPieceForm = React.createClass({ this.setState(state); }, - getFormData(){ - return { - digital_work_key: this.state.digitalWorkKey - }; - }, - - submitKey(key){ - this.setState({ - digitalWorkKey: key - }); - }, - setIsUploadReady(isReady) { this.setState({ isUploadReady: isReady @@ -94,14 +78,22 @@ let RegisterPieceForm = React.createClass({ className="ascribe-form-bordered" ref='form' url={ApiUrls.pieces_list} - getFormData={this.getFormData} handleSuccess={this.props.handleSuccess} - buttons={} + + + + } spinner={ @@ -111,9 +103,9 @@ let RegisterPieceForm = React.createClass({

{this.props.headerMessage}

- - ); - } -}); - export default RegisterPieceForm; diff --git a/js/components/ascribe_forms/input_fineuploader.js b/js/components/ascribe_forms/input_fineuploader.js new file mode 100644 index 00000000..2867b46e --- /dev/null +++ b/js/components/ascribe_forms/input_fineuploader.js @@ -0,0 +1,93 @@ +'use strict'; + +import React from 'react'; + +import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader'; + +import AppConstants from '../../constants/application_constants'; +import ApiUrls from '../../constants/api_urls'; + +import { getCookie } from '../../utils/fetch_api_utils'; + +let InputFileUploader = React.createClass({ + propTypes: { + setIsUploadReady: React.PropTypes.func, + isReadyForFormSubmission: React.PropTypes.func, + onClick: React.PropTypes.func, + + // isFineUploaderActive is used to lock react fine uploader in case + // a user is actually not logged in already to prevent him from droping files + // before login in + isFineUploaderActive: React.PropTypes.bool, + onLoggedOut: React.PropTypes.func, + editable: React.PropTypes.bool, + enableLocalHashing: React.PropTypes.bool, + + // provided by Property + disabled: React.PropTypes.bool + }, + + getInitialState() { + return { + value: null + + }; + }, + + submitKey(key){ + this.setState({ + value: key + }); + }, + + render() { + + let editable = this.props.isFineUploaderActive; + + // if disabled is actually set by property, we want to override + // isFineUploaderActive + if(typeof this.props.disabled !== 'undefined') { + editable = !this.props.disabled; + } + + + return ( + + ); + } +}); + +export default InputFileUploader; \ No newline at end of file From 1d184973f445ec3ba41712c72848c1fe2a0763ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 10 Sep 2015 11:22:42 +0200 Subject: [PATCH 2/5] reset method for react s3 fineuploader --- .../ascribe_forms/input_fineuploader.js | 8 +++++--- js/components/ascribe_forms/property.js | 8 ++++++++ .../ascribe_uploader/react_s3_fine_uploader.js | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/js/components/ascribe_forms/input_fineuploader.js b/js/components/ascribe_forms/input_fineuploader.js index 2867b46e..52e1d5b5 100644 --- a/js/components/ascribe_forms/input_fineuploader.js +++ b/js/components/ascribe_forms/input_fineuploader.js @@ -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 ( Date: Thu, 10 Sep 2015 11:35:39 +0200 Subject: [PATCH 3/5] reset method for property collapsible --- js/components/ascribe_forms/form.js | 3 --- js/components/ascribe_forms/input_textarea_toggable.js | 10 +++++++--- js/components/ascribe_forms/property_collapsible.js | 7 +++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index 0429fd4d..182e7ba7 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -61,7 +61,6 @@ let Form = React.createClass({ }, reset() { - console.log(this.refs); for(let ref in this.refs) { if (typeof this.refs[ref].reset === 'function'){ this.refs[ref].reset(); @@ -106,12 +105,10 @@ let Form = React.createClass({ data[this.refs[ref].props.name] = this.refs[ref].state.value; } - console.log(this.props); if (this.props.getFormData){ data = mergeOptionsWithDuplicates(data, this.props.getFormData()); } - console.log(data); return data; }, diff --git a/js/components/ascribe_forms/input_textarea_toggable.js b/js/components/ascribe_forms/input_textarea_toggable.js index bc70c530..ac3994a7 100644 --- a/js/components/ascribe_forms/input_textarea_toggable.js +++ b/js/components/ascribe_forms/input_textarea_toggable.js @@ -4,6 +4,7 @@ import React from 'react'; import TextareaAutosize from 'react-textarea-autosize'; + let InputTextAreaToggable = React.createClass({ propTypes: { editable: React.PropTypes.bool.isRequired, @@ -17,14 +18,17 @@ let InputTextAreaToggable = React.createClass({ value: this.props.defaultValue }; }, + handleChange(event) { this.setState({value: event.target.value}); this.props.onChange(event); }, + render() { let className = 'form-control ascribe-textarea'; let textarea = null; - if (this.props.editable){ + + if(this.props.editable) { className = className + ' ascribe-textarea-editable'; textarea = ( ); - } - else{ + } else { textarea =
{this.state.value}
; } + return textarea; } }); diff --git a/js/components/ascribe_forms/property_collapsible.js b/js/components/ascribe_forms/property_collapsible.js index 03ec404d..ef9a1329 100644 --- a/js/components/ascribe_forms/property_collapsible.js +++ b/js/components/ascribe_forms/property_collapsible.js @@ -42,6 +42,13 @@ let PropertyCollapsile = React.createClass({ } }, + reset() { + // If the child input is a native HTML element, it will be reset automatically + // by the DOM. + // However, we need to collapse this component again. + this.setState(this.getInitialState()); + }, + render() { let tooltip = ; if (this.props.tooltip){ From 5588f766c1a82f4e761dd59dfde3828eb7dccce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 10 Sep 2015 13:24:32 +0200 Subject: [PATCH 4/5] add reset functionality for InputDate and LoanForm --- js/components/ascribe_forms/form.js | 22 ++++++++++++++++--- js/components/ascribe_forms/form_loan.js | 10 +++++---- .../ascribe_forms/form_register_piece.js | 19 +++++----------- js/components/ascribe_forms/input_date.js | 7 +++++- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index 182e7ba7..115a8d8e 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -41,7 +41,9 @@ let Form = React.createClass({ // It will make use of the GlobalNotification isInline: React.PropTypes.bool, - autoComplete: React.PropTypes.string + autoComplete: React.PropTypes.string, + + onReset: React.PropTypes.func }, getDefaultProps() { @@ -61,6 +63,12 @@ let Form = React.createClass({ }, reset() { + // If onReset prop is defined from outside, + // notify component that a form reset is happening. + if(this.props.onReset && typeof this.props.onReset === 'function') { + this.props.onReset(); + } + for(let ref in this.refs) { if (typeof this.refs[ref].reset === 'function'){ this.refs[ref].reset(); @@ -184,8 +192,16 @@ let Form = React.createClass({ buttons = (

- - + +

); diff --git a/js/components/ascribe_forms/form_loan.js b/js/components/ascribe_forms/form_loan.js index 276ff492..60dad486 100644 --- a/js/components/ascribe_forms/form_loan.js +++ b/js/components/ascribe_forms/form_loan.js @@ -69,10 +69,11 @@ let LoanForm = React.createClass({ }, handleOnChange(event) { - let potentialEmail = event.target.value; - - if(potentialEmail.match(/.*@.*/)) { - LoanContractActions.fetchLoanContract(potentialEmail); + // event.target.value is the submitted email of the loanee + if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) { + LoanContractActions.fetchLoanContract(event.target.value); + } else { + LoanContractActions.flushLoanContract(); } }, @@ -143,6 +144,7 @@ let LoanForm = React.createClass({ ref='form' url={this.props.url} getFormData={this.getFormData} + onReset={this.handleOnChange} handleSuccess={this.props.handleSuccess} buttons={this.getButtons()} spinner={ diff --git a/js/components/ascribe_forms/form_register_piece.js b/js/components/ascribe_forms/form_register_piece.js index e9b3df57..8f2666c0 100644 --- a/js/components/ascribe_forms/form_register_piece.js +++ b/js/components/ascribe_forms/form_register_piece.js @@ -80,19 +80,12 @@ let RegisterPieceForm = React.createClass({ url={ApiUrls.pieces_list} handleSuccess={this.props.handleSuccess} buttons={ - - - - + } spinner={ diff --git a/js/components/ascribe_forms/input_date.js b/js/components/ascribe_forms/input_date.js index 837221e5..3e2892c0 100644 --- a/js/components/ascribe_forms/input_date.js +++ b/js/components/ascribe_forms/input_date.js @@ -18,7 +18,8 @@ let InputDate = React.createClass({ getInitialState() { return { - value: null + value: null, + value_moment: null }; }, @@ -45,6 +46,10 @@ let InputDate = React.createClass({ }); }, + reset() { + this.setState(this.getInitialState()); + }, + render() { return (
From b5e5102ea4260c9d966ed411efa56a83572b3e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 10 Sep 2015 14:00:59 +0200 Subject: [PATCH 5/5] replace in keyword with dot notation checking --- .../ascribe_detail/edition_container.js | 2 +- .../ascribe_detail/piece_container.js | 2 +- js/components/ascribe_forms/form.js | 23 ++++++++++--------- js/components/ascribe_forms/property.js | 12 ++++++---- .../slides_container.js | 11 ++++++--- .../ascribe_detail/prize_piece_container.js | 11 ++++++++- .../ascribe_detail/cyland_piece_container.js | 2 +- .../cyland/cyland_register_piece.js | 3 +++ .../ascribe_detail/ikonotv_piece_container.js | 2 +- 9 files changed, 45 insertions(+), 23 deletions(-) diff --git a/js/components/ascribe_detail/edition_container.js b/js/components/ascribe_detail/edition_container.js index 15086434..2194123d 100644 --- a/js/components/ascribe_detail/edition_container.js +++ b/js/components/ascribe_detail/edition_container.js @@ -50,7 +50,7 @@ let EditionContainer = React.createClass({ }, render() { - if('title' in this.state.edition) { + if(this.state.edition && this.state.edition.title) { return ( this[this.props.method](), 100); } else { throw new Error('This HTTP method is not supported by form.js (' + this.props.method + ')'); @@ -109,11 +109,11 @@ let Form = React.createClass({ getFormData() { let data = {}; - for (let ref in this.refs){ + for(let ref in this.refs){ data[this.refs[ref].props.name] = this.refs[ref].state.value; } - if (this.props.getFormData){ + if (this.props.getFormData && typeof this.props.getFormData === 'function'){ data = mergeOptionsWithDuplicates(data, this.props.getFormData()); } @@ -125,11 +125,12 @@ let Form = React.createClass({ }, handleSuccess(response){ - if ('handleSuccess' in this.props){ + if(this.props.handleSuccess && typeof this.props.handleSuccess === 'function') { this.props.handleSuccess(response); } - for (var ref in this.refs){ - if ('handleSuccess' in this.refs[ref]){ + + for(let ref in this.refs) { + if(this.refs[ref] && this.refs[ref].handleSuccess && typeof this.refs[ref].handleSuccess === 'function'){ this.refs[ref].handleSuccess(); } } @@ -141,7 +142,7 @@ let Form = React.createClass({ handleError(err){ if (err.json) { - for (var input in err.json.errors){ + for (let input in err.json.errors){ if (this.refs && this.refs[input] && this.refs[input].state) { this.refs[input].setErrors(err.json.errors[input]); } else { @@ -171,8 +172,8 @@ let Form = React.createClass({ }, clearErrors(){ - for (var ref in this.refs){ - if ('clearErrors' in this.refs[ref]){ + for(let ref in this.refs){ + if (this.refs[ref] && this.refs[ref].clearErrors && typeof this.refs[ref].clearErrors === 'function'){ this.refs[ref].clearErrors(); } } @@ -221,7 +222,7 @@ let Form = React.createClass({ }, renderChildren() { - return ReactAddons.Children.map(this.props.children, (child, i) => { + return ReactAddons.Children.map(this.props.children, (child) => { if (child) { return ReactAddons.addons.cloneWithProps(child, { handleChange: this.handleChangeChild, diff --git a/js/components/ascribe_forms/property.js b/js/components/ascribe_forms/property.js index de88e1a0..61c5c96e 100644 --- a/js/components/ascribe_forms/property.js +++ b/js/components/ascribe_forms/property.js @@ -29,8 +29,11 @@ let Property = React.createClass({ handleChange: React.PropTypes.func, ignoreFocus: React.PropTypes.bool, className: React.PropTypes.string, + onClick: React.PropTypes.func, onChange: React.PropTypes.func, + onBlur: React.PropTypes.func, + children: React.PropTypes.oneOfType([ React.PropTypes.arrayOf(React.PropTypes.element), React.PropTypes.element @@ -109,7 +112,7 @@ let Property = React.createClass({ handleChange(event) { this.props.handleChange(event); - if ('onChange' in this.props) { + if (this.props.onChange && typeof this.props.onChange === 'function') { this.props.onChange(event); } @@ -125,7 +128,7 @@ let Property = React.createClass({ // if onClick is defined from the outside, // just call it - if(this.props.onClick) { + if(this.props.onClick && typeof this.props.onClick === 'function') { this.props.onClick(); } @@ -140,7 +143,7 @@ let Property = React.createClass({ isFocused: false }); - if(this.props.onBlur) { + if(this.props.onBlur && typeof this.props.onBlur === 'function') { this.props.onBlur(event); } }, @@ -198,6 +201,7 @@ let Property = React.createClass({ }, render() { + let footer = null; let tooltip = ; let style = this.props.style ? mergeOptions({}, this.props.style) : {}; @@ -207,7 +211,7 @@ let Property = React.createClass({ {this.props.tooltip} ); } - let footer = null; + if(this.props.footer){ footer = (
diff --git a/js/components/ascribe_slides_container/slides_container.js b/js/components/ascribe_slides_container/slides_container.js index 8b800377..c78478f1 100644 --- a/js/components/ascribe_slides_container/slides_container.js +++ b/js/components/ascribe_slides_container/slides_container.js @@ -4,13 +4,12 @@ import React from 'react'; import Router from 'react-router'; import ReactAddons from 'react/addons'; -import Col from 'react-bootstrap/lib/Col'; - import SlidesContainerBreadcrumbs from './slides_container_breadcrumbs'; let State = Router.State; let Navigation = Router.Navigation; + let SlidesContainer = React.createClass({ propTypes: { children: React.PropTypes.arrayOf(React.PropTypes.element), @@ -30,12 +29,15 @@ let SlidesContainer = React.createClass({ let slideNum = -1; let startFrom = -1; - if(queryParams && 'slide_num' in queryParams) { + // We can actually need to check if slide_num is present as a key in queryParams. + // We do not really care about its value though... + if(queryParams && 'slide_num' in queryParams.slide_num) { slideNum = parseInt(queryParams.slide_num, 10); } // if slide_num is not set, this will be done in componentDidMount // the query param 'start_from' removes all slide children before the respective number + // Also, we use the 'in' keyword for the same reason as above in 'slide_num' if(queryParams && 'start_from' in queryParams) { startFrom = parseInt(queryParams.start_from, 10); } @@ -51,6 +53,9 @@ let SlidesContainer = React.createClass({ componentDidMount() { // check if slide_num was defined, and if not then default to 0 let queryParams = this.getQuery(); + + // We use 'in' to check if the key is present in the user's browser url bar, + // we do not really care about its value at this point if(!('slide_num' in queryParams)) { // we're first requiring all the other possible queryParams and then set diff --git a/js/components/whitelabel/prize/components/ascribe_detail/prize_piece_container.js b/js/components/whitelabel/prize/components/ascribe_detail/prize_piece_container.js index 4b785fc2..822557db 100644 --- a/js/components/whitelabel/prize/components/ascribe_detail/prize_piece_container.js +++ b/js/components/whitelabel/prize/components/ascribe_detail/prize_piece_container.js @@ -90,14 +90,23 @@ let PieceContainer = React.createClass({ }, render() { - if('title' in this.state.piece) { + if(this.state.piece && this.state.piece.title) { + /* + + This really needs a refactor! + + - Tim + + */ // Only show the artist name if you are the participant or if you are a judge and the piece is shortlisted let artistName = ((this.state.currentUser.is_jury && !this.state.currentUser.is_judge) || (this.state.currentUser.is_judge && !this.state.piece.selected )) ?