2016-02-18 16:26:52 +09:00
|
|
|
// const Formsy = require('formsy-react');
|
|
|
|
// const FRC = require('formsy-react-components');
|
|
|
|
|
2016-02-24 10:09:23 +09:00
|
|
|
import Messages from "meteor/nova:core";
|
2016-02-23 13:10:08 +09:00
|
|
|
|
2016-02-18 16:26:52 +09:00
|
|
|
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({
|
|
|
|
|
2016-02-22 13:23:46 +09:00
|
|
|
propTypes: {
|
2016-02-23 11:34:40 +09:00
|
|
|
document: React.PropTypes.object.isRequired,
|
2016-02-22 13:23:46 +09:00
|
|
|
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) {
|
2016-02-23 13:10:08 +09:00
|
|
|
console.log(error)
|
|
|
|
Messages.flash(error.message, "error")
|
2016-02-21 14:02:24 +09:00
|
|
|
} else {
|
2016-02-23 13:10:08 +09:00
|
|
|
Messages.flash("Post edited.", "success")
|
2016-02-21 14:02:24 +09:00
|
|
|
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() {
|
|
|
|
|
2016-02-22 13:23:46 +09:00
|
|
|
({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}>
|
2016-02-22 13:23:46 +09:00
|
|
|
<div className="post-edit">
|
2016-02-23 11:34:40 +09:00
|
|
|
<h3>Edit Post “{post.title}”</h3>
|
2016-02-22 13:23:46 +09:00
|
|
|
<Formsy.Form onSubmit={this.submitForm}>
|
|
|
|
<Input
|
|
|
|
name="url"
|
2016-02-23 11:34:40 +09:00
|
|
|
value={post.url}
|
2016-02-22 13:23:46 +09:00
|
|
|
label="URL"
|
|
|
|
type="text"
|
|
|
|
className="text-input"
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
name="title"
|
2016-02-23 11:34:40 +09:00
|
|
|
value={post.title}
|
2016-02-22 13:23:46 +09:00
|
|
|
label="Title"
|
|
|
|
type="text"
|
|
|
|
className="text-input"
|
|
|
|
/>
|
|
|
|
<Textarea
|
|
|
|
name="body"
|
2016-02-23 11:34:40 +09:00
|
|
|
value={post.body}
|
2016-02-22 13:23:46 +09:00
|
|
|
label="Body"
|
|
|
|
type="text"
|
|
|
|
className="textarea"
|
|
|
|
/>
|
|
|
|
<CheckboxGroup
|
|
|
|
name="categories"
|
2016-02-23 11:34:40 +09:00
|
|
|
value={post.categories}
|
2016-02-22 13:23:46 +09:00
|
|
|
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;
|