Facebook login multiple tabs

You must Login before you can answer or comment on any questions.

Hello, If the user is not logged in, i want to display the default fb login button. If they are logged in, I want to display 3 different tabs using tabgroup and the logout button. if the user clicks on logout button, i want to hide the tabgroup and display the login window again. How can I accomplish this? Below works up until i hit logout button on winA.js, then it just displays login button. instead of that i want it to show the main win and hide tabgroups. Thanks a lot!

main.js

Titanium.UI.setBackgroundColor('#000');
var buttonStyle;
var loggedin = false;
 
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
 
var winA = Titanium.UI.createWindow ({
    title: "WinA", 
    backgroundColor: "#fff",
    url: "wina.js", 
    fullscreen : false 
});
 
 
var winB = Titanium.UI.createWindow ({
    title: "WinB",
    backgroundColor: "#fff",
    url: "winb.js", 
    fullscreen : false
});
 
var winATab = Titanium.UI.createTab ({
    title: "WinA", 
    window: winA 
});
 
var winBTab = Titanium.UI.createTab ({
    title: "winB", 
    window: winB 
});
 
// Add the tab to our tab group
tabGroup.addTab(winATab);
tabGroup.addTab(winBTab);
 
buttonStyle = Ti.Facebook.BUTTON_STYLE_WIDE;
Ti.Facebook.appid = 'xxx';
Ti.Facebook.permissions = ['publish_stream'];
Ti.Facebook.addEventListener('login', function(e) {
    loggedin = true;
 
    tabGroup.open();
});
 
if (Titanium.Facebook.loggedIn) {
    tabGroup.open();
} 
 
Ti.Facebook.addEventListener('login', function(e) {
    if (e.success) {
        alert('Thank you for loggin in!');
    tabGroup.open();
    mainWin.hide();
    }
});
 
 
if (!Titanium.Facebook.loggedIn) {
var mainWin = Titanium.UI.createWindow({  
    title:'Login Win',
    backgroundColor:'#fff'
});
// Add the button.  Note that it doesn't need a click event listener.
mainWin.add(Ti.Facebook.createLoginButton({
    top : 10,
    style : buttonStyle,
}));
 
mainWin.open();
}
wina.js
var win = Titanium.UI.currentWindow;
var abt_lbl1 = Titanium.UI.createLabel({
    text:'awin',
            right:5,
            left:5,
            top:0,
            layout:'vertical',
            height:'auto',
            width:'auto',
            textAlign:'left',
        });
win.add(Ti.Facebook.createLoginButton({
    botton : 10
}));
 
 
Ti.Facebook.addEventListener('logout', function(e) {
    if (e.success) {
        alert('Thank you for logout in!');
    mainWin.show();
    tabGroup.close();
   }
});
win.add(abt_lbl1);
winb.js
var win = Titanium.UI.currentWindow;
var abt_lbl1 = Titanium.UI.createLabel({
    text:'Bwin',
            right:5,
            left:5,
            top:0,
            layout:'vertical',
            height:'auto',
            width:'auto',
            textAlign:'left',
        });
 
win.add(abt_lbl1);
In other words, I want to have a universal fb login checker where it'll check if user's logged in, if logged in displays tabs, if logged out displays login window. Thanks.

— asked 2 years ago by Prabin J
0 Comments

1 Answer

if (!Titanium.Facebook.loggedIn) {
// mainWin is local ONLY because you defined it here
var mainWin = Titanium.UI.createWindow({  
    title:'Login Win',
    backgroundColor:'#fff'
});
// Add the button.  Note that it doesn't need a click event listener.
mainWin.add(Ti.Facebook.createLoginButton({
    top : 10,
    style : buttonStyle,
}));
 
mainWin.open();
}
should be like this
var mainWin;
if (!Titanium.Facebook.loggedIn) {
// mainWin is local ONLY because you defined it here
    mainWin = Titanium.UI.createWindow({  
    title:'Login Win',
    backgroundColor:'#fff'
});
// Add the button.  Note that it doesn't need a click event listener.
mainWin.add(Ti.Facebook.createLoginButton({
    top : 10,
    style : buttonStyle,
}));
 
mainWin.open();
}
also how does mainWin get defined in winA.js?

Your Answer

Think you can help? Login to answer this question!