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: {
|
2015-07-10 14:15:22 +02:00
|
|
|
pieceId: React.PropTypes.number,
|
2015-07-09 14:37:33 +02:00
|
|
|
extraData: React.PropTypes.object,
|
2015-06-22 23:32:41 +02:00
|
|
|
handleSuccess: React.PropTypes.func,
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
title: React.PropTypes.string,
|
|
|
|
editable: React.PropTypes.bool
|
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 17:24:06 +02:00
|
|
|
let extradata = {};
|
2015-06-22 23:32:41 +02:00
|
|
|
extradata[this.props.name] = this.refs.form.refs[this.props.name].state.value;
|
2015-06-09 16:09:59 +02:00
|
|
|
return {
|
2015-07-09 14:37:33 +02:00
|
|
|
extradata: extradata,
|
|
|
|
piece_id: this.props.pieceId
|
2015-06-09 16:09:59 +02:00
|
|
|
};
|
|
|
|
},
|
2015-08-05 18:14:49 +02:00
|
|
|
|
2015-06-22 23:32:41 +02:00
|
|
|
render() {
|
2015-07-09 14:37:33 +02:00
|
|
|
let defaultValue = this.props.extraData[this.props.name] || '';
|
2015-06-17 17:48:23 +02:00
|
|
|
if (defaultValue.length === 0 && !this.props.editable){
|
2015-06-16 14:01:53 +02:00
|
|
|
return null;
|
|
|
|
}
|
2015-08-07 15:08:02 +02:00
|
|
|
let url = requests.prepareUrl(ApiUrls.piece_extradata, {piece_id: this.props.pieceId});
|
2015-06-09 16:09:59 +02:00
|
|
|
return (
|
2015-06-22 23:32:41 +02:00
|
|
|
<Form
|
|
|
|
ref='form'
|
|
|
|
url={url}
|
|
|
|
handleSuccess={this.props.handleSuccess}
|
2015-09-21 12:05:42 +02:00
|
|
|
getFormData={this.getFormData}
|
|
|
|
disabled={!this.props.editable}>
|
2015-06-22 23:32:41 +02:00
|
|
|
<Property
|
|
|
|
name={this.props.name}
|
2015-09-21 12:05:42 +02:00
|
|
|
label={this.props.title}>
|
2015-06-22 23:32:41 +02:00
|
|
|
<InputTextAreaToggable
|
2015-07-09 14:37:33 +02:00
|
|
|
rows={1}
|
2015-06-22 23:32:41 +02:00
|
|
|
defaultValue={defaultValue}
|
2015-07-03 19:08:56 +02:00
|
|
|
placeholder={getLangText('Fill in%s', ' ') + this.props.title}
|
2015-07-10 14:15:22 +02:00
|
|
|
required="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;
|