diff --git a/web/app/assets/javascripts/invitationDialog.js b/web/app/assets/javascripts/invitationDialog.js
index a3c569f59..bd25de876 100644
--- a/web/app/assets/javascripts/invitationDialog.js
+++ b/web/app/assets/javascripts/invitationDialog.js
@@ -1,5 +1,4 @@
(function(context,$) {
-
"use strict";
context.JK = context.JK || {};
context.JK.InvitationDialog = function(app) {
@@ -152,49 +151,99 @@
};
window._oauth_win = window.open("/auth/google_login", "_blank", "height=500,width=500,menubar=no,resizable=no,status=no");
}
+
+ //////////////
+ // FB handlers
- function showFacebookDialog() {
- /*
- $('#invitation-textarea-container').hide();
- $('#invitation-checkbox-container').show();
- $('#btn-send-invitation').hide();
- $('#btn-next-invitation').show();
- invitationDialog.showDialog();
- $('#invitation-checkboxes').html('
Loading your contacts...
');
- */
- window._oauth_callback = function() {
- window._oauth_win.close();
- window._oauth_win = null;
- window._oauth_callback = null;
- /*
- $.ajax({
- type: "GET",
- url: "/gmail_contacts",
- success: function(response) {
- $('#invitation-checkboxes').html('');
- for (var i in response) {
- $('#invitation-checkboxes').append("");
- }
-
- $('.invitation-checkbox').change(function() {
- var checkedBoxes = $('.invitation-checkbox:checkbox:checked');
- var emails = '';
- for (var i = 0; i < checkedBoxes.length; i++) {
- emails += $(checkedBoxes[i]).data('email') + ', ';
- }
- emails = emails.replace(/, $/, '');
- $('#txt-emails').val(emails);
- });
- },
- error: function() {
- $('#invitation-checkboxes').html("Load failed");
- }
- });
- */
- };
- window._oauth_win = window.open("/auth/facebook_login", "_blank", "height=500,width=500,menubar=no,resizable=no,status=no");
+ // Additional initialization code such as adding Event Listeners goes here
+ function handle_fblogin_response(response) {
+ if (response.status === 'connected') {
+ // the user is logged in and has authenticated your
+ // app, and response.authResponse supplies
+ // the user's ID, a valid access token, a signed
+ // request, and the time the access token
+ // and signed request each expire
+ var uid = response.authResponse.userID;
+ var accessToken = response.authResponse.accessToken;
+ window.fb_logged_in_state = "connected";
+ } else if (response.status === 'not_authorized') {
+ // the user is logged in to Facebook,
+ // but has not authenticated your app
+ // TODO: popup authorization dialog
+ window.fb_logged_in_state = "not_authorized";
+ }
+ else {
+ // the user isn't logged in to Facebook.
+ window.fb_logged_in_state = "not_logged_in";
+ }
}
+ this.fb_login = function() {
+ //try {}
+ FB.login(function(response) {
+ handle_fblogin_response(response);
+ }, {scope:'publish_stream'});
+ }
+
+ function show_feed_dialog() {
+ var obj = {
+ method: 'feed',
+ redirect_uri: 'http://jamkazamdev.local:3000/',
+ link: 'https://developers.facebook.com/docs/reference/dialogs/',
+ picture: 'http://fbrell.com/f8.jpg',
+ name: 'Facebook Dialogs',
+ caption: 'Reference Documentation',
+ description: 'Using Dialogs to interact with users.'
+ };
+ function fbFeedDialogCallback(response) {
+ console.log("feedback dialog closed: " + response['post_id'])
+ }
+ FB.ui(obj, fbFeedDialogCallback);
+ }
+
+ function showFacebookDialog(evt) {
+ evt.stopPropagation();
+ var fb_state = window.fb_logged_in_state;
+
+ if (fb_state == "connected") {
+ show_feed_dialog();
+ } else if (fb_state == "not_authorized") {
+ this.fb_login();
+ } else {
+ this.fb_login();
+ }
+ }
+
+ function callFB(fbAppID){
+ var fbAppID_ = fbAppID;
+ window.fbAsyncInit = function() {
+ FB.init({
+ appId : fbAppID_,
+ // channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html',
+ status : true, // check the login status upon init?
+ cookie : true, // set sessions cookies to allow server to access the session?
+ xfbml : true, // parse XFBML tags on this page?
+ oauth : true, // enable OAuth 2.0
+ });
+ // listen to see if the user is known/logged in
+ FB.getLoginStatus(function(response) {
+ handle_fblogin_response(response);
+ });
+ };
+
+ // Load the SDK Asynchronously
+ (function(d){
+ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
+ js = d.createElement('script'); js.id = id; js.async = true;
+ js.src = "//connect.facebook.net/en_US/all.js";
+ d.getElementsByTagName('head')[0].appendChild(js);
+ }(document));
+ }
+
+ // END FB handlers
+ //////////////
+
+
function clearTextFields() {
$('#txt-emails').val('').removeData('google_invite_count');
$('#txt-message').val('');
@@ -211,16 +260,17 @@
registerEvents(false);
}
- function initialize(){
+ function initialize(fbAppID){
var dialogBindings = {
'beforeShow' : beforeShow,
'afterHide': afterHide
};
app.bindDialog('inviteUsers', dialogBindings);
+
+ callFB(fbAppID);
};
-
this.initialize = initialize;
this.showEmailDialog = showEmailDialog;
this.showGoogleDialog = showGoogleDialog;
@@ -228,4 +278,4 @@
}
return this;
-})(window,jQuery);
\ No newline at end of file
+})(window,jQuery);
diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js
index 4e63c8c24..8277145c9 100644
--- a/web/app/assets/javascripts/sidebar.js
+++ b/web/app/assets/javascripts/sidebar.js
@@ -522,6 +522,11 @@
invitationDialog.showGoogleDialog();
return false;
});
+
+ $('#sidebar-div .btn-facebook-invitation').click(function(evt) {
+ invitationDialog.showFacebookDialog(evt);
+ return false;
+ });
}
function registerFriendUpdate() {
diff --git a/web/app/views/clients/_createSession.html.erb b/web/app/views/clients/_createSession.html.erb
index 7a0b3f565..c37a4af3e 100644
--- a/web/app/views/clients/_createSession.html.erb
+++ b/web/app/views/clients/_createSession.html.erb
@@ -98,16 +98,14 @@
E-mail
-
-
-