var React = require('react');
var CreateForm = require('../components/CreateForm');
var Toolbar = require('../components/Toolbar');
var ListHeader = require('../components/ListHeader');

var { Button } = require('elemental');

var Header = React.createClass({
	
	displayName: 'ListHeader',
	
	getInitialState: function() {
		return {
			createIsOpen: Keystone.showCreateForm
		};
	},
	
	toggleCreateModal: function(visible) {
		this.setState({
			createIsOpen: visible
		});
	},
	
	renderCreateButton: function() {
		var props = { type: 'success' };
		if (Keystone.list.autocreate) {
			props.href = '?new' + Keystone.csrf.query;
		} else {
			props.onClick = this.toggleCreateModal.bind(this, true);
		}
		return (
			<Button {...props}>
				<span className="octicon octicon-plus" />
				Create {Keystone.list.singular}
			</Button>
		);
	},
	
	renderCreateForm: function() {
		return <CreateForm list={Keystone.list} isOpen={this.state.createIsOpen} onCancel={this.toggleCreateModal.bind(this, false)} values={Keystone.createFormData} err={Keystone.createFormErrors} />;
	},
	
	render: function() {
		if (Keystone.list.nocreate) return null;
				
		return <ListHeader />;
	}
	
});

React.render(<Header />, document.getElementById('list-view-header'));

@@ -27,110 +27,8 @@
 ');%0A
-var CreateForm = require('../components/CreateForm');%0Avar Toolbar = require('../components/Toolbar');%0A
 var 
@@ -82,48 +82,8 @@
 );%0A%0A
-var %7B Button %7D = require('elemental');%0A%0A
 var 
@@ -111,18 +111,16 @@
 Class(%7B%0A
-%09%0A
 %09display
@@ -126,20 +126,16 @@
 yName: '
-List
 Header',
@@ -141,795 +141,8 @@
 ,%0A%09%0A
-%09getInitialState: function() %7B%0A%09%09return %7B%0A%09%09%09createIsOpen: Keystone.showCreateForm%0A%09%09%7D;%0A%09%7D,%0A%09%0A%09toggleCreateModal: function(visible) %7B%0A%09%09this.setState(%7B%0A%09%09%09createIsOpen: visible%0A%09%09%7D);%0A%09%7D,%0A%09%0A%09renderCreateButton: function() %7B%0A%09%09var props = %7B type: 'success' %7D;%0A%09%09if (Keystone.list.autocreate) %7B%0A%09%09%09props.href = '?new' + Keystone.csrf.query;%0A%09%09%7D else %7B%0A%09%09%09props.onClick = this.toggleCreateModal.bind(this, true);%0A%09%09%7D%0A%09%09return (%0A%09%09%09%3CButton %7B...props%7D%3E%0A%09%09%09%09%3Cspan className=%22octicon octicon-plus%22 /%3E%0A%09%09%09%09Create %7BKeystone.list.singular%7D%0A%09%09%09%3C/Button%3E%0A%09%09);%0A%09%7D,%0A%09%0A%09renderCreateForm: function() %7B%0A%09%09return %3CCreateForm list=%7BKeystone.list%7D isOpen=%7Bthis.state.createIsOpen%7D onCancel=%7Bthis.toggleCreateModal.bind(this, false)%7D values=%7BKeystone.createFormData%7D err=%7BKeystone.createFormErrors%7D /%3E;%0A%09%7D,%0A%09%0A
 %09ren

remove old junk from list-header