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

69 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import requests from '../../utils/requests';
2015-08-05 18:14:49 +02:00
import { getLangText } from '../../utils/lang_utils.js';
2015-06-09 17:24:06 +02:00
2015-08-07 15:08:02 +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: {
name: React.PropTypes.string.isRequired,
pieceId: React.PropTypes.number.isRequired,
2016-01-19 19:36:30 +01:00
convertLinks: React.PropTypes.bool,
editable: React.PropTypes.bool,
extraData: React.PropTypes.object,
2015-06-22 23:32:41 +02:00
handleSuccess: React.PropTypes.func,
name: React.PropTypes.string,
title: React.PropTypes.string
},
2015-08-05 18:14:49 +02:00
getFormData() {
return {
extradata: {
[this.props.name]: this.refs.form.refs[this.props.name].state.value
},
piece_id: this.props.pieceId
};
},
2015-06-22 23:32:41 +02:00
render() {
const { convertLinks, editable, extraData, handleSuccess, name, pieceId, title } = this.props;
const defaultValue = (extraData && extraData[name]) || null;
if (!defaultValue && !editable) {
2015-06-16 14:01:53 +02:00
return null;
}
return (
2015-06-22 23:32:41 +02:00
<Form
ref='form'
2016-01-19 19:36:30 +01:00
disabled={!editable}
getFormData={this.getFormData}
2016-01-19 19:36:30 +01:00
handleSuccess={handleSuccess}
url={requests.prepareUrl(ApiUrls.piece_extradata, { piece_id: pieceId })}>
2015-06-22 23:32:41 +02:00
<Property
name={name}
label={title}>
2015-06-22 23:32:41 +02:00
<InputTextAreaToggable
rows={1}
convertLinks={convertLinks}
2015-06-22 23:32:41 +02:00
defaultValue={defaultValue}
placeholder={getLangText('Fill in%s', ' ') + title}
required />
2015-06-22 23:32:41 +02:00
</Property>
<hr />
</Form>
);
}
});
2015-06-22 23:32:41 +02:00
export default PieceExtraDataForm;