Vulcan/client/views/posts/post_edit.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-11-29 10:25:11 +09:00
AutoForm.hooks({
editPostForm: {
before: {
editPost: function(doc, template) {
2012-09-13 11:05:49 +09:00
var post = doc;
2013-10-09 12:39:05 +09:00
// ------------------------------ Checks ------------------------------ //
2014-07-03 13:15:23 +09:00
if (!Meteor.user()) {
flashMessage(i18n.t('you_must_be_logged_in'), "");
return false;
}
// ------------------------------ Callbacks ------------------------------ //
2014-07-03 13:15:23 +09:00
// run all post edit client callbacks on post object successively
post = postEditClientCallbacks.reduce(function(result, currentFunction) {
return currentFunction(result);
}, post);
return post;
}
2014-11-29 10:25:11 +09:00
},
onSuccess: function(operation, post, template) {
trackEvent("edit post", {'postId': post._id});
Router.go('post_page', {_id: post._id});
},
2014-11-29 10:25:11 +09:00
onError: function(operation, error, template) {
console.log(error)
flashMessage(error.reason.split('|')[0], "error"); // workaround because error.details returns undefined
clearSeenMessages();
2013-01-13 09:13:25 +09:00
}
2014-11-29 10:25:11 +09:00
}
2014-12-08 16:10:32 +09:00
});
// delete link
2014-12-08 16:10:32 +09:00
Template[getTemplate('post_edit')].events({
'click .delete-link': function(e){
var post = this.post;
e.preventDefault();
if(confirm("Are you sure?")){
Router.go("/");
Meteor.call("deletePostById", post._id, function(error) {
if (error) {
console.log(error);
flashMessage(error.reason, 'error');
} else {
flashMessage(i18n.t('your_post_has_been_deleted'), 'success');
}
});
}
}
2014-12-03 09:10:14 +09:00
});