2016-12-08 09:42:50 +01:00
|
|
|
import { Components, registerComponent } from 'meteor/nova:lib';
|
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';
|
2016-11-07 22:46:31 +09:00
|
|
|
import NovaForm from "meteor/nova:forms";
|
2016-06-23 11:40:35 +09:00
|
|
|
import Posts from "meteor/nova:posts";
|
2016-11-07 22:46:31 +09:00
|
|
|
import { withRouter } from 'react-router'
|
2016-12-08 09:42:50 +01:00
|
|
|
import { ShowIf, withMessages } from 'meteor/nova:core';
|
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 (
|
2016-12-01 16:09:54 +09:00
|
|
|
<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>
|
2016-12-01 16:09:54 +09:00
|
|
|
</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()}
|
2016-11-12 14:11:36 +01:00
|
|
|
<NovaForm
|
|
|
|
collection={Posts}
|
2016-11-30 16:54:58 +09:00
|
|
|
documentId={this.props.post._id}
|
2016-12-05 16:30:31 +09:00
|
|
|
extraFragment={`
|
|
|
|
htmlBody
|
|
|
|
postedAt
|
|
|
|
user{
|
|
|
|
_id
|
|
|
|
__displayName
|
|
|
|
__emailHash
|
|
|
|
__slug
|
|
|
|
}
|
|
|
|
`}
|
2016-12-08 23:48:16 +01:00
|
|
|
successCallback={post => {
|
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 = {
|
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-14 17:03:35 +09:00
|
|
|
actions: React.PropTypes.object,
|
|
|
|
events: React.PropTypes.object,
|
2016-11-03 14:07:58 +09:00
|
|
|
closeCallback: React.PropTypes.func,
|
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);
|