1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 21:52:08 +02:00
onion/js/components/ascribe_forms/form_piece_extradata.js

63 lines
1.9 KiB
JavaScript

'use strict';
import React from 'react';
import requests from '../../utils/requests';
import { getLangText } from '../../utils/lang_utils.js';
import ApiUrls from '../../constants/api_urls';
import Form from './form';
import Property from './property';
import InputTextAreaToggable from './input_textarea_toggable';
let PieceExtraDataForm = React.createClass({
propTypes: {
pieceId: React.PropTypes.number,
extraData: React.PropTypes.object,
handleSuccess: React.PropTypes.func,
name: React.PropTypes.string,
title: React.PropTypes.string,
editable: React.PropTypes.bool
},
getFormData() {
let extradata = {};
extradata[this.props.name] = this.refs.form.refs[this.props.name].state.value;
return {
extradata: extradata,
piece_id: this.props.pieceId
};
},
render() {
let defaultValue = this.props.extraData[this.props.name] || '';
if (defaultValue.length === 0 && !this.props.editable){
return null;
}
let url = requests.prepareUrl(ApiUrls.piece_extradata, {piece_id: this.props.pieceId});
return (
<Form
ref='form'
url={url}
handleSuccess={this.props.handleSuccess}
getFormData={this.getFormData}
disabled={!this.props.editable}>
<Property
name={this.props.name}
label={this.props.title}>
<InputTextAreaToggable
rows={1}
defaultValue={defaultValue}
placeholder={getLangText('Fill in%s', ' ') + this.props.title}
required />
</Property>
<hr />
</Form>
);
}
});
export default PieceExtraDataForm;