2016-06-16 19:20:36 -03:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-09-11 23:08:18 +02:00
|
|
|
import {resolveWidget} from './Widgets';
|
2016-05-30 16:55:32 -07:00
|
|
|
|
|
|
|
export default class ControlPane extends React.Component {
|
|
|
|
controlFor(field) {
|
2016-06-10 14:01:14 -03:00
|
|
|
const { entry, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props;
|
2016-09-11 23:08:18 +02:00
|
|
|
const widget = resolveWidget(field.get('widget'));
|
2016-09-11 17:53:44 +02:00
|
|
|
return <div className="cms-control">
|
|
|
|
<label>{ field.get('label') }</label>
|
2016-09-11 23:08:18 +02:00
|
|
|
{React.createElement(widget.control, {
|
2016-09-11 17:53:44 +02:00
|
|
|
field: field,
|
|
|
|
value: entry.getIn(['data', field.get('name')]),
|
|
|
|
onChange: (value) => onChange(entry.setIn(['data', field.get('name')], value)),
|
|
|
|
onAddMedia: onAddMedia,
|
|
|
|
onRemoveMedia: onRemoveMedia,
|
|
|
|
getMedia: getMedia
|
|
|
|
})}
|
|
|
|
</div>;
|
2016-05-30 16:55:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { collection } = this.props;
|
|
|
|
if (!collection) { return null; }
|
|
|
|
return <div>
|
2016-06-16 19:20:36 -03:00
|
|
|
{collection.get('fields').map((field) => <div key={field.get('name')}>{this.controlFor(field)}</div>)}
|
2016-05-30 16:55:32 -07:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 19:20:36 -03:00
|
|
|
|
|
|
|
ControlPane.propTypes = {
|
|
|
|
collection: ImmutablePropTypes.map.isRequired,
|
|
|
|
entry: ImmutablePropTypes.map.isRequired,
|
|
|
|
getMedia: PropTypes.func.isRequired,
|
|
|
|
onAddMedia: PropTypes.func.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
onRemoveMedia: PropTypes.func.isRequired,
|
|
|
|
};
|