2015-04-28 15:54:19 +09:00
|
|
|
Template.post_edit.helpers({
|
|
|
|
postFields: function () {
|
2015-04-28 17:15:53 +09:00
|
|
|
return Posts.simpleSchema().getEditableFields(Meteor.user());
|
2015-04-28 15:54:19 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-29 10:25:11 +09:00
|
|
|
AutoForm.hooks({
|
|
|
|
editPostForm: {
|
2013-07-19 14:30:39 +03:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
before: {
|
2015-05-04 10:19:50 +09:00
|
|
|
"method-update": function() {
|
|
|
|
|
|
|
|
var post = this.currentDoc;
|
|
|
|
var modifier = this.updateDoc;
|
2013-10-09 12:39:05 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
// ------------------------------ Checks ------------------------------ //
|
2014-07-03 13:15:23 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
if (!Meteor.user()) {
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(i18n.t('you_must_be_logged_in'), "");
|
2014-12-22 09:49:28 +09:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-31 16:11:48 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
// ------------------------------ Callbacks ------------------------------ //
|
2014-07-03 13:15:23 +09:00
|
|
|
|
2015-05-04 12:32:00 +09:00
|
|
|
modifier = Telescope.callbacks.run("postEditClient", modifier, post);
|
|
|
|
return modifier;
|
2014-12-22 09:49:28 +09:00
|
|
|
}
|
2014-11-29 10:25:11 +09:00
|
|
|
},
|
|
|
|
|
2015-05-04 12:32:00 +09:00
|
|
|
onSuccess: function(formType, post) {
|
2015-04-22 11:49:42 +09:00
|
|
|
Events.track("edit post", {'postId': post._id});
|
2015-06-30 19:31:23 +09:00
|
|
|
Router.go('post_page', post);
|
2014-12-03 00:06:00 -08:00
|
|
|
},
|
2014-11-29 10:25:11 +09:00
|
|
|
|
2015-05-04 12:32:00 +09:00
|
|
|
onError: function(formType, error) {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
// delete link
|
2015-04-13 14:52:03 +09:00
|
|
|
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
|
|
|
});
|