mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 12:16:37 -04:00
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
Template.comment_edit.helpers({
|
|
comment:function(){
|
|
return Comments.findOne(Session.get('selectedCommentId'));
|
|
}
|
|
});
|
|
|
|
Template.comment_edit.rendered = function(){
|
|
var comment= Comments.findOne(Session.get('selectedCommentId'));
|
|
if(comment && Meteor.user() && !this.editor){
|
|
this.editor = new EpicEditor(EpicEditorOptions).load();
|
|
this.editor.importFile('editor',comment.body);
|
|
}
|
|
}
|
|
|
|
Template.comment_edit.events = {
|
|
'click input[type=submit]': function(e, instance){
|
|
e.preventDefault();
|
|
if(!Meteor.user()) throw 'You must be logged in.';
|
|
|
|
var selectedCommentId=Session.get('selectedCommentId');
|
|
var selectedPostId=Comments.findOne(selectedCommentId).post;
|
|
var content = instance.editor.exportFile();
|
|
|
|
var commentId = Comments.update(selectedCommentId,
|
|
{
|
|
$set: {
|
|
body: content
|
|
}
|
|
}
|
|
);
|
|
|
|
trackEvent("edit comment", {'postId': selectedPostId, 'commentId': selectedCommentId});
|
|
|
|
Router.navigate("posts/"+selectedPostId, {trigger:true});
|
|
}
|
|
|
|
, 'click .delete-link': function(e){
|
|
e.preventDefault();
|
|
if(confirm("Are you sure?")){
|
|
var selectedCommentId=Session.get('selectedCommentId');
|
|
Comments.remove(selectedCommentId);
|
|
Router.navigate("comments/deleted", {trigger:true});
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|