1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 18:13:49 +01:00
onion/js/components/ascribe_forms/form_piece_extradata.js

63 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import requests from '../../utils/requests';
2015-06-09 17:24:06 +02:00
import apiUrls from '../../constants/api_urls';
2015-06-22 23:32:41 +02:00
import Form from './form';
import Property from './property';
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-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;
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-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});
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-22 23:32:41 +02:00
export default PieceExtraDataForm;