Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. AutoForm.hooks({
  2. PostsSearchOrInsert: {
  3. before: {
  4. insert: function(doc, template) {
  5.  
  6. // if searching
  7. if(doc.postType === 'looking') {
  8.  
  9. // we don't need postType for search
  10. var urlQuery = _.omit(doc, 'postType');
  11. var path = FlowRouter.path('/search', {}, urlQuery);
  12.  
  13. FlowRouter.go(path);
  14.  
  15. // cancel insert, so this query won't get inserted to db
  16. return false;
  17. }
  18. else // if inserting
  19. {
  20. // Must the user be logged in to add posts?
  21. if(!Meteor.user()) {
  22. // Add some jquery modal dialog package and issue a
  23. // modal dialog requesting that user signs in
  24. return false;
  25. }
  26.  
  27. doc = _.extend(doc, {
  28. ownerId: Meteor.user()
  29. });
  30.  
  31. // append user id to post here or whatever
  32. // You have to make changes in the schema in order for this to work
  33. // doc = _.extend(doc, {
  34. // userId: Meteor.userId()
  35. // });
  36. }
  37.  
  38. // return doc indicated that everythng is ok and we proceed with
  39. // validation and insertion
  40. return doc;
  41. }
  42. }
  43. }
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement