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

62 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-09-17 14:51:14 +09:00
Template.post_submit.onCreated(function () {
Telescope.subsManager.subscribe('allUsersAdmin');
});
Template.post_submit.helpers({
postFields: function () {
return Posts.getInsertableFields(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');
this.template.$('input, textarea').not(":disabled").addClass("disabled").prop("disabled", true);
// ------------------------------ Checks ------------------------------ //
2014-11-28 15:18:55 +09:00
if (!Meteor.user()) {
Messages.flash(__('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
post = Telescope.callbacks.run("posts.new.client", post);
2014-11-28 15:18:55 +09:00
return post;
}
2014-11-28 11:19:55 +09:00
},
onSuccess: function(operation, post) {
Events.track("new post", {'postId': post._id});
var template = this.template;
Telescope.subsManager.subscribe('singlePost', post._id, function () {
template.$('button[type=submit]').removeClass('loading');
2015-09-18 16:27:59 +09:00
FlowRouter.go('postPage', post);
});
},
2014-11-28 11:19:55 +09:00
onError: function(operation, error) {
this.template.$('button[type=submit]').removeClass('loading');
this.template.$('.disabled').removeClass("disabled").prop("disabled", false);
2015-09-22 11:41:12 +09:00
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];
2015-09-18 16:27:59 +09:00
FlowRouter.go('postPage', {slug: '_', _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
}
});