Vulcan/client/views/posts/post_submit.js
Sacha Greif 50fc3eb11a Merge branch 'namespace' of https://github.com/TelescopeJS/Telescope into namespace
# Conflicts:
#	lib/users.js
#	packages/telescope-base/lib/base.js
#	packages/telescope-base/package.js
#	packages/telescope-lib
2015-04-20 13:57:37 +09:00

50 lines
1.5 KiB
JavaScript

AutoForm.hooks({
submitPostForm: {
before: {
method: function(doc) {
this.template.$('button[type=submit]').addClass('loading');
var post = doc;
// ------------------------------ Checks ------------------------------ //
if (!Meteor.user()) {
Messages.flash(i18n.t('you_must_be_logged_in'), 'error');
return false;
}
// ------------------------------ Callbacks ------------------------------ //
// run all post submit client callbacks on properties object successively
post = Posts.hooks.submitClientCallbacks.reduce(function(result, currentFunction) {
return currentFunction(result);
}, post);
return post;
}
},
onSuccess: function(operation, post) {
this.template.$('button[type=submit]').removeClass('loading');
trackEvent("new post", {'postId': post._id});
Router.go('post_page', {_id: post._id});
if (post.status === Posts.config.STATUS_PENDING) {
Messages.flash(i18n.t('thanks_your_post_is_awaiting_approval'), 'success');
}
},
onError: function(operation, error) {
this.template.$('button[type=submit]').removeClass('loading');
Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
Messages.clearSeen();
// $(e.target).removeClass('disabled');
if (error.error == 603) {
var dupePostId = error.reason.split('|')[1];
Router.go('post_page', {_id: dupePostId});
}
}
}
});