Vulcan/packages/nova-base-components/lib/posts/PostsEditForm.jsx

74 lines
2.2 KiB
React
Raw Normal View History

2016-03-29 10:13:35 +09:00
import React, { PropTypes, Component } from 'react';
2016-06-09 17:42:20 +09:00
import { FormattedMessage, intlShape } from 'react-intl';
import NovaForm from "meteor/nova:forms";
import { DocumentContainer } from "meteor/utilities:react-list-container";
2016-05-22 15:23:30 +09:00
import { Messages } from "meteor/nova:core";
2016-03-29 10:13:35 +09:00
import Actions from "../actions.js";
2016-04-14 10:12:35 +09:00
class PostsEditForm extends Component{
2016-03-29 10:13:35 +09:00
constructor() {
super();
this.deletePost = this.deletePost.bind(this);
}
deletePost() {
const post = this.props.post;
2016-06-09 17:42:20 +09:00
const deletePostConfirm = this.context.intl.formatMessage({id: "posts.delete_confirm"}, {title: post.title});
const deletePostSuccess = this.context.intl.formatMessage({id: "posts.delete_success"}, {title: post.title});
if (window.confirm(deletePostConfirm)) {
Actions.call('posts.deleteById', post._id, (error, result) => {
2016-06-09 17:42:20 +09:00
Messages.flash(deletePostSuccess, "success");
2016-03-29 10:13:35 +09:00
Events.track("post deleted", {'_id': post._id});
});
}
}
2016-05-20 09:33:55 +09:00
renderAdminArea() {
return (
<div className="posts-edit-form-admin">
<div className="posts-edit-form-id">ID: {this.props.post._id}</div>
<Telescope.components.PostsStats post={this.props.post} />
</div>
)
}
2016-03-29 10:13:35 +09:00
render() {
2016-03-29 10:13:35 +09:00
return (
<div className="posts-edit-form">
2016-05-20 09:33:55 +09:00
{Users.is.admin(this.context.currentUser) ? this.renderAdminArea() : null}
<DocumentContainer
collection={Posts}
publication="posts.single"
selector={{_id: this.props.post._id}}
terms={{_id: this.props.post._id}}
joins={Posts.getJoins()}
component={NovaForm}
componentProps={{
// note: the document prop will be passed from DocumentContainer
collection: Posts,
currentUser: this.context.currentUser,
2016-06-09 17:42:20 +09:00
methodName: "posts.edit"
}}
2016-03-29 10:13:35 +09:00
/>
2016-04-07 10:33:44 +09:00
<hr/>
2016-06-09 17:42:20 +09:00
<a onClick={this.deletePost} className="delete-post-link"><Telescope.components.Icon name="close"/> <FormattedMessage id="posts.delete"/></a>
2016-03-29 10:13:35 +09:00
</div>
)
}
}
2016-04-14 10:12:35 +09:00
PostsEditForm.propTypes = {
2016-03-29 10:13:35 +09:00
post: React.PropTypes.object.isRequired
}
2016-04-14 10:12:35 +09:00
PostsEditForm.contextTypes = {
2016-06-09 17:42:20 +09:00
currentUser: React.PropTypes.object,
intl: intlShape
}
2016-03-29 10:13:35 +09:00
2016-04-14 10:12:35 +09:00
module.exports = PostsEditForm;
export default PostsEditForm;