2015-06-09 16:09:59 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2015-06-16 13:48:48 +02:00
|
|
|
import requests from '../../utils/requests';
|
2015-06-09 17:24:06 +02:00
|
|
|
|
2015-06-09 16:09:59 +02:00
|
|
|
import apiUrls from '../../constants/api_urls';
|
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
import Form from './form';
|
|
|
|
import Property from './property';
|
2015-06-09 16:09:59 +02:00
|
|
|
import InputTextAreaToggable from './input_textarea_toggable';
|
|
|
|
|
2015-06-09 17:24:06 +02:00
|
|
|
let PieceExtraDataForm = React.createClass({
|
2015-06-22 23:32:41 +02:00
|
|
|
propTypes: {
|
|
|
|
edition: React.PropTypes.object,
|
|
|
|
handleSuccess: React.PropTypes.func,
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
title: React.PropTypes.string,
|
|
|
|
editable: React.PropTypes.bool
|
2015-06-09 16:09:59 +02:00
|
|
|
},
|
2015-06-22 23:32:41 +02:00
|
|
|
getFormData(){
|
2015-06-09 17:24:06 +02:00
|
|
|
let extradata = {};
|
2015-06-22 23:32:41 +02:00
|
|
|
extradata[this.props.name] = this.refs.form.refs[this.props.name].state.value;
|
2015-06-09 16:09:59 +02:00
|
|
|
return {
|
2015-06-22 23:32:41 +02:00
|
|
|
bitcoin_id: this.props.edition.bitcoin_id,
|
2015-06-09 17:24:06 +02:00
|
|
|
extradata: extradata
|
2015-06-09 16:09:59 +02:00
|
|
|
};
|
|
|
|
},
|
2015-06-22 23:32:41 +02:00
|
|
|
render() {
|
|
|
|
let defaultValue = this.props.edition.extra_data[this.props.name] || '';
|
2015-06-17 17:48:23 +02:00
|
|
|
if (defaultValue.length === 0 && !this.props.editable){
|
2015-06-16 14:01:53 +02:00
|
|
|
return null;
|
|
|
|
}
|
2015-06-22 23:32:41 +02:00
|
|
|
let url = requests.prepareUrl(apiUrls.piece_extradata, {piece_id: this.props.edition.bitcoin_id});
|
2015-06-09 16:09:59 +02:00
|
|
|
return (
|
2015-06-22 23:32:41 +02:00
|
|
|
<Form
|
|
|
|
ref='form'
|
|
|
|
url={url}
|
|
|
|
handleSuccess={this.props.handleSuccess}
|
|
|
|
getFormData={this.getFormData}>
|
|
|
|
<Property
|
|
|
|
name={this.props.name}
|
|
|
|
label={this.props.title}
|
|
|
|
editable={this.props.editable}>
|
|
|
|
<InputTextAreaToggable
|
|
|
|
rows={3}
|
|
|
|
editable={this.props.editable}
|
|
|
|
defaultValue={defaultValue}
|
|
|
|
placeholder={'Fill in ' + this.props.title}
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property hidden={true} name='bitcoin_id'>
|
|
|
|
<input defaultValue={this.props.edition.bitcoin_id}/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
2015-06-09 16:09:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
|
2015-06-16 13:48:48 +02:00
|
|
|
export default PieceExtraDataForm;
|