|
@ -22,11 +22,17 @@ const styles = { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
class BikeForm extends React.Component { |
|
|
class BikeForm extends React.Component { |
|
|
constructor({ bike }) { |
|
|
constructor({ bike, editing = false }) { |
|
|
super(); |
|
|
super(); |
|
|
this.state = { |
|
|
if (editing) { |
|
|
bike, |
|
|
this.state = { |
|
|
}; |
|
|
bike, |
|
|
|
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.state = { |
|
|
|
|
|
bike: {}, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this); |
|
|
this.handleChange = this.handleChange.bind(this); |
|
|
this.handleSizeChange = this.handleSizeChange.bind(this); |
|
|
this.handleSizeChange = this.handleSizeChange.bind(this); |
|
@ -74,10 +80,11 @@ class BikeForm extends React.Component { |
|
|
const id = this.state.bike.id; |
|
|
const id = this.state.bike.id; |
|
|
const data = JSON.stringify(this.state.bike); |
|
|
const data = JSON.stringify(this.state.bike); |
|
|
const csrfToken = Cookies.get('csrftoken'); |
|
|
const csrfToken = Cookies.get('csrftoken'); |
|
|
|
|
|
const url = this.props.editing ? `/api/v1/bikes/${id}/` : '/api/v1/bikes/'; |
|
|
|
|
|
|
|
|
fetch(`/api/v1/bikes/${id}/`, { |
|
|
fetch(url, { |
|
|
credentials: 'same-origin', |
|
|
credentials: 'same-origin', |
|
|
method: 'PUT', |
|
|
method: this.props.editing ? 'PUT' : 'POST', |
|
|
headers: { |
|
|
headers: { |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
|
'X-CSRFToken': csrfToken, |
|
|
'X-CSRFToken': csrfToken, |
|
@ -99,7 +106,8 @@ class BikeForm extends React.Component { |
|
|
cpic_searched_at, |
|
|
cpic_searched_at, |
|
|
created_at, |
|
|
created_at, |
|
|
stolen, |
|
|
stolen, |
|
|
} = this.state.bike; |
|
|
} = this.props.bike; |
|
|
|
|
|
const editing = this.props.editing; |
|
|
const createdAtFormatted = (moment(created_at).isValid()) ? moment(created_at).tz(timezone).fromNow() : ''; |
|
|
const createdAtFormatted = (moment(created_at).isValid()) ? moment(created_at).tz(timezone).fromNow() : ''; |
|
|
const claimedAtFormatted = (moment(claimed_at).isValid()) ? moment(claimed_at).tz(timezone).fromNow() : ''; |
|
|
const claimedAtFormatted = (moment(claimed_at).isValid()) ? moment(claimed_at).tz(timezone).fromNow() : ''; |
|
|
const cpicSearchedAtFormatted = (moment(cpic_searched_at).isValid()) ? moment(cpic_searched_at).tz(timezone) |
|
|
const cpicSearchedAtFormatted = (moment(cpic_searched_at).isValid()) ? moment(cpic_searched_at).tz(timezone) |
|
@ -159,53 +167,60 @@ class BikeForm extends React.Component { |
|
|
required |
|
|
required |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
{editing && |
|
|
<TextField |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
floatingLabelText="Created at" |
|
|
<TextField |
|
|
value={createdAtFormatted} |
|
|
floatingLabelText="Created at" |
|
|
fullWidth |
|
|
value={createdAtFormatted} |
|
|
readOnly |
|
|
fullWidth |
|
|
disabled |
|
|
readOnly |
|
|
/> |
|
|
disabled |
|
|
</div> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-grid"> |
|
|
} |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
|
|
|
<TextField |
|
|
|
|
|
floatingLabelText="Claimed on" |
|
|
|
|
|
value={claimedAtFormatted} |
|
|
|
|
|
fullWidth |
|
|
|
|
|
disabled |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
|
|
|
<TextField |
|
|
|
|
|
floatingLabelText="Claimed by" |
|
|
|
|
|
value={claimed_by} |
|
|
|
|
|
fullWidth |
|
|
|
|
|
disabled |
|
|
|
|
|
readonly |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
<div className="content-grid mdl-grid" style={styles.bottom}> |
|
|
{editing && |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<div className="mdl-grid"> |
|
|
<TextField floatingLabelText="CPIC searched" value={cpicSearchedAtFormatted} /> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
</div> |
|
|
<TextField |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
floatingLabelText="Claimed on" |
|
|
<Checkbox |
|
|
value={claimedAtFormatted} |
|
|
name="stolen" |
|
|
fullWidth |
|
|
label="Stolen" |
|
|
disabled |
|
|
labelPosition="left" |
|
|
/> |
|
|
style={styles.checkbox} |
|
|
</div> |
|
|
checked={stolen} |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
disabled |
|
|
<TextField |
|
|
/> |
|
|
floatingLabelText="Claimed by" |
|
|
|
|
|
value={claimed_by} |
|
|
|
|
|
fullWidth |
|
|
|
|
|
disabled |
|
|
|
|
|
readonly |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-cell mdl-cell--2-col"> |
|
|
} |
|
|
<FlatButton label="Check" onTouchTap={this.handleCpicCheck} disabled={!!cpic_searched_at} primary /> |
|
|
|
|
|
|
|
|
{editing && |
|
|
|
|
|
<div className="content-grid mdl-grid" style={styles.bottom}> |
|
|
|
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
|
|
|
<TextField floatingLabelText="CPIC searched" value={cpicSearchedAtFormatted} disabled /> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
|
|
|
<Checkbox |
|
|
|
|
|
name="stolen" |
|
|
|
|
|
label="Stolen" |
|
|
|
|
|
labelPosition="left" |
|
|
|
|
|
style={styles.checkbox} |
|
|
|
|
|
checked={stolen} |
|
|
|
|
|
disabled |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div className="mdl-cell mdl-cell--2-col"> |
|
|
|
|
|
<FlatButton label="Check" onTouchTap={this.handleCpicCheck} disabled={!!cpic_searched_at} primary /> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
<div className="mdl-grid" style={styles.bottom}> |
|
|
<div className="mdl-grid" style={styles.bottom}> |
|
|
<div className="mdl-cell mdl-cell--8-col"> |
|
|
<div className="mdl-cell mdl-cell--8-col"> |
|
|
<Source |
|
|
<Source |
|
@ -213,18 +228,20 @@ class BikeForm extends React.Component { |
|
|
onChange={this.handleSourceChange} |
|
|
onChange={this.handleSourceChange} |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
{editing && |
|
|
<div style={styles.block}> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<Checkbox |
|
|
<div style={styles.block}> |
|
|
checked={this.state.bike.stripped} |
|
|
<Checkbox |
|
|
name="stripped" |
|
|
checked={this.state.bike.stripped} |
|
|
label="Stripped" |
|
|
name="stripped" |
|
|
labelPosition="left" |
|
|
label="Stripped" |
|
|
style={styles.checkbox} |
|
|
labelPosition="left" |
|
|
onCheck={this.handleChange} |
|
|
style={styles.checkbox} |
|
|
/> |
|
|
onCheck={this.handleChange} |
|
|
|
|
|
/> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-cell right"> |
|
|
<div className="mdl-cell right"> |
|
|