Vulcan/client/templates/post_edit.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2012-09-13 11:05:49 +09:00
(function(){
var editor;
2012-09-06 11:09:24 +09:00
Template.post_edit.events = {
'click input[type=submit]': function(e){
e.preventDefault();
2012-09-06 11:09:24 +09:00
if(!Meteor.user()) throw 'You must be logged in.';
2012-09-06 11:09:24 +09:00
var selected_post_id=Session.get("selected_post_id");
var title= $('#title').val();
var url = $('#url').val();
2012-09-13 11:05:49 +09:00
var body = editor.exportFile();
console.log("body: ", body)
2012-09-06 11:09:24 +09:00
2012-09-06 19:42:11 +09:00
Posts.update(selected_post_id,
2012-09-06 11:09:24 +09:00
{
$set: {
headline: title
, url: url
, body: body
}
}
);
Router.navigate("posts/"+selected_post_id, {trigger:true});
}
2012-09-07 10:57:57 +09:00
, 'click .delete-link': function(e){
e.preventDefault();
if(confirm("Are you sure?")){
var selected_post_id=Session.get("selected_post_id");
Posts.remove(selected_post_id);
Router.navigate("posts/deleted", {trigger:true});
}
}
};
Template.post_edit.post = function(){
var post = Posts.findOne(Session.get('selected_post_id'));
return post;
};
2012-09-13 11:05:49 +09:00
Template.post_edit.rendered = function(){
var post= Posts.findOne(Session.get('selected_post_id'));
if(post){
editor= new EpicEditor(EpicEditorOptions).load();
editor.importFile('editor',post.body);
}
}
})();