Vulcan/client/views/comments/comment_form.js
Sacha Greif ff8bf40694 Merge branch 'telescope-master-semantic-messages' of https://github.com/AdmitHub/Telescope into AdmitHub-telescope-master-semantic-messages
Conflicts:
	client/helpers/handlebars.js
	client/views/comments/comment_edit.js
	client/views/comments/comment_form.js
	client/views/comments/comment_item.js
	client/views/posts/modules/post_upvote.js
	client/views/posts/post_edit.js
	client/views/posts/post_submit.js
	client/views/users/user_edit.js
	client/views/users/user_email.js
	lib/router.js
	packages/telescope-tags/lib/client/views/category_item.js
2014-12-06 17:34:08 +09:00

45 lines
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');
clearSeenMessages();
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);
flashMessage(error.reason, "error");
}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);
flashMessage(error.reason, "error");
}else{
trackEvent("newComment", newComment);
Session.set('scrollToCommentId', newComment._id);
$commentForm.val('');
}
});
}
}
});