Vulcan/client/views/comments/comment_edit.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

var editComment = function(instance) {
var comment = instance.data.comment;
var content = instance.$('#body').val();
2013-10-09 12:39:05 +09:00
if(!Meteor.user())
throw i18n.t('you_must_be_logged_in');
Comments.update(comment._id, {
$set: {
body: content
}
});
trackEvent("edit comment", {'postId': comment.postId, 'commentId': comment._id});
Router.go('post_page_comment', {_id: comment.postId, commentId: comment._id});
};
2013-10-09 12:39:05 +09:00
Template.comment_edit.onRendered(function() {
var self = this;
2015-04-12 21:19:30 +09:00
this.$("#comment").keydown(function (e) {
if(((e.metaKey || e.ctrlKey) && e.keyCode == 13) || (e.ctrlKey && e.keyCode == 13)){
editComment(self);
}
});
});
Template.comment_edit.events({
'click input[type=submit]': function(e, instance){
e.preventDefault();
editComment(instance);
2013-10-09 12:39:05 +09:00
},
'click .delete-link': function(e){
var comment = this;
e.preventDefault();
if(confirm(i18n.t("are_you_sure"))){
2013-10-09 12:39:05 +09:00
Meteor.call('removeComment', comment._id);
Router.go('post_page', {_id: comment.postId});
2015-03-27 16:24:21 +08:00
Messages.flash("Your comment has been deleted.", "success");
2013-10-09 12:39:05 +09:00
}
}
});