fixing comment and post edit before hooks

This commit is contained in:
Sacha Greif 2015-05-04 12:32:00 +09:00
parent 44402fb753
commit fcc290c55f
6 changed files with 16 additions and 17 deletions

View file

@ -23,18 +23,18 @@ AutoForm.hooks({
// ------------------------------ Callbacks ------------------------------ //
// run all post edit client callbacks on modifier object successively
comment = Telescope.callbacks.run("commentEditClient", modifier, comment);
return comment;
modifier = Telescope.callbacks.run("commentEditClient", modifier, comment);
return modifier;
}
},
onSuccess: function(operation, comment) {
onSuccess: function(formType, comment) {
comment = this.currentDoc;
Events.track("edit comment", {'commentId': comment._id});
Router.go('post_page', {_id: comment.postId});
},
onError: function(operation, error) {
onError: function(formType, error) {
console.log(error);
Messages.flash(error.reason.split('|')[0], "error"); // workaround because error.details returns undefined
Messages.clearSeen();

View file

@ -59,9 +59,8 @@ Comments.edit = function (commentId, modifier, comment) {
Telescope.callbacks.runAsync("commentEditAsync", modifier, comment);
// ------------------------------ After Update ------------------------------ //
return Comments.findOne(commentId);
}
};
// ------------------------------------------------------------------------------------------- //
// ----------------------------------------- Methods ----------------------------------------- //

View file

@ -43,7 +43,7 @@ getEmbedlyData = function (url) {
// and the thumbnail object if it hasn't already been set
// Async variant that directly modifies the post object with update()
var addMediaAfterSubmit = function (post) {
function addMediaAfterSubmit (post) {
var set = {};
if(post.url){
var data = getEmbedlyData(post.url);

View file

@ -40,7 +40,8 @@ Telescope.callbacks.run = function (hook, item, constant) {
if (typeof callbacks !== "undefined" && !!callbacks.length) { // if the hook exists, and contains callbacks to run
return callbacks.reduce(function(result, callback) {
return callback(result);
// console.log(callback.name);
return callback(result, constant);
}, item);
} else { // else, just return the item unchanged
@ -64,6 +65,7 @@ Telescope.callbacks.runAsync = function (hook, item, constant) {
Meteor.defer(function () {
// run all post submit server callbacks on post object successively
callbacks.forEach(function(callback) {
// console.log(callback.name);
callback(item, constant);
});
});

View file

@ -22,20 +22,19 @@ AutoForm.hooks({
// ------------------------------ Callbacks ------------------------------ //
post = Telescope.callbacks.run("postEditClient", modifier, post);
return post;
modifier = Telescope.callbacks.run("postEditClient", modifier, post);
return modifier;
}
},
onSuccess: function(operation, post) {
onSuccess: function(formType, post) {
post = this.currentDoc;
Events.track("edit post", {'postId': post._id});
Router.go('post_page', {_id: post._id});
},
onError: function(operation, error) {
console.log(error)
onError: function(formType, error) {
console.log(error);
Messages.flash(error.reason.split('|')[0], "error"); // workaround because error.details returns undefined
Messages.clearSeen();
}

View file

@ -89,7 +89,6 @@ Posts.edit = function (postId, modifier, post) {
Telescope.callbacks.runAsync("postEditAsync", modifier, post);
// ------------------------------ After Update ------------------------------ //
return Posts.findOne(postId);
};