post_submit.js 612 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @file
  3. *
  4. *
  5. * User: marand
  6. * Date: 31/08/15
  7. * Time: 20:47
  8. */
  9. Template.postSubmit.events({
  10. 'submit form': function (e) {
  11. e.preventDefault();
  12. var post = {
  13. url: $(e.target).find('[name=url]').val(),
  14. title: $(e.target).find('[name=title]').val()
  15. };
  16. Meteor.call('postInsert', post, function (error, result) {
  17. // Display the error to the user and abort.
  18. if (error) {
  19. return alert(error);
  20. }
  21. if (result.postExists) {
  22. alert("This link has already been posted");
  23. }
  24. Router.go('postPage', { _id: result._id });
  25. });
  26. }
  27. });