Vulcan/client/views/comments/comment_form.js
Sacha Greif 45ccf1d8f1 Merge pull request #588 from anthonymayer/urls_by_route_name
Switching from manually generating urls to using IronRouter functions.
2014-12-04 11:44:44 +09:00

45 lines
No EOL
1.3 KiB
JavaScript

Template[getTemplate('comment_form')].helpers({
canComment: function(){
return canComment(Meteor.user());
}
});
Template[getTemplate('comment_form')].events({
'submit form': function(e, instance){
var $commentForm = instance.$('#comment');
e.preventDefault();
$(e.target).addClass('disabled');
clearSeenErrors();
var content = $commentForm.val();
if(getCurrentTemplate() == 'comment_reply'){
// child comment
var parentComment = this.comment;
Meteor.call('comment', parentComment.postId, parentComment._id, content, function(error, newComment){
if(error){
console.log(error);
throwError(error.reason);
}else{
trackEvent("newComment", newComment);
Router.go('post_page_comment', {
_id: parentComment.postId,
commentId: newComment._id
});
}
});
}else{
// root comment
var post = postObject;
Meteor.call('comment', post._id, null, content, function(error, newComment){
if(error){
console.log(error);
throwError(error.reason);
}else{
trackEvent("newComment", newComment);
Session.set('scrollToCommentId', newComment._id);
$commentForm.val('');
}
});
}
}
});