2012-09-25 09:20:49 +09:00
|
|
|
Template.comment_edit.helpers({
|
|
|
|
comment:function(){
|
2012-10-01 10:59:08 +09:00
|
|
|
return Comments.findOne(Session.get('selectedCommentId'));
|
2012-09-25 09:20:49 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Template.comment_edit.rendered = function(){
|
2012-10-01 10:59:08 +09:00
|
|
|
var comment= Comments.findOne(Session.get('selectedCommentId'));
|
2012-10-10 11:03:09 +09:00
|
|
|
|
2012-09-25 09:20:49 +09:00
|
|
|
if(comment && Meteor.user() && !this.editor){
|
|
|
|
this.editor = new EpicEditor(EpicEditorOptions).load();
|
|
|
|
this.editor.importFile('editor',comment.body);
|
2012-10-08 15:11:35 +02:00
|
|
|
$(this.editor.editor).bind('keydown', 'meta+return', function(){
|
|
|
|
$(window.editor).closest('form').find('input[type="submit"]').click();
|
|
|
|
});
|
2012-09-25 09:20:49 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Template.comment_edit.events = {
|
2012-09-29 17:48:49 +09:00
|
|
|
'click input[type=submit]': function(e, instance){
|
|
|
|
e.preventDefault();
|
|
|
|
if(!Meteor.user()) throw 'You must be logged in.';
|
|
|
|
|
2012-10-01 10:59:08 +09:00
|
|
|
var selectedCommentId=Session.get('selectedCommentId');
|
|
|
|
var selectedPostId=Comments.findOne(selectedCommentId).post;
|
2012-09-29 17:48:49 +09:00
|
|
|
var content = instance.editor.exportFile();
|
|
|
|
|
2012-10-01 10:59:08 +09:00
|
|
|
var commentId = Comments.update(selectedCommentId,
|
2012-09-29 17:48:49 +09:00
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
body: content
|
2012-09-25 09:20:49 +09:00
|
|
|
}
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
|
|
|
);
|
2012-10-01 10:59:08 +09:00
|
|
|
|
|
|
|
trackEvent("edit comment", {'postId': selectedPostId, 'commentId': selectedCommentId});
|
|
|
|
|
2012-10-02 13:49:38 +09:00
|
|
|
Router.navigate("posts/"+selectedPostId+"/comment/"+selectedCommentId, {trigger:true});
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
2012-09-25 09:20:49 +09:00
|
|
|
|
2012-09-29 17:48:49 +09:00
|
|
|
, 'click .delete-link': function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
if(confirm("Are you sure?")){
|
2012-10-01 10:59:08 +09:00
|
|
|
var selectedCommentId=Session.get('selectedCommentId');
|
2012-10-03 15:59:03 +09:00
|
|
|
Meteor.call('removeComment', selectedCommentId);
|
2012-09-29 17:48:49 +09:00
|
|
|
Router.navigate("comments/deleted", {trigger:true});
|
2012-09-25 09:20:49 +09:00
|
|
|
}
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
2012-09-25 09:20:49 +09:00
|
|
|
|
2012-09-29 17:48:49 +09:00
|
|
|
};
|
2012-09-25 09:20:49 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|