2014-11-12 10:12:26 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-17 12:58:03 -05:00
|
|
|
var ngModule = angular.module('woServices');
|
2014-11-12 10:12:26 -05:00
|
|
|
ngModule.service('newsletter', Newsletter);
|
2014-11-19 11:19:55 -05:00
|
|
|
module.exports = Newsletter;
|
2014-11-12 10:12:26 -05:00
|
|
|
|
2014-12-11 12:12:37 -05:00
|
|
|
function Newsletter() {}
|
2014-11-12 10:12:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sign up to the whiteout newsletter
|
|
|
|
*/
|
|
|
|
Newsletter.prototype.signup = function(emailAddress, agree) {
|
2014-12-11 12:12:37 -05:00
|
|
|
return new Promise(function(resolve, reject) {
|
2014-11-12 10:12:26 -05:00
|
|
|
// validate email address
|
|
|
|
if (emailAddress.indexOf('@') < 0) {
|
|
|
|
reject(new Error('Invalid email address!'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!agree) {
|
|
|
|
// don't sign up if the user has not agreed
|
|
|
|
resolve(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var formData = new FormData();
|
|
|
|
formData.append('EMAIL', emailAddress);
|
|
|
|
formData.append('b_52ea5a9e1be9e1d194f184158_6538e8f09f', '');
|
|
|
|
|
|
|
|
var uri = 'https://whiteout.us8.list-manage.com/subscribe/post?u=52ea5a9e1be9e1d194f184158&id=6538e8f09f';
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('post', uri, true);
|
|
|
|
|
|
|
|
xhr.onload = function() {
|
|
|
|
resolve(xhr);
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.onerror = function(err) {
|
|
|
|
reject(err);
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.send(formData);
|
|
|
|
});
|
|
|
|
};
|