2015-04-28 11:32:53 +09:00
|
|
|
Template.comment_submit.helpers({
|
|
|
|
commentFields: function () {
|
2015-04-28 17:15:53 +09:00
|
|
|
return Comments.simpleSchema().getEditableFields(Meteor.user());
|
2015-04-28 11:32:53 +09:00
|
|
|
},
|
|
|
|
reason: function () {
|
|
|
|
return !!Meteor.user() ? i18n.t('sorry_you_do_not_have_the_rights_to_comments'): i18n.t('please_log_in_to_comment');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
AutoForm.hooks({
|
|
|
|
submitCommentForm: {
|
2014-06-27 19:42:33 +09:00
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
before: {
|
|
|
|
method: function(doc) {
|
2014-12-24 10:13:48 +09:00
|
|
|
|
2015-05-04 10:19:50 +09:00
|
|
|
var comment = doc;
|
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
this.template.$('button[type=submit]').addClass('loading');
|
2014-12-24 10:13:48 +09:00
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
var parent = Template.parentData(5); // TODO: find a less brittle way to do this
|
2014-12-24 10:13:48 +09:00
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
if (!!parent.comment) { // child comment
|
|
|
|
var parentComment = parent.comment;
|
|
|
|
comment.parentCommentId = parentComment._id;
|
|
|
|
comment.postId = parentComment.postId;
|
|
|
|
} else { // root comment
|
|
|
|
var post = parent;
|
|
|
|
comment.postId = post._id;
|
|
|
|
}
|
2014-12-28 11:45:35 +09:00
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
// ------------------------------ Checks ------------------------------ //
|
2014-12-27 18:34:01 +09:00
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
if (!Meteor.user()) {
|
|
|
|
Messages.flash(i18n.t('you_must_be_logged_in'), 'error');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------ Callbacks ------------------------------ //
|
|
|
|
|
|
|
|
// run all comment submit client callbacks on properties object successively
|
|
|
|
comment = Telescope.callbacks.run("commentSubmitClient", comment);
|
|
|
|
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
},
|
2015-01-07 08:22:46 +01:00
|
|
|
|
2015-04-28 09:44:43 +09:00
|
|
|
onSuccess: function(operation, comment) {
|
|
|
|
this.template.$('button[type=submit]').removeClass('loading');
|
|
|
|
Events.track("new comment", {'commentId': comment._id});
|
|
|
|
Router.go('post_page', {_id: comment.postId});
|
|
|
|
if (comment.status === Posts.config.STATUS_PENDING) {
|
|
|
|
Messages.flash(i18n.t('thanks_your_post_is_awaiting_approval'), 'success');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onError: function(operation, error) {
|
|
|
|
this.template.$('button[type=submit]').removeClass('loading');
|
|
|
|
Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
|
|
|
|
Messages.clearSeen();
|
2014-12-28 12:13:13 +09:00
|
|
|
}
|
2015-04-28 09:44:43 +09:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2015-04-11 14:35:51 +09:00
|
|
|
|
2015-04-28 11:32:53 +09:00
|
|
|
Template.comment_submit.onRendered(function() {
|
2015-04-11 14:35:51 +09:00
|
|
|
var self = this;
|
2015-04-12 21:19:30 +09:00
|
|
|
this.$("#comment").keydown(function (e) {
|
|
|
|
if(((e.metaKey || e.ctrlKey) && e.keyCode == 13) || (e.ctrlKey && e.keyCode == 13)){
|
2015-04-28 09:44:43 +09:00
|
|
|
// submitComment(self);
|
|
|
|
// TODO: find a way to trigger autoform submission here
|
2015-04-12 21:19:30 +09:00
|
|
|
}
|
2015-04-11 14:35:51 +09:00
|
|
|
});
|
2015-04-28 09:44:43 +09:00
|
|
|
});
|