mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00

Also combining can.upvote and can.downvote and deleting unused permissions function and random cleanup.
50 lines
No EOL
1.5 KiB
JavaScript
50 lines
No EOL
1.5 KiB
JavaScript
AutoForm.hooks({
|
|
submitPostForm: {
|
|
|
|
before: {
|
|
submitPost: function(doc, template) {
|
|
|
|
template.$('button[type=submit]').addClass('loading');
|
|
|
|
var post = doc;
|
|
|
|
// ------------------------------ Checks ------------------------------ //
|
|
|
|
if (!Meteor.user()) {
|
|
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
|
|
return false;
|
|
}
|
|
|
|
// ------------------------------ Callbacks ------------------------------ //
|
|
|
|
// run all post submit client callbacks on properties object successively
|
|
post = postSubmitClientCallbacks.reduce(function(result, currentFunction) {
|
|
return currentFunction(result);
|
|
}, post);
|
|
|
|
return post;
|
|
}
|
|
},
|
|
|
|
onSuccess: function(operation, post, template) {
|
|
template.$('button[type=submit]').removeClass('loading');
|
|
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});
|
|
},
|
|
|
|
onError: function(operation, error, template) {
|
|
template.$('button[type=submit]').removeClass('loading');
|
|
flashMessage(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
|
|
clearSeenMessages();
|
|
// $(e.target).removeClass('disabled');
|
|
if (error.error == 603) {
|
|
var dupePostId = error.reason.split('|')[1];
|
|
Router.go('post_page', {_id: dupePostId});
|
|
}
|
|
}
|
|
|
|
}
|
|
}); |