-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
59 lines (45 loc) · 1.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var linkedin = require('ti.linkedin');
// Setting up linkedin permissions and module itself
linkedin.permissions = [linkedin.PERMISSION_BASIC_PROFILE, linkedin.PERMISSION_EMAIL_ADDRESSES];
linkedin.initialize();
var window = Ti.UI.createWindow({
backgroundColor: "white"
});
window.add(Ti.UI.createView({
layout: "vertical",
height: Ti.UI.SIZE
}));
// Adding login and logout buttons
var login = Ti.UI.createButton({
title: 'Login',
enabled: true
});
var logout = Ti.UI.createButton({
top: 20,
title: 'Logout',
enabled: false
});
window.children[0].add(login);
window.children[0].add(logout);
// Adding listeners
linkedin.addEventListener('login', onLogin);
linkedin.addEventListener('logout', onLogout);
login.addEventListener("click", function() { linkedin.authorize() });
logout.addEventListener("click", function() { linkedin.logout() });
// Opening window
window.open();
// Handlers
function onLogin(event) {
Ti.API.info('User is logged in?', linkedin.loggedIn);
Ti.API.info(JSON.stringify(event));
if (!event.success) {
return;
}
login.enabled = false;
logout.enabled = true;
}
function onLogout(event) {
Ti.API.info('User is logged in?', linkedin.loggedIn);
login.enabled = true;
logout.enabled = false;
}