1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/components/ascribe_forms/form_piece_extradata.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import requests from '../../utils/requests';
2015-07-03 19:08:56 +02:00
import { getLangText } from '../../utils/lang_utils.js'
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: {
2015-07-10 14:15:22 +02:00
pieceId: React.PropTypes.number,
extraData: React.PropTypes.object,
2015-06-22 23:32:41 +02:00
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 {
extradata: extradata,
piece_id: this.props.pieceId
};
},
2015-06-22 23:32:41 +02:00
render() {
let defaultValue = this.props.extraData[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;
}
let url = requests.prepareUrl(apiUrls.piece_extradata, {piece_id: this.props.pieceId});
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={1}
2015-06-22 23:32:41 +02:00
editable={this.props.editable}
defaultValue={defaultValue}
2015-07-03 19:08:56 +02:00
placeholder={getLangText('Fill in%s', ' ') + this.props.title}
2015-07-10 14:15:22 +02:00
required="required"/>
2015-06-22 23:32:41 +02:00
</Property>
<hr />
</Form>
);
}
});
2015-06-22 23:32:41 +02:00
export default PieceExtraDataForm;