Vulcan/client/views/comments/comment_form.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

Template.comment_form.rendered = function(){
if(Meteor.user() && !this.editor){
this.editor = new EpicEditor(EpicEditorOptions).load();
}
}
Template.comment_form.events = {
'click input[type=submit]': function(e, instance){
e.preventDefault();
2012-10-01 18:48:46 +09:00
$(e.target).addClass('disabled');
var $comment = $('#comment');
var content = instance.editor.exportFile();
if(window.template=='comment_page'){
2012-10-04 14:54:26 +09:00
// child comment
var parentCommentId=Session.get('selectedCommentId');
var parentComment=Comments.findOne(parentCommentId);
var parentUser=Meteor.users.findOne(parentComment.userId);
2012-10-04 14:54:26 +09:00
var postId=Comments.findOne(parentCommentId).post;
2012-10-04 10:09:20 +09:00
var post=Posts.findOne(postId);
2012-10-04 14:54:26 +09:00
var postUser=Meteor.users.findOne(post.userId);
var properties={
'commentAuthorId': Meteor.user()._id,
'commentAuthorName': getDisplayName(Meteor.user()),
'postId': postId,
'parentCommentId': parentCommentId,
'parentAuthorId': parentComment.userId,
'parentAuthorName': getDisplayName(parentUser)
};
Meteor.call('comment', postId, parentCommentId, content, function(error, result){
Session.set('selectedCommentId', null);
2012-10-04 10:09:20 +09:00
2012-10-04 14:54:26 +09:00
properties['commentId']=result;
trackEvent("newComment", properties);
2012-10-04 15:26:59 +09:00
Meteor.call('addNotification','newReply', properties, parentUser, Meteor.user());
2012-10-04 15:02:12 +09:00
if(parentComment.userId!=post.userId){
2012-10-04 14:54:26 +09:00
// if the original poster is different from the author of the parent comment
// notify them too
2012-10-04 15:26:59 +09:00
Meteor.call('addNotification','newComment', properties, postUser, Meteor.user());
2012-10-04 14:54:26 +09:00
}
2012-10-04 10:09:20 +09:00
Session.set('scrollToCommentId', result);
Router.navigate('posts/'+postId, {trigger:true});
});
}else{
2012-10-04 14:54:26 +09:00
// root comment
var postId=Session.get('selectedPostId');
2012-10-04 13:30:57 +09:00
var post=Posts.findOne(postId);
var postUser=Meteor.users.findOne(post.userId);
2012-10-04 14:54:26 +09:00
var properties={
'commentAuthorId': Meteor.user()._id,
'commentAuthorName': getDisplayName(Meteor.user()),
2012-10-04 17:25:10 +09:00
'postId': postId
2012-10-04 14:54:26 +09:00
};
Meteor.call('comment', postId, parentCommentId, content, function(error, result){
2012-10-04 14:54:26 +09:00
properties['commentId']=result;
trackEvent("newComment", properties);
2012-10-04 15:26:59 +09:00
Meteor.call('addNotification','newComment', properties, postUser, Meteor.user());
Session.set('scrollToCommentId', result);
instance.editor.importFile('editor', '');
});
}
2012-10-04 14:54:26 +09:00
if(window.template=='comment_page'){
// post a child comment
}else{
// post a root comment
}
}
};