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: {
|
2015-04-02 17:35:23 +02:00
|
|
|
method: function(doc) {
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2015-03-10 14:24:05 +09:00
|
|
|
this.template.$('button[type=submit]').addClass('loading');
|
2014-12-27 18:34:01 +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()) {
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(i18n.t('you_must_be_logged_in'), 'error');
|
2014-12-22 09:49:28 +09:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2015-03-10 14:24:05 +09:00
|
|
|
onSuccess: function(operation, post) {
|
|
|
|
this.template.$('button[type=submit]').removeClass('loading');
|
2014-12-22 09:49:28 +09:00
|
|
|
trackEvent("new post", {'postId': post._id});
|
2015-01-21 11:09:18 +09:00
|
|
|
Router.go('post_page', {_id: post._id});
|
2014-12-22 09:49:28 +09:00
|
|
|
if (post.status === STATUS_PENDING) {
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(i18n.t('thanks_your_post_is_awaiting_approval'), 'success');
|
2014-12-22 09:49:28 +09:00
|
|
|
}
|
2014-12-03 00:06:00 -08:00
|
|
|
},
|
2014-11-28 11:19:55 +09:00
|
|
|
|
2015-03-10 14:24:05 +09:00
|
|
|
onError: function(operation, error) {
|
|
|
|
this.template.$('button[type=submit]').removeClass('loading');
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
|
|
|
|
Messages.clearSeen();
|
2014-11-28 15:18:55 +09:00
|
|
|
// $(e.target).removeClass('disabled');
|
|
|
|
if (error.error == 603) {
|
|
|
|
var dupePostId = error.reason.split('|')[1];
|
2015-01-18 23:55:39 -08:00
|
|
|
Router.go('post_page', {_id: dupePostId});
|
2014-11-28 15:18:55 +09:00
|
|
|
}
|
2014-07-03 13:15:23 +09:00
|
|
|
}
|
2014-12-22 11:49:35 +09:00
|
|
|
|
2012-10-10 08:32:49 +09:00
|
|
|
}
|
2015-03-27 16:24:21 +08:00
|
|
|
});
|