post_edit.js 832 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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, { $set: postProperties },function (error, result) {
  18. // Display the error to the user and abort.
  19. if (error) {
  20. return alert(error.reason);
  21. }
  22. else {
  23. Router.go('postPage', { _id: currentPostId });
  24. }
  25. });
  26. },
  27. 'click .delete': function (e) {
  28. e.preventDefault();
  29. if (confirm("Delete this post ?")) {
  30. var currentPostId = this._id;
  31. Posts.remove(currentPostId);
  32. Router.go('postsList');
  33. }
  34. }
  35. });