2016-05-30 16:55:32 -07:00
|
|
|
import React from 'react';
|
|
|
|
import Widgets from './Widgets';
|
|
|
|
|
|
|
|
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-05-30 16:55:32 -07:00
|
|
|
const widget = Widgets[field.get('widget')] || Widgets._unknown;
|
|
|
|
return React.createElement(widget.Control, {
|
|
|
|
key: field.get('name'),
|
|
|
|
field: field,
|
2016-06-05 01:52:18 -07:00
|
|
|
value: entry.getIn(['data', field.get('name')]),
|
2016-06-08 04:42:24 -03:00
|
|
|
onChange: (value) => onChange(entry.setIn(['data', field.get('name')], value)),
|
|
|
|
onAddMedia: onAddMedia,
|
2016-06-10 14:01:14 -03:00
|
|
|
onRemoveMedia: onRemoveMedia,
|
2016-06-10 00:16:01 -03:00
|
|
|
getMedia: getMedia
|
2016-05-30 16:55:32 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { collection } = this.props;
|
|
|
|
if (!collection) { return null; }
|
|
|
|
|
|
|
|
return <div>
|
2016-06-05 01:52:18 -07:00
|
|
|
{collection.get('fields').map((field) => <div key={field.get('names ')}>{this.controlFor(field)}</div>)}
|
2016-05-30 16:55:32 -07:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|