2015-09-17 14:51:14 +09:00
|
|
|
Template.post_submit.onCreated(function () {
|
|
|
|
Telescope.subsManager.subscribe('allUsersAdmin');
|
|
|
|
});
|
|
|
|
|
2015-04-28 11:32:53 +09:00
|
|
|
Template.post_submit.helpers({
|
|
|
|
postFields: function () {
|
2015-04-28 17:15:53 +09:00
|
|
|
return Posts.simpleSchema().getEditableFields(Meteor.user());
|
2015-04-28 11:32:53 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2014-12-22 09:49:28 +09:00
|
|
|
var post = doc;
|
2014-11-28 15:18:55 +09:00
|
|
|
|
2015-05-04 10:19:50 +09:00
|
|
|
this.template.$('button[type=submit]').addClass('loading');
|
|
|
|
|
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
|
2015-04-24 16:34:05 +09:00
|
|
|
post = Telescope.callbacks.run("postSubmitClient", 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) {
|
2015-04-22 11:49:42 +09:00
|
|
|
Events.track("new post", {'postId': post._id});
|
2015-09-08 11:54:14 +09:00
|
|
|
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);
|
2015-09-08 11:54:14 +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');
|
2015-05-02 13:44:41 +09:00
|
|
|
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
|
|
|
}
|
2014-12-22 11:49:35 +09:00
|
|
|
|
2012-10-10 08:32:49 +09:00
|
|
|
}
|
2015-05-14 11:21:44 +09:00
|
|
|
});
|