2012-10-02 10:54:04 +09:00
|
|
|
// Template.post_edit.preserve(['#title', '#url', '#editor', '#sticky']);
|
|
|
|
|
|
|
|
// Template.post_edit.preserve({
|
|
|
|
// // 'input[id]': function (node) { return node.id; }
|
|
|
|
// '[name]': function(node) { return node.getAttribute('name');}
|
|
|
|
// });
|
2012-09-29 17:48:49 +09:00
|
|
|
|
|
|
|
Template.post_edit.helpers({
|
|
|
|
post: function(){
|
2012-10-01 10:59:08 +09:00
|
|
|
return Posts.findOne(Session.get('selectedPostId'));
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Template.post_edit.rendered = function(){
|
2012-10-01 10:59:08 +09:00
|
|
|
var post= Posts.findOne(Session.get('selectedPostId'));
|
2012-09-29 17:48:49 +09:00
|
|
|
if(post && !this.editor){
|
|
|
|
this.editor= new EpicEditor(EpicEditorOptions).load();
|
|
|
|
this.editor.importFile('editor',post.body);
|
|
|
|
}
|
2012-10-02 10:54:04 +09:00
|
|
|
// workaround {{#constant}} bug
|
|
|
|
if(post && !this.postRendered){
|
|
|
|
$('#title').val(post.headline);
|
|
|
|
this.postRendered=true;
|
|
|
|
}
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
2012-09-13 11:05:49 +09:00
|
|
|
|
2012-09-06 11:09:24 +09:00
|
|
|
Template.post_edit.events = {
|
2012-09-29 17:48:49 +09:00
|
|
|
'click input[type=submit]': function(e, instance){
|
2012-09-06 10:14:03 +09:00
|
|
|
e.preventDefault();
|
2012-09-06 11:09:24 +09:00
|
|
|
if(!Meteor.user()) throw 'You must be logged in.';
|
2012-09-06 10:14:03 +09:00
|
|
|
|
2012-10-01 10:59:08 +09:00
|
|
|
var selectedPostId=Session.get('selectedPostId');
|
2012-09-06 11:09:24 +09:00
|
|
|
var title= $('#title').val();
|
|
|
|
var url = $('#url').val();
|
2012-09-29 17:48:49 +09:00
|
|
|
var body = instance.editor.exportFile();
|
2012-10-02 10:54:04 +09:00
|
|
|
var sticky=!!$('#sticky').attr('checked');
|
|
|
|
console.log('sticky:', sticky);
|
2012-09-06 11:09:24 +09:00
|
|
|
|
2012-10-01 10:59:08 +09:00
|
|
|
Posts.update(selectedPostId,
|
2012-09-29 17:48:49 +09:00
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
headline: title
|
|
|
|
, url: url
|
|
|
|
, body: body
|
2012-10-02 10:54:04 +09:00
|
|
|
, sticky: sticky
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
|
|
|
}
|
2012-09-06 11:09:24 +09:00
|
|
|
);
|
2012-10-01 10:59:08 +09:00
|
|
|
|
|
|
|
trackEvent("edit post", {'postId': selectedPostId});
|
|
|
|
|
|
|
|
Router.navigate("posts/"+selectedPostId, {trigger:true});
|
2012-09-06 10:14:03 +09:00
|
|
|
}
|
2012-09-07 10:57:57 +09:00
|
|
|
|
|
|
|
, 'click .delete-link': function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
if(confirm("Are you sure?")){
|
2012-10-01 10:59:08 +09:00
|
|
|
var selectedPostId=Session.get('selectedPostId');
|
|
|
|
Posts.remove(selectedPostId);
|
2012-09-07 10:57:57 +09:00
|
|
|
Router.navigate("posts/deleted", {trigger:true});
|
|
|
|
}
|
|
|
|
}
|
2012-09-29 17:48:49 +09:00
|
|
|
};
|