From 7d3d2a2920b04c0064909c985c9b7dfc738a07ee Mon Sep 17 00:00:00 2001 From: quenenni Date: Wed, 27 Mar 2013 02:19:27 +0100 Subject: [PATCH] Changed tabs to spaces & removed trailing spaces --- client.js | 8 --- ep.json | 4 +- handleMessage.js | 63 ++++++++++++---------- static/css/email_notifications.css | 10 ++-- static/js/ep_email.js | 8 +-- templates/email_notifications_settings.ejs | 28 +++++----- update.js | 6 +-- 7 files changed, 64 insertions(+), 63 deletions(-) diff --git a/client.js b/client.js index 4a9a1e5..ef960a8 100644 --- a/client.js +++ b/client.js @@ -5,13 +5,6 @@ exports.eejsBlock_scripts = function (hook_name, args, cb) { return cb(); }; -/* -exports.eejsBlock_embedPopup = function (hook_name, args, cb) { - args.content = args.content + eejs.require("ep_email_notifications/templates/embedFrame.html", {}, module); - return cb(); -}; -*/ - exports.eejsBlock_mySettings = function (hook_name, args, cb) { args.content = args.content + eejs.require('ep_email_notifications/templates/email_notifications_settings.ejs'); return cb(); @@ -20,4 +13,3 @@ exports.eejsBlock_mySettings = function (hook_name, args, cb) { exports.eejsBlock_styles = function (hook_name, args, cb) { args.content = args.content + ''; }; - diff --git a/ep.json b/ep.json index 9202804..f77ce2a 100644 --- a/ep.json +++ b/ep.json @@ -6,8 +6,8 @@ "padUpdate": "ep_email_notifications/update", "handleMessage": "ep_email_notifications/handleMessage", "eejsBlock_scripts": "ep_email_notifications/client", - "eejsBlock_mySettings": "ep_email_notifications/client:eejsBlock_mySettings", - "eejsBlock_styles": "ep_email_notifications/client:eejsBlock_styles" + "eejsBlock_mySettings": "ep_email_notifications/client:eejsBlock_mySettings", + "eejsBlock_styles": "ep_email_notifications/client:eejsBlock_styles" }, "client_hooks": { "postAceInit":"ep_email_notifications/static/js/ep_email:postAceInit", diff --git a/handleMessage.js b/handleMessage.js index 00064b4..6b724f5 100644 --- a/handleMessage.js +++ b/handleMessage.js @@ -33,20 +33,21 @@ exports.handleMessage = function(hook_name, context, callback){ }); // end async for each } - if(context.message.data.userInfo.email_option == 'subscribe' && alreadyExists == true){ - // SUbscription - console.debug("email ", context.message.data.userInfo.email, "already subscribed to ", context.message.data.padId, " so sending message to client"); + if(context.message.data.userInfo.email_option == 'subscribe' && alreadyExists == true){ + // SUbscription + console.debug("email ", context.message.data.userInfo.email, "already subscribed to ", context.message.data.padId, " so sending message to client"); - context.client.json.send({ type: "COLLABROOM", + context.client.json.send({ type: "COLLABROOM", data:{ type: "emailSubscriptionSuccess", payload: false } }); } else if(context.message.data.userInfo.email_option == 'subscribe' && alreadyExists == false){ - // SUbscription + // SUbscription var validatesAsEmail = check(context.message.data.userInfo.email).isEmail(); - if(!validatesAsEmail){ // send validation failed if it's malformed.. y'know in general fuck em! + if(!validatesAsEmail){ + // Subscription -> failed coz mail malformed.. y'know in general fuck em! console.warn("Dropped email subscription due to malformed email address"); context.client.json.send({ type: "COLLABROOM", data:{ @@ -55,12 +56,13 @@ exports.handleMessage = function(hook_name, context, callback){ } }); } else { + // Subscription -> Go for it console.debug ("Subscription: Wrote to the database and sent client a positive response ",context.message.data.userInfo.email); exports.setAuthorEmail( context.message.data.userInfo.userId, context.message.data.userInfo, - callback + callback ); exports.setAuthorEmailRegistered( @@ -75,15 +77,15 @@ exports.handleMessage = function(hook_name, context, callback){ payload: true } }); - } + } } else if(context.message.data.userInfo.email_option == 'unsubscribe' && alreadyExists == true) { - // Unsubscription + // Unsubscription -> Go for it console.debug ("Unsubscription: Remove from the database and sent client a positive response ",context.message.data.userInfo.email); - exports.unsetAuthorEmail( + exports.unsetAuthorEmail( context.message.data.userInfo.userId, context.message.data.userInfo, - callback + callback ); exports.unsetAuthorEmailRegistered( @@ -98,17 +100,17 @@ exports.handleMessage = function(hook_name, context, callback){ payload: true } }); - } else if(context.message.data.userInfo.email_option == 'unsubscribe' && alreadyExists == false) { - // Unsubscription - console.debug ("Unsubscription: Send client a negative response ",context.message.data.userInfo.email); + } else if(context.message.data.userInfo.email_option == 'unsubscribe' && alreadyExists == false) { + // Unsubscription -> Send failed as email not found + console.debug ("Unsubscription: Send client a negative response ",context.message.data.userInfo.email); - context.client.json.send({ type: "COLLABROOM", + context.client.json.send({ type: "COLLABROOM", data:{ type: "emailUnsubscriptionSuccess", payload: false } }); - } + } }); // close db get callback([null]); // don't run onto passing colorId or anything else to the message handler @@ -121,7 +123,7 @@ exports.handleMessage = function(hook_name, context, callback){ console.debug(context.message); var userIdFound = false; - // does email Subscription already exist for this name and padID? + // does email Subscription already exist for this UserId? db.get("emailSubscription:"+context.message.data.padId, function(err, userIds){ if(userIds){ async.forEach(Object.keys(userIds), function(user, cb){ @@ -129,7 +131,7 @@ exports.handleMessage = function(hook_name, context, callback){ console.debug("Options for this pad ", userIds[user].authorId, " found in the Db"); userIdFound = true; - // We send back the options set for this user + // We send back the options associated to this userId context.client.json.send({ type: "COLLABROOM", data:{ type: "emailNotificationGetUserInfo", @@ -152,13 +154,13 @@ exports.handleMessage = function(hook_name, context, callback){ }); if (!userIdFound) { - // We send back the options set for this user + // No options set for this userId context.client.json.send({ type: "COLLABROOM", data:{ type: "emailNotificationGetUserInfo", payload: { success:false - } + } } }); } @@ -197,19 +199,26 @@ exports.setAuthorEmailRegistered = function(datas, authorId, padId){ // Updates the database by removing the email record for that AuthorId exports.unsetAuthorEmail = function (author, datas, callback){ db.get("globalAuthor:" + author, function(err, value){ // get the current value + + // Remove the email option from the datas delete value['email']; + + // Write the modified datas back in the Db db.set("globalAuthor:" + author, value); }); } -// Remove email and padId from the database +// Remove email, options and padId from the database exports.unsetAuthorEmailRegistered = function(datas, authorId, padId){ console.debug("unregistered", datas.email, " to ", padId); - // Here we have to basically hack a new value into the database, this isn't clean or polite. - db.get("emailSubscription:" + padId, function(err, value){ // get the current value - delete value[datas.email]; // remove the registered values to the object - console.warn("written to database"); - db.set("emailSubscription:" + padId, value); // stick it in the database - }); + db.get("emailSubscription:" + padId, function(err, value){ // get the current value + + // remove the registered options from the object + delete value[datas.email]; + + // Write the modified datas back in the Db + console.warn("written to database"); + db.set("emailSubscription:" + padId, value); + }); } diff --git a/static/css/email_notifications.css b/static/css/email_notifications.css index f8e3264..71c61d7 100644 --- a/static/css/email_notifications.css +++ b/static/css/email_notifications.css @@ -1,10 +1,10 @@ .ep_email_settings { - display: none; - padding-left: 1.5em; - padding: .2em; + display: none; + padding-left: 1.5em; + padding: .2em; } .ep_email_input { - padding:.2em; - width:177px; + padding:.2em; + width:177px; } diff --git a/static/js/ep_email.js b/static/js/ep_email.js index 709b3a4..d93dde1 100644 --- a/static/js/ep_email.js +++ b/static/js/ep_email.js @@ -22,14 +22,14 @@ exports.postAceInit = function(hook, context){ // Prepare subscription before submit form $('#ep_email_subscribe').on('click', function() { - $('#ep_email_option').val('subscribe'); - checkAndSend(); + $('#ep_email_option').val('subscribe'); + checkAndSend(); }); // Prepare unsubscription before submit form $('#ep_email_unsubscribe').on('click', function() { - $('#ep_email_option').val('unsubscribe'); - checkAndSend(); + $('#ep_email_option').val('unsubscribe'); + checkAndSend(); }); // subscribe by email can be active.. diff --git a/templates/email_notifications_settings.ejs b/templates/email_notifications_settings.ejs index b935e7a..482d934 100644 --- a/templates/email_notifications_settings.ejs +++ b/templates/email_notifications_settings.ejs @@ -2,19 +2,19 @@
-
- - -
- - -
- - - -
-
- - +
+ + +
+ + +
+ + + +
+
+ +

diff --git a/update.js b/update.js index a6653fa..6b29cf7 100644 --- a/update.js +++ b/update.js @@ -45,8 +45,8 @@ exports.notifyBegin = function(padId){ async.forEach(Object.keys(recipients), function(recipient, cb){ // Is this recipient already on the pad? exports.isUserEditingPad(padId, recipients[recipient].authorId, function(err,userIsOnPad){ // is the user already on the pad? - var onStart = typeof(recipients[recipient].onStart) == "undefined" || recipients[recipient].onStart?true:false; // In case onStart wasn't defined we set it to true - if(!userIsOnPad && onStart){ + var onStart = typeof(recipients[recipient].onStart) == "undefined" || recipients[recipient].onStart?true:false; // In case onStart wasn't defined we set it to true + if(!userIsOnPad && onStart){ console.debug("Emailing "+recipient +" about a new begin update"); server.send({ text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)", @@ -77,7 +77,7 @@ exports.notifyEnd = function(padId){ async.forEach(Object.keys(recipients), function(recipient, cb){ // Is this recipient already on the pad? exports.isUserEditingPad(padId, recipients[recipient].authorId, function(err,userIsOnPad){ // is the user already on the$ - var onEnd = typeof(recipients[recipient].onEnd) == "undefined" || recipients[recipient].onEnd?true:false; // In case onEnd wasn't defined we set it to true + var onEnd = typeof(recipients[recipient].onEnd) == "undefined" || recipients[recipient].onEnd?true:false; // In case onEnd wasn't defined we set it to false if(!userIsOnPad && onEnd){ console.debug("Emailing "+recipient +" about a pad finished being updated");