2015-06-09 16:09:59 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2015-06-16 13:48:48 +02:00
|
|
|
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-09 16:09:59 +02:00
|
|
|
|
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';
|
|
|
|
|
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() {
|
2015-06-09 16:09:59 +02:00
|
|
|
return {
|
2016-01-07 18:29:55 +01:00
|
|
|
extradata: {
|
|
|
|
[this.props.name]: this.refs.form.refs[this.props.name].state.value
|
|
|
|
},
|
2015-07-09 14:37:33 +02:00
|
|
|
piece_id: this.props.pieceId
|
2015-06-09 16:09:59 +02:00
|
|
|
};
|
|
|
|
},
|
2016-01-07 18:29:55 +01:00
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
render() {
|
2016-01-07 18:29:55 +01:00
|
|
|
const { convertLinks, editable, extraData, handleSuccess, name, pieceId, 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}
|
|
|
|
url={requests.prepareUrl(ApiUrls.piece_extradata, { piece_id: pieceId })}>
|
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;
|