Vulcan/client/views/comments/comment_form.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-07-05 11:24:28 +09:00
Template[getTemplate('comment_form')].helpers({
reason: function () {
return !!Meteor.user() ? i18n.t('sorry_you_do_not_have_the_rights_to_comments'): i18n.t('please_log_in_to_comment');
2014-06-27 19:42:33 +09:00
}
});
2014-06-27 19:42:33 +09:00
2014-07-05 11:24:28 +09:00
Template[getTemplate('comment_form')].events({
2013-04-26 17:28:09 +09:00
'submit form': function(e, instance){
2014-12-24 10:13:48 +09:00
e.preventDefault();
2012-10-01 18:48:46 +09:00
$(e.target).addClass('disabled');
clearSeenMessages();
2014-12-24 10:13:48 +09:00
2014-12-27 18:34:01 +09:00
2014-12-24 10:13:48 +09:00
var comment = {};
var $commentForm = instance.$('#comment');
2014-12-27 18:34:01 +09:00
var $submitButton = instance.$('.btn-submit');
2014-12-24 10:13:48 +09:00
var body = $commentForm.val();
// now that the form is latency compensated, we don't actually need to show this
// $commentForm.prop('disabled', true);
// $submitButton.addClass('loading');
$commentForm.val('');
var post = postObject;
2014-12-27 18:34:01 +09:00
comment = {
postId: post._id,
body: body
}
// child comment
if (getCurrentTemplate() == 'comment_reply') {
comment.parentCommentId = this.comment._id;
}
2012-10-04 14:54:26 +09:00
Meteor.call('submitComment', comment, function(error, newComment){
// $commentForm.prop('disabled', false);
// $submitButton.removeClass('loading');
if(error){
console.log(error);
flashMessage(error.reason, "error");
}else{
trackEvent("newComment", newComment);
2014-12-24 10:13:48 +09:00
}
});
}
});