diff --git a/static/js/ep_email.js b/static/js/ep_email.js index 35af671..a690027 100644 --- a/static/js/ep_email.js +++ b/static/js/ep_email.js @@ -1,15 +1,50 @@ exports.postAceInit = function(){ + // after 10 seconds if we dont already have an email for this author then prompt them - setTimeout(function(){askClientToEnterEmail()},10000); + setTimeout(function(){init()},10000); +} + +function init(){ + if(clientHasAlreadyRegistered){ // if the client has already registered for emails on this pad. + showAlreadyRegistered(); // client has already registered, let em know.. + }else{ + askClientToEnterEmail(); // ask the client to register + } +} + +function showAlreadyRegistered(){ // the client already registered for emails on this pad so notify the UI + $.gritter.add({ + // (string | mandatory) the heading of the notification + title: "Email subscription", + // (string | mandatory) the text inside the notification + text: "You are already registered for emails for this pad", + // (bool | optional) if you want it to fade out on its own or just sit there + sticky: false + }); + +} + +function clientHasAlreadyRegistered(){ // Has the client already registered for emails on this? + // Given a specific AuthorID do we have an email address in the database? + // Given that email address is it registered to this pad? + // need to pass the server a message to check + var userId = pad.getUserId(); + var message = {}; + message.type = 'USERINFO_AUTHOR_EMAIL_IS_REGISTERED_TO_PAD'; + message.userInfo = {}; + message.userInfo.userId = userId; + pad.collabClient.sendMessage(message); + + } function askClientToEnterEmail(){ $.gritter.add({ // (string | mandatory) the heading of the notification - title: "Recieve Email notifications for this pad", + title: "Email notifications for this pad", // (string | mandatory) the text inside the notification - text: "