Vulcan/packages/telescope-posts/lib/client/templates/post_submit.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

Template.post_submit.helpers({
postFields: function () {
return Posts.simpleSchema().getEditableFields(Meteor.user());
}
});
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
before: {
method: function(doc) {
2014-11-28 15:18:55 +09:00
var post = doc;
2014-11-28 15:18:55 +09:00
this.template.$('button[type=submit]').addClass('loading');
// ------------------------------ Checks ------------------------------ //
2014-11-28 15:18:55 +09:00
if (!Meteor.user()) {
2015-03-27 16:24:21 +08:00
Messages.flash(i18n.t('you_must_be_logged_in'), 'error');
return false;
}
2014-11-28 15:18:55 +09:00
// ------------------------------ Callbacks ------------------------------ //
2014-11-28 15:18:55 +09:00
// run all post submit client callbacks on properties object successively
2015-04-24 16:34:05 +09:00
post = Telescope.callbacks.run("postSubmitClient", post);
2014-11-28 15:18:55 +09:00
return post;
}
2014-11-28 11:19:55 +09:00
},
onSuccess: function(operation, post) {
this.template.$('button[type=submit]').removeClass('loading');
Events.track("new post", {'postId': post._id});
Router.go('post_page', {_id: post._id});
if (post.status === Posts.config.STATUS_PENDING) {
2015-03-27 16:24:21 +08:00
Messages.flash(i18n.t('thanks_your_post_is_awaiting_approval'), 'success');
}
},
2014-11-28 11:19:55 +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) {
2014-11-28 15:18:55 +09:00
var dupePostId = error.reason.split('|')[1];
Router.go('post_page', {_id: dupePostId});
2014-11-28 15:18:55 +09:00
}
2014-07-03 13:15:23 +09:00
}
2012-10-10 08:32:49 +09:00
}
2015-03-27 16:24:21 +08:00
});