-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.js
More file actions
61 lines (52 loc) · 1.52 KB
/
list.js
File metadata and controls
61 lines (52 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var React = require('react');
var CreateForm = require('../components/CreateForm');
var View = React.createClass({
displayName: 'ListView',
getInitialState: function() {
return {
createIsVisible: Keystone.showCreateForm,
animateCreateForm: false
};
},
toggleCreate: function(visible) {
this.setState({
createIsVisible: visible,
animateCreateForm: true
});
},
renderCreateButton: function() {
if (Keystone.list.autocreate) {
return (
<div className="toolbar">
<a href={'?new' + Keystone.csrf.query} className="btn btn-default btn-create btn-create-item">
<span className="ion-plus-round mr-5" />
Create {Keystone.list.singular}
</a>
</div>
);
}
return (
<div className="toolbar">
<button type="button" className="btn btn-default btn-create btn-create-item" onClick={this.toggleCreate.bind(this, true)}>
<span className="ion-plus-round mr-5" />
Create {Keystone.list.singular}
</button>
</div>
);
},
renderCreateForm: function() {
if (!this.state.createIsVisible) return null;
return <CreateForm list={Keystone.list} animate={this.state.animateCreateForm} onCancel={this.toggleCreate.bind(this, false)} values={Keystone.createFormData} err={Keystone.createFormErrors} />;
},
render: function() {
if (Keystone.list.nocreate) return null;
return (
<div className="create-item">
{this.renderCreateButton()}
{this.renderCreateForm()}
<hr />
</div>
);
}
});
React.render(<View />, document.getElementById('list-view'));