Vulcan/packages/nova-components/lib/posts/PostEdit.jsx

123 lines
3.1 KiB
React
Raw Normal View History

2016-02-18 16:26:52 +09:00
// const Formsy = require('formsy-react');
// const FRC = require('formsy-react-components');
import Formsy from 'formsy-react';
import FRC from 'formsy-react-components';
// import Modal from 'react-modal';
const Checkbox = FRC.Checkbox;
const CheckboxGroup = FRC.CheckboxGroup;
const Input = FRC.Input;
const RadioGroup = FRC.RadioGroup;
const Select = FRC.Select;
const Textarea = FRC.Textarea;
// const customStyles = {
// content : {
// top : '50%',
// left : '50%',
// right : 'auto',
// bottom : 'auto',
// marginRight : '-50%',
// transform : 'translate(-50%, -50%)'
// }
// };
const PostEdit = React.createClass({
propTypes: {
2016-02-23 11:34:40 +09:00
document: React.PropTypes.object.isRequired,
currentUser: React.PropTypes.object.isRequired,
categories: React.PropTypes.array
},
2016-02-18 16:26:52 +09:00
submitForm(data) {
2016-02-23 11:34:40 +09:00
const post = this.props.document;
2016-02-18 16:26:52 +09:00
const modifier = {$set: _.compactObject(data)};
2016-02-23 11:34:40 +09:00
event.preventDefault();
Meteor.call('posts.edit', post._id, modifier, (error, post) => {
2016-02-21 14:02:24 +09:00
if (error) {
console.log(error);
2016-02-21 14:02:24 +09:00
// handle error
} else {
FlowRouter.go('posts.single', post);
}
});
2016-02-18 16:26:52 +09:00
},
renderAdminForm() {
2016-02-23 11:34:40 +09:00
const post = this.props.document;
2016-02-18 16:26:52 +09:00
return (
<div className="admin-fields">
<RadioGroup
name="status"
2016-02-23 11:34:40 +09:00
value={post.status}
2016-02-18 16:26:52 +09:00
label="Status"
options={Posts.config.postStatuses}
/>
<Checkbox
name="sticky"
2016-02-23 11:34:40 +09:00
value={post.sticky}
2016-02-18 16:26:52 +09:00
label="Sticky"
/>
</div>
)
},
render() {
({CanEditPost} = Telescope.components);
2016-02-23 11:34:40 +09:00
const post = this.props.document;
2016-02-18 16:26:52 +09:00
const categoriesOptions = this.props.categories.map(category => {
return {
value: category._id,
label: category.name
}
});
return (
2016-02-23 11:34:40 +09:00
<CanEditPost user={this.props.currentUser} post={post}>
<div className="post-edit">
2016-02-23 11:34:40 +09:00
<h3>Edit Post {post.title}</h3>
<Formsy.Form onSubmit={this.submitForm}>
<Input
name="url"
2016-02-23 11:34:40 +09:00
value={post.url}
label="URL"
type="text"
className="text-input"
/>
<Input
name="title"
2016-02-23 11:34:40 +09:00
value={post.title}
label="Title"
type="text"
className="text-input"
/>
<Textarea
name="body"
2016-02-23 11:34:40 +09:00
value={post.body}
label="Body"
type="text"
className="textarea"
/>
<CheckboxGroup
name="categories"
2016-02-23 11:34:40 +09:00
value={post.categories}
label="Categories"
type="text"
options={categoriesOptions}
/>
{Users.is.admin(this.props.currentUser) ? this.renderAdminForm() : ""}
<button type="submit" className="button button--primary">Submit</button>
</Formsy.Form>
</div>
</CanEditPost>
2016-02-18 16:26:52 +09:00
)
}
});
2016-02-16 15:08:30 +09:00
module.exports = PostEdit;