2017-03-23 16:27:59 +09:00
|
|
|
import { Components, registerComponent, getFragment, withMessages } from 'meteor/vulcan:core';
|
2016-03-29 10:13:35 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-12-08 23:48:16 +01:00
|
|
|
import { intlShape } from 'react-intl';
|
2017-03-23 16:27:59 +09:00
|
|
|
import Posts from "meteor/vulcan:posts";
|
2016-11-07 22:46:31 +09:00
|
|
|
import { withRouter } from 'react-router'
|
2016-11-04 14:38:31 +09:00
|
|
|
|
2016-11-03 14:07:58 +09:00
|
|
|
class PostsEditForm extends Component {
|
2016-03-29 10:13:35 +09:00
|
|
|
|
2016-05-20 09:33:55 +09:00
|
|
|
renderAdminArea() {
|
|
|
|
return (
|
2017-01-18 12:51:10 +01:00
|
|
|
<Components.ShowIf check={Posts.options.mutations.edit.check} document={this.props.post}>
|
2016-08-06 19:47:04 +02:00
|
|
|
<div className="posts-edit-form-admin">
|
|
|
|
<div className="posts-edit-form-id">ID: {this.props.post._id}</div>
|
2016-12-06 18:06:29 +01:00
|
|
|
<Components.PostsStats post={this.props.post} />
|
2016-08-06 19:47:04 +02:00
|
|
|
</div>
|
2017-01-18 12:51:10 +01:00
|
|
|
</Components.ShowIf>
|
2016-05-20 09:33:55 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-03-29 10:13:35 +09:00
|
|
|
render() {
|
2016-03-31 09:36:25 +09:00
|
|
|
|
2016-03-29 10:13:35 +09:00
|
|
|
return (
|
2016-04-19 15:45:36 +09:00
|
|
|
<div className="posts-edit-form">
|
2016-08-06 19:47:04 +02:00
|
|
|
{this.renderAdminArea()}
|
2017-01-18 12:51:10 +01:00
|
|
|
<Components.SmartForm
|
2016-11-12 14:11:36 +01:00
|
|
|
collection={Posts}
|
2016-11-30 16:54:58 +09:00
|
|
|
documentId={this.props.post._id}
|
2017-01-30 19:46:48 +09:00
|
|
|
mutationFragment={getFragment('PostsPage')}
|
2016-12-08 23:48:16 +01:00
|
|
|
successCallback={post => {
|
2017-01-10 17:49:03 +09:00
|
|
|
this.props.closeModal();
|
2016-11-12 14:11:36 +01:00
|
|
|
this.props.flash(this.context.intl.formatMessage({id: "posts.edit_success"}, {title: post.title}), 'success');
|
2016-03-31 09:36:25 +09:00
|
|
|
}}
|
2016-11-12 17:28:08 +01:00
|
|
|
removeSuccessCallback={({documentId, documentTitle}) => {
|
2016-12-08 23:48:16 +01:00
|
|
|
// post edit form is being included from a single post, redirect to index
|
2016-11-30 10:31:19 +01:00
|
|
|
// note: this.props.params is in the worst case an empty obj (from react-router)
|
|
|
|
if (this.props.params._id) {
|
2016-11-12 17:28:08 +01:00
|
|
|
this.props.router.push('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteDocumentSuccess = this.context.intl.formatMessage({id: 'posts.delete_success'}, {title: documentTitle});
|
|
|
|
this.props.flash(deleteDocumentSuccess, "success");
|
2016-11-30 10:31:19 +01:00
|
|
|
// todo: handle events in collection callbacks
|
|
|
|
// this.context.events.track("post deleted", {_id: documentId});
|
2016-11-12 17:28:08 +01:00
|
|
|
}}
|
2016-11-23 11:07:48 +09:00
|
|
|
showRemove={true}
|
2016-03-29 10:13:35 +09:00
|
|
|
/>
|
|
|
|
</div>
|
2016-11-12 14:11:36 +01:00
|
|
|
);
|
2016-12-08 23:48:16 +01:00
|
|
|
|
2016-03-29 10:13:35 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
PostsEditForm.propTypes = {
|
2017-01-10 17:49:03 +09:00
|
|
|
closeModal: React.PropTypes.func,
|
2016-11-04 14:14:19 +01:00
|
|
|
flash: React.PropTypes.func,
|
|
|
|
post: React.PropTypes.object.isRequired,
|
2016-03-29 10:13:35 +09:00
|
|
|
}
|
|
|
|
|
2016-04-14 10:12:35 +09:00
|
|
|
PostsEditForm.contextTypes = {
|
2016-06-09 17:42:20 +09:00
|
|
|
intl: intlShape
|
|
|
|
}
|
2016-03-29 10:13:35 +09:00
|
|
|
|
2016-12-08 23:48:16 +01:00
|
|
|
registerComponent('PostsEditForm', PostsEditForm, withMessages, withRouter);
|