aboutsummaryrefslogtreecommitdiffstats
path: root/Resources/friendship/ui/FriendSelector.js
blob: 47114db27af92d659e89fc1d053bbc6d416b90f3 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
(function() {
	fs.ui.friendSelectorButton = function() {
		var button = Ti.UI.createButton({
			image: 'images/friends.png'
		});
		
		button.addEventListener('click', function() {
			fs.ui.createFriendSelector().open();
		});
		
		return button;
	};
	
	fs.ui.createFriendSelector = function() {
		var done_button = Ti.UI.createButton({
			title: 'Done',
			style: (fs.app.isAndroid) ? null : Titanium.UI.iPhone.SystemButtonStyle.DONE
		});
		
		var win = Ti.UI.createWindow({
			title: 'Filter Friends',
			barColor: fs.ui.styles.navBarColour,
			modal: true,
			rightNavButton: done_button
		});
		
		done_button.addEventListener('click', function() {
			fs.ui.refreshFilteredLikeList();
			win.close();
		});
		
		var friend_table = Ti.UI.createTableView({
			bottom: 44
		});
		var switch_buttons = [];
		
		var friends = [];
	
		for (var key in fs.data.friends) {
			friends.push(fs.data.friends[key]);
		}
		friends.sort(function(a, b) {
	    	a = a.name;
	    	b = b.name;
	    	return a > b ? 1 : (a < b ? -1 : 0);
		});
		
		for (var i = 0; i < friends.length; i++) {
			var row = Ti.UI.createTableViewRow({
				selectionStyle: 'none'
			});
			var name = Ti.UI.createLabel({
				text: friends[i].name,
				font: {fontSize: 16, fontWeight: 'bold'},
				left: 45
			});
			var avatar = Ti.UI.createImageView({
				image: friends[i].pic,
				height: 35,
				width: 35,
				left: 5
			});
			var switch_button = Ti.UI.createSwitch({
				right: 5,
				value: fs.data.friends[friends[i].uid.toString()].selected,
				SP_uidString: friends[i].uid.toString(),
			});
			switch_button.addEventListener("change", function(e) {
				fs.data.friends[this.SP_uidString].selected = e.value;
			});
			switch_buttons.push(switch_button);
			
			row.add(avatar);
			row.add(name);
			row.add(switch_button);
			
			friend_table.appendRow(row);
		}
		
		win.add(friend_table);
		
		
		var buttonbar = Ti.UI.createButtonBar({
			labels: [{title: 'Enable All'}, {title: 'Disable All'}],
			backgroundColor: fs.ui.styles.navBarColour,
			width: 240
		});
		var flexSpace = Titanium.UI.createButton({
			systemButton: (fs.app.isAndroid) ? null : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
		});
		var toolbar = Ti.UI.createToolbar({
			barColor: fs.ui.styles.navBarColour,
			bottom: 0,
			items: [flexSpace, buttonbar, flexSpace]
		});
		
		buttonbar.addEventListener('click', function(e) {
			if (e.index == 0) {
				for (var i = 0; i < switch_buttons.length; i++) {
					switch_buttons[i].value = true
				}
				for (key in fs.data.friends) {
					fs.data.friends[key].selected = true
				}
			}
			else if (e.index == 1) {
				for (var i = 0; i < switch_buttons.length; i++) {
					switch_buttons[i].value = false
				}
				
				for (key in fs.data.friends) {
					fs.data.friends[key].selected = false
				}
			}
		});
		
		win.add(toolbar);
		
		return win;
	};
})();