2014-11-28 11:19:55 +09:00
|
|
|
AutoForm.hooks({
|
2014-11-29 10:25:11 +09:00
|
|
|
submitPostForm: {
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
before: {
|
|
|
|
submitPost: function(doc, template) {
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
var post = doc;
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
// ------------------------------ Checks ------------------------------ //
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
if (!Meteor.user()) {
|
|
|
|
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
// ------------------------------ Callbacks ------------------------------ //
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
// run all post submit client callbacks on properties object successively
|
|
|
|
post = postSubmitClientCallbacks.reduce(function(result, currentFunction) {
|
|
|
|
return currentFunction(result);
|
|
|
|
}, post);
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
return post;
|
|
|
|
}
|
2014-11-28 11:19:55 +09:00
|
|
|
},
|
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
onSuccess: function(operation, post, template) {
|
|
|
|
trackEvent("new post", {'postId': post._id});
|
|
|
|
if (post.status === STATUS_PENDING) {
|
|
|
|
flashMessage(i18n.t('thanks_your_post_is_awaiting_approval'), 'success');
|
|
|
|
}
|
|
|
|
Router.go('post_page', {_id: post._id});
|
2014-12-03 00:06:00 -08:00
|
|
|
},
|
2014-11-28 11:19:55 +09:00
|
|
|
|
|
|
|
onError: function(operation, error, template) {
|
2014-12-06 17:49:29 +09:00
|
|
|
flashMessage(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
|
2014-12-06 17:41:15 +09:00
|
|
|
clearSeenMessages();
|
2014-11-28 15:18:55 +09:00
|
|
|
// $(e.target).removeClass('disabled');
|
|
|
|
if (error.error == 603) {
|
|
|
|
var dupePostId = error.reason.split('|')[1];
|
|
|
|
Router.go('/posts/'+dupePostId);
|
|
|
|
}
|
2014-07-03 13:15:23 +09:00
|
|
|
}
|
2014-12-22 11:49:35 +09:00
|
|
|
|
2012-10-10 08:32:49 +09:00
|
|
|
}
|
2014-11-28 15:18:55 +09:00
|
|
|
});
|