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

52 lines
1.4 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';
import FormMixin from '../../mixins/form_mixin';
import InputTextAreaToggable from './input_textarea_toggable';
2015-06-09 17:24:06 +02:00
let PieceExtraDataForm = React.createClass({
mixins: [FormMixin],
url() {
return requests.prepareUrl(apiUrls.piece_extradata, {piece_id: this.props.editions[0].bitcoin_id});
},
getFormData() {
2015-06-09 17:24:06 +02:00
let extradata = {};
extradata[this.props.name] = this.refs[this.props.name].state.value;
return {
bitcoin_id: this.getBitcoinIds().join(),
2015-06-09 17:24:06 +02:00
extradata: extradata
};
},
renderForm() {
2015-06-16 14:01:53 +02:00
let defaultValue = this.props.editions[0].extra_data[this.props.name] || '';
if (defaultValue.length === 0 && ~this.props.editable){
return null;
}
return (
2015-06-09 17:24:06 +02:00
<form role="form" key={this.props.name}>
<h5>{this.props.title}</h5>
<InputTextAreaToggable
2015-06-09 17:24:06 +02:00
ref={this.props.name}
className="form-control"
2015-06-16 14:01:53 +02:00
defaultValue={defaultValue}
rows={3}
2015-06-16 14:01:53 +02:00
editable={this.props.editable}
required=""
onSubmit={this.submit}
/>
</form>
);
}
});
export default PieceExtraDataForm;