Vulcan/client/views/comments/comment_edit.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-07-05 11:24:28 +09:00
Template[getTemplate('comment_edit')].rendered = function(){
2014-05-01 19:58:56 -07:00
if(this.data){ // XXX
var comment = this.data.comment;
2013-10-09 12:39:05 +09:00
2014-05-01 19:58:56 -07:00
if(comment && Meteor.user() && !this.editor){
this.editor = new EpicEditor(EpicEditorOptions).load();
this.editor.importFile('editor', comment.body);
$(this.editor.editor).bind('keydown', 'meta+return', function(){
$(window.editor).closest('form').find('input[type="submit"]').click();
});
}
2013-10-09 12:39:05 +09:00
}
};
2014-07-05 11:24:28 +09:00
Template[getTemplate('comment_edit')].events({
2013-10-09 12:39:05 +09:00
'click input[type=submit]': function(e, instance){
var comment = this;
var content = cleanUp(instance.editor.exportFile());
e.preventDefault();
if(!Meteor.user())
2013-11-09 02:02:05 +01:00
throw i18n.t('You must be logged in.');
2013-10-09 12:39:05 +09:00
Comments.update(comment._id, {
$set: {
body: content
}
});
trackEvent("edit comment", {'postId': comment.postId, 'commentId': comment._id});
Router.go("/posts/"+comment.postId+"/comment/"+comment._id);
2013-10-09 12:39:05 +09:00
},
'click .delete-link': function(e){
var comment = this;
e.preventDefault();
2013-11-09 02:02:05 +01:00
if(confirm(i18n.t("Are you sure?"))){
2013-10-09 12:39:05 +09:00
Meteor.call('removeComment', comment._id);
Router.go("/posts/"+comment.postId);
throwError("Your comment has been deleted.");
// Router.go("/comments/deleted");
2013-10-09 12:39:05 +09:00
}
}
});