mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
replace in keyword with dot notation checking
This commit is contained in:
parent
5588f766c1
commit
b5e5102ea4
@ -50,7 +50,7 @@ let EditionContainer = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
if('title' in this.state.edition) {
|
||||
if(this.state.edition && this.state.edition.title) {
|
||||
return (
|
||||
<Edition
|
||||
edition={this.state.edition}
|
||||
|
@ -206,7 +206,7 @@ let PieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
if('title' in this.state.piece) {
|
||||
if(this.state.piece && this.state.piece.title) {
|
||||
return (
|
||||
<Piece
|
||||
piece={this.state.piece}
|
||||
|
@ -70,7 +70,7 @@ let Form = React.createClass({
|
||||
}
|
||||
|
||||
for(let ref in this.refs) {
|
||||
if (typeof this.refs[ref].reset === 'function'){
|
||||
if (this.refs[ref].reset && typeof this.refs[ref].reset === 'function'){
|
||||
this.refs[ref].reset();
|
||||
}
|
||||
}
|
||||
@ -86,7 +86,7 @@ let Form = React.createClass({
|
||||
this.clearErrors();
|
||||
|
||||
// selecting http method based on props
|
||||
if(this[this.props.method]) {
|
||||
if(this[this.props.method] && typeof this[this.props.method] === 'function') {
|
||||
window.setTimeout(() => 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,
|
||||
|
@ -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 = <span/>;
|
||||
let style = this.props.style ? mergeOptions({}, this.props.style) : {};
|
||||
|
||||
@ -207,7 +211,7 @@ let Property = React.createClass({
|
||||
{this.props.tooltip}
|
||||
</Tooltip>);
|
||||
}
|
||||
let footer = null;
|
||||
|
||||
if(this.props.footer){
|
||||
footer = (
|
||||
<div className="ascribe-property-footer">
|
||||
|
@ -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
|
||||
|
@ -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 )) ?
|
||||
<span className="glyphicon glyphicon-eye-close" aria-hidden="true"/> : this.state.piece.artist_name;
|
||||
|
||||
// Only show the artist email if you are a judge and the piece is shortlisted
|
||||
let artistEmail = (this.state.currentUser.is_judge && this.state.piece.selected ) ?
|
||||
<DetailProperty label={getLangText('REGISTREE')} value={ this.state.piece.user_registered } /> : null;
|
||||
|
||||
return (
|
||||
<Piece
|
||||
piece={this.state.piece}
|
||||
|
@ -68,7 +68,7 @@ let CylandPieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
if('title' in this.state.piece) {
|
||||
if(this.state.piece && this.state.piece.title) {
|
||||
return (
|
||||
<Piece
|
||||
piece={this.state.piece}
|
||||
|
@ -72,6 +72,9 @@ let CylandRegisterPiece = React.createClass({
|
||||
// we may need to enter the process at step 1 or 2.
|
||||
// If this is the case, we'll need the piece number to complete submission.
|
||||
// It is encoded in the URL as a queryParam and we're checking for it here.
|
||||
//
|
||||
// We're using 'in' here as we want to know if 'piece_id' is present in the url,
|
||||
// we don't care about the value.
|
||||
if(queryParams && 'piece_id' in queryParams) {
|
||||
PieceActions.fetchOne(queryParams.piece_id);
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ let IkonotvPieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
render() {
|
||||
if('title' in this.state.piece) {
|
||||
if(this.state.piece && this.state.piece.title) {
|
||||
return (
|
||||
<Piece
|
||||
piece={this.state.piece}
|
||||
|
Loading…
Reference in New Issue
Block a user