post_edit.js 834 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @file
  3. *
  4. *
  5. * User: marand
  6. * Date: 02/09/15
  7. * Time: 08:43
  8. */
  9. Template.postEdit.events({
  10. 'submit form': function (e) {
  11. e.preventDefault();
  12. var currentPostId = this._id;
  13. var postProperties = {
  14. url: $(e.target).find('[name=url]').val(),
  15. title: $(e.target).find('[name=title]').val()
  16. };
  17. Posts.update(currentPostId, {
  18. $set: postProperties
  19. },function (error) {
  20. // Display the error to the user and abort.
  21. if (error) {
  22. return alert(error.reason);
  23. }
  24. else {
  25. Router.go('postPage', { _id: currentPostId });
  26. }
  27. });
  28. },
  29. 'click .delete': function (e) {
  30. e.preventDefault();
  31. if (confirm("Delete this post ?")) {
  32. var currentPostId = this._id;
  33. Posts.remove(currentPostId);
  34. Router.go('postsList');
  35. }
  36. }
  37. });