2016-03-29 10:13:35 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-04-04 10:21:18 +09:00
|
|
|
import NovaForm from "meteor/nova:forms";
|
2016-03-29 10:13:35 +09:00
|
|
|
|
2016-03-31 11:04:24 +09:00
|
|
|
import SmartContainers from "meteor/utilities:react-list-container";
|
|
|
|
const DocumentContainer = SmartContainers.DocumentContainer;
|
|
|
|
|
2016-03-29 10:13:35 +09:00
|
|
|
import Core from "meteor/nova:core";
|
|
|
|
const Messages = Core.Messages;
|
|
|
|
|
|
|
|
import Actions from "../actions.js";
|
|
|
|
|
|
|
|
class PostEditForm extends Component{
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.deletePost = this.deletePost.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
deletePost() {
|
|
|
|
const post = this.props.post;
|
|
|
|
if (window.confirm(`Delete post “${post.title}”?`)) {
|
|
|
|
Actions.call('posts.deleteById', post._id, function(){
|
|
|
|
Messages.flash(`Post “${post.title}” deleted.`, "success");
|
|
|
|
Events.track("post deleted", {'_id': post._id});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-03-31 09:36:25 +09:00
|
|
|
|
|
|
|
({FlashMessages} = Telescope.components);
|
|
|
|
|
2016-03-29 10:13:35 +09:00
|
|
|
return (
|
|
|
|
<div className="edit-post-form">
|
|
|
|
<div className="modal-form-title edit-post-form-header">
|
|
|
|
<h3>Edit Post</h3>
|
|
|
|
<a onClick={this.deletePost} className="delete-post-link"><Icon name="close"/> Delete Post</a>
|
|
|
|
</div>
|
2016-03-31 11:04:24 +09:00
|
|
|
<DocumentContainer
|
|
|
|
collection={Posts}
|
|
|
|
publication="posts.single"
|
|
|
|
selector={{_id: this.props.post._id}}
|
|
|
|
terms={{_id: this.props.post._id}}
|
|
|
|
joins={Posts.getJoins()}
|
2016-04-04 10:21:18 +09:00
|
|
|
component={NovaForm}
|
2016-03-31 11:04:24 +09:00
|
|
|
componentProps={{
|
2016-04-04 10:21:18 +09:00
|
|
|
// note: the document prop will be passed from DocumentContainer
|
2016-03-31 11:04:24 +09:00
|
|
|
collection: Posts,
|
|
|
|
currentUser: this.context.currentUser,
|
|
|
|
methodName: "posts.edit",
|
2016-04-04 10:21:18 +09:00
|
|
|
labelFunction: (fieldName)=>Telescope.utils.getFieldLabel(fieldName, Posts)
|
2016-03-31 09:36:25 +09:00
|
|
|
}}
|
2016-03-29 10:13:35 +09:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PostEditForm.propTypes = {
|
|
|
|
post: React.PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
PostEditForm.contextTypes = {
|
|
|
|
currentUser: React.PropTypes.object
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = PostEditForm;
|
|
|
|
export default PostEditForm;
|