2015-06-09 16:09:59 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
import Form from './form';
|
|
|
|
import Property from './property';
|
2015-06-09 16:09:59 +02:00
|
|
|
import InputTextAreaToggable from './input_textarea_toggable';
|
|
|
|
|
2016-06-13 14:35:02 +02:00
|
|
|
import { getLangText } from '../../utils/lang.js';
|
2016-06-14 16:53:18 +02:00
|
|
|
import { formatText } from '../../utils/text';
|
2016-06-14 13:05:57 +02:00
|
|
|
import { resolveUrl } from '../../utils/url_resolver';
|
2016-06-13 14:35:02 +02:00
|
|
|
|
|
|
|
|
2015-06-09 17:24:06 +02:00
|
|
|
let PieceExtraDataForm = React.createClass({
|
2015-06-22 23:32:41 +02:00
|
|
|
propTypes: {
|
2016-01-14 16:31:19 +01:00
|
|
|
name: React.PropTypes.string.isRequired,
|
|
|
|
pieceId: React.PropTypes.number.isRequired,
|
|
|
|
|
2016-01-19 19:36:30 +01:00
|
|
|
convertLinks: React.PropTypes.bool,
|
2016-01-14 16:31:19 +01:00
|
|
|
editable: React.PropTypes.bool,
|
2015-07-09 14:37:33 +02:00
|
|
|
extraData: React.PropTypes.object,
|
2015-06-22 23:32:41 +02:00
|
|
|
handleSuccess: React.PropTypes.func,
|
2016-01-14 16:31:19 +01:00
|
|
|
title: React.PropTypes.string
|
2015-06-09 16:09:59 +02:00
|
|
|
},
|
2015-08-05 18:14:49 +02:00
|
|
|
|
2015-08-06 10:31:51 +02:00
|
|
|
getFormData() {
|
2016-06-14 16:53:18 +02:00
|
|
|
const { name, pieceId } = this.props;
|
|
|
|
|
2015-06-09 16:09:59 +02:00
|
|
|
return {
|
2016-01-07 18:29:55 +01:00
|
|
|
extradata: {
|
2016-06-14 16:53:18 +02:00
|
|
|
[name]: this.refs.form.refs[name].state.value
|
2016-01-07 18:29:55 +01:00
|
|
|
},
|
2016-06-14 16:53:18 +02:00
|
|
|
piece_id: pieceId
|
2015-06-09 16:09:59 +02:00
|
|
|
};
|
|
|
|
},
|
2016-01-07 18:29:55 +01:00
|
|
|
|
2016-06-14 16:53:18 +02:00
|
|
|
getUrl() {
|
|
|
|
return formatText(resolveUrl('piece_extradata'), {
|
|
|
|
pieceId: this.props.pieceId
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
render() {
|
2016-06-14 16:53:18 +02:00
|
|
|
const { convertLinks, editable, extraData, handleSuccess, name, title } = this.props;
|
2016-01-14 16:31:19 +01:00
|
|
|
const defaultValue = (extraData && extraData[name]) || null;
|
2016-01-07 18:29:55 +01:00
|
|
|
|
2016-01-14 16:31:19 +01:00
|
|
|
if (!defaultValue && !editable) {
|
2015-06-16 14:01:53 +02:00
|
|
|
return null;
|
|
|
|
}
|
2016-01-07 18:29:55 +01:00
|
|
|
|
2015-06-09 16:09:59 +02:00
|
|
|
return (
|
2015-06-22 23:32:41 +02:00
|
|
|
<Form
|
|
|
|
ref='form'
|
2016-01-19 19:36:30 +01:00
|
|
|
disabled={!editable}
|
2015-09-21 12:05:42 +02:00
|
|
|
getFormData={this.getFormData}
|
2016-01-19 19:36:30 +01:00
|
|
|
handleSuccess={handleSuccess}
|
2016-06-14 16:53:18 +02:00
|
|
|
url={this.getUrl()}>
|
2015-06-22 23:32:41 +02:00
|
|
|
<Property
|
2016-01-07 18:29:55 +01:00
|
|
|
name={name}
|
|
|
|
label={title}>
|
2015-06-22 23:32:41 +02:00
|
|
|
<InputTextAreaToggable
|
2015-07-09 14:37:33 +02:00
|
|
|
rows={1}
|
2016-01-07 18:29:55 +01:00
|
|
|
convertLinks={convertLinks}
|
2015-06-22 23:32:41 +02:00
|
|
|
defaultValue={defaultValue}
|
2016-01-07 18:29:55 +01:00
|
|
|
placeholder={getLangText('Fill in%s', ' ') + title}
|
2015-10-28 19:19:14 +01:00
|
|
|
required />
|
2015-06-22 23:32:41 +02:00
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
2015-06-09 16:09:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
|
2015-06-16 13:48:48 +02:00
|
|
|
export default PieceExtraDataForm;
|