12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- Template.postSubmit.events({
- 'submit form': function (e) {
- e.preventDefault();
- var post = {
- url: $(e.target).find('[name=url]').val(),
- title: $(e.target).find('[name=title]').val()
- };
- var errors = validatePost(post);
- if (errors.title || errors.url) {
- Session.set('postSubmitErrors', errors);
-
- return null;
- }
- Meteor.call('postInsert', post, function (error, result) {
-
- if (error) {
- return throwError(error.reason);
- }
- if (result.postExists) {
- throwError("This link has already been posted");
- }
- Router.go('postPage', { _id: result._id });
- });
- }
- });
- Template.postSubmit.onCreated(function () {
- Session.set('postSubmitErrors', {});
- });
- Template.postSubmit.helpers({
- errorMessage: function (field) {
- return Session.get('postSubmitErrors')[field];
- },
- errorClass: function (field) {
- return Session.get('postSubmitErrors')[field] ? 'has-error' : '';
- }
- });
|