1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-07 04:04:20 +01:00
onion/js/components/ascribe_forms/form_piece_extradata.js

76 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
2015-06-22 23:32:41 +02:00
import Form from './form';
import Property from './property';
import InputTextAreaToggable from './input_textarea_toggable';
import { getLangText } from '../../utils/lang.js';
import { formatText } from '../../utils/text';
import { resolveUrl } from '../../utils/url_resolver';
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,
title: React.PropTypes.string
},
2015-08-05 18:14:49 +02:00
getFormData() {
const { name, pieceId } = this.props;
return {
extradata: {
[name]: this.refs.form.refs[name].state.value
},
piece_id: pieceId
};
},
getUrl() {
return formatText(resolveUrl('piece_extradata'), {
pieceId: this.props.pieceId
});
},
2015-06-22 23:32:41 +02:00
render() {
const { convertLinks, editable, extraData, handleSuccess, name, 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={this.getUrl()}>
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;