1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * @file
- *
- *
- * User: marand
- * Date: 02/09/15
- * Time: 08:43
- */
- Template.postEdit.events({
- 'submit form': function (e) {
- e.preventDefault();
- var currentPostId = this._id;
- var postProperties = {
- url: $(e.target).find('[name=url]').val(),
- title: $(e.target).find('[name=title]').val()
- };
- var errors = validatePost(postProperties);
- if (errors.title || errors.url) {
- Session.set('postEditErrors', errors);
- return;
- }
- Posts.update(currentPostId, { $set: postProperties }, function (error) {
- // Display the error to the user and abort.
- if (error) {
- return throwError(error.reason);
- }
- else {
- Router.go('postPage', { _id: currentPostId });
- }
- });
- },
- 'click .delete': function (e) {
- e.preventDefault();
- if (confirm("Delete this post ?")) {
- var currentPostId = this._id;
- Posts.remove(currentPostId);
- Router.go('postsList');
- }
- }
- });
- Template.postEdit.onCreated(function () {
- Session.set('postEditErrors', {});
- });
- Template.postEdit.helpers({
- errorMessage: function (field) {
- return Session.get('postEditErrors')[field];
- },
- errorClass: function (field) {
- return Session.get('postEditErrors')[field] ? 'has-error' : '';
- }
- });
|