1
0
mirror of https://github.com/moparisthebest/mail synced 2024-10-31 15:25:01 -04:00
mail/src/js/service/newsletter.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
2014-11-17 12:58:03 -05:00
var ngModule = angular.module('woServices');
ngModule.service('newsletter', Newsletter);
module.exports = Newsletter;
2014-12-11 12:12:37 -05:00
function Newsletter() {}
/**
* 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) {
// 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);
});
};