Skip to content

Instantly share code, notes, and snippets.

@jurajkrivda
Created August 20, 2015 09:46
Show Gist options
  • Save jurajkrivda/70fff0070f53f444223d to your computer and use it in GitHub Desktop.
Save jurajkrivda/70fff0070f53f444223d to your computer and use it in GitHub Desktop.
reactive var
Template.maintenance.onCreated(function() {
this.subscribed = new ReactiveVar(false);
this.errorMessage = new ReactiveVar(null);
this.subscribing = new ReactiveVar(false);
});
Template.maintenance.helpers({
'subscribed': function () {
return Template.instance().subscribed.get();
},
'errorMessage': function () {
return Template.instance().errorMessage.get();
},
'subscribing': function () {
return Template.instance().subscribing.get();
}
});
Template.maintenance.events({
'submit .mailchimp-form': function (e, template) {
e.preventDefault();
var $input = $(e.target).find('[type=email]');
if (!$input.val()) {
return;
}
Meteor.call('subscribeMailChimp', $input.val(), function (error, result) {
if (error) {
var message;
switch (error.error) {
case 232: // 'Email_NotExists'
message = 'Email not exists';
break;
case 214: // 'List_AlreadySubscribed'
message = 'Already subscribed!';
break;
default:
message = 'Subscribe error';
}
template.errorMessage.set(message);
} else {
template.subscribed.set(true);
$input.val('');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment