I want to add a logout button on the navbar rightNavButton. The following code creates and activates the button, but for only one page.
var loggedIn = Ti.App.Properties.getBool('app:isLoggedIn'); var logOutButton = Ti.UI.createButton({ title : 'Log Out' }); $.homeView.setRightNavButton(logOutButton); logOutButton.addEventListener('click', function(e) { Cloud.Users.logout(function(e) { if (e.success) { alert('Success: Logged out'); Ti.App.Properties.setBool('app:isLoggedIn', false); } else { Ti.API.log('Error:\n' + ((e.error && e.message) || JSON.stringify(e))); } }); });I've looked at setting this code as a global function
Alloy.Globals.logOut
, but not sure how to pass in the calling view controller as a parameter. With this example, $.homeView
is the calling controller.
My questions are: 1) Is there an easier/better way to do this so that I don't have to repeat the same code on each page? 2) Is it safe to make a function like this global?
As always, if you need more detail, please ask. And thank you for your time.