Vulcan/packages/telescope-posts/lib/client/templates/post_edit.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

Template.post_edit.helpers({
postFields: function () {
return Posts.simpleSchema().getEditableFields(Meteor.user());
}
});
2014-11-29 10:25:11 +09:00
AutoForm.hooks({
editPostForm: {
before: {
"method-update": function() {
var post = this.currentDoc;
var modifier = this.updateDoc;
2013-10-09 12:39:05 +09:00
// ------------------------------ Checks ------------------------------ //
2014-07-03 13:15:23 +09:00
if (!Meteor.user()) {
2015-03-27 16:24:21 +08:00
Messages.flash(i18n.t('you_must_be_logged_in'), "");
return false;
}
// ------------------------------ Callbacks ------------------------------ //
2014-07-03 13:15:23 +09:00
post = Telescope.callbacks.run("postEditClient", modifier, post);
return post;
}
2014-11-29 10:25:11 +09:00
},
2015-03-11 08:34:44 +09:00
onSuccess: function(operation, post) {
Events.track("edit post", {'postId': post._id});
Router.go('post_page', {_id: post._id});
},
2014-11-29 10:25:11 +09:00
2015-03-11 08:34:44 +09:00
onError: function(operation, error) {
2014-11-29 10:25:11 +09:00
console.log(error)
2015-03-27 16:24:21 +08:00
Messages.flash(error.reason.split('|')[0], "error"); // workaround because error.details returns undefined
Messages.clearSeen();
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
Template.post_edit.events({
2014-12-08 16:10:32 +09:00
'click .delete-link': function(e){
var post = this.post;
e.preventDefault();
2015-03-27 16:24:21 +08:00
2014-12-08 16:10:32 +09:00
if(confirm("Are you sure?")){
Router.go("/");
Meteor.call("deletePostById", post._id, function(error) {
if (error) {
console.log(error);
2015-03-27 16:24:21 +08:00
Messages.flash(error.reason, 'error');
2014-12-08 16:10:32 +09:00
} else {
2015-03-27 16:24:21 +08:00
Messages.flash(i18n.t('your_post_has_been_deleted'), 'success');
2014-12-08 16:10:32 +09:00
}
});
}
}
2015-03-27 16:24:21 +08:00
});