Created
August 20, 2015 09:46
-
-
Save jurajkrivda/70fff0070f53f444223d to your computer and use it in GitHub Desktop.
reactive var
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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