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-09-16 15:18:27 -04:00
|
|
|
};
|
2012-09-25 09:20:49 +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())
|
2014-11-19 00:00:09 +08:00
|
|
|
throw i18n.t('you_must_be_logged_in');
|
2013-10-09 12:39:05 +09:00
|
|
|
|
|
|
|
Comments.update(comment._id, {
|
|
|
|
$set: {
|
|
|
|
body: content
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-22 10:49:39 +09:00
|
|
|
trackEvent("edit comment", {'postId': comment.postId, 'commentId': comment._id});
|
2014-12-03 00:06:00 -08:00
|
|
|
Router.go('post_page_comment', {_id: comment.postId, commentId: comment._id});
|
2013-10-09 12:39:05 +09:00
|
|
|
},
|
|
|
|
'click .delete-link': function(e){
|
|
|
|
var comment = this;
|
|
|
|
|
|
|
|
e.preventDefault();
|
2014-12-03 00:06:00 -08:00
|
|
|
|
2014-11-19 00:00:09 +08:00
|
|
|
if(confirm(i18n.t("are_you_sure"))){
|
2013-10-09 12:39:05 +09:00
|
|
|
Meteor.call('removeComment', comment._id);
|
2014-12-03 00:06:00 -08:00
|
|
|
Router.go('post_page', {_id: comment.postId});
|
2014-03-20 13:02:07 +05:30
|
|
|
throwError("Your comment has been deleted.");
|
2013-10-09 12:39:05 +09:00
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:13:53 +02:00
|
|
|
});
|