Vulcan/client/views/comments/comment_form.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-07-05 11:24:28 +09:00
Template[getTemplate('comment_form')].helpers({
2014-06-27 19:42:33 +09:00
canComment: function(){
return canComment(Meteor.user());
}
});
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){
var $commentForm = instance.$('#comment');
e.preventDefault();
2012-10-01 18:48:46 +09:00
$(e.target).addClass('disabled');
clearSeenErrors();
var content = $commentForm.val();
if(getCurrentTemplate() == 'comment_reply'){
2013-04-26 17:28:09 +09:00
// child comment
2013-10-09 20:11:58 +09:00
var parentComment = this.comment;
Meteor.call('comment', parentComment.postId, parentComment._id, content, function(error, newComment){
2013-10-09 20:11:58 +09:00
if(error){
console.log(error);
throwError(error.reason);
}else{
trackEvent("newComment", newComment);
Router.go('post_page_comment', {
_id: parentComment.postId,
commentId: newComment._id
});
2013-10-09 20:11:58 +09:00
}
2013-04-26 17:28:09 +09:00
});
}else{
2013-04-26 17:28:09 +09:00
// root comment
var post = postObject;
2012-10-04 14:54:26 +09:00
Meteor.call('comment', post._id, null, content, function(error, newComment){
2013-10-09 20:11:58 +09:00
if(error){
console.log(error);
throwError(error.reason);
}else{
trackEvent("newComment", newComment);
Session.set('scrollToCommentId', newComment._id);
$commentForm.val('');
2013-10-09 20:11:58 +09:00
}
2013-04-26 17:28:09 +09:00
});
}
}
});