-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflyout.js
218 lines (195 loc) · 6.78 KB
/
flyout.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//======================================================================
// ExCL is an open source mobile platform for museums that feature basic
// museum information and extends visitor engagement with museum exhibits.
// Copyright (C) 2014 Children's Museum of Houston and the Regents of the
// University of California.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//=====================================================================
var args = arguments[0] || {};
var APICalls = setPathForLibDirectory("customCalls/apiCalls");
var json = Alloy.Globals.museumJSON;
var ageFilterOn = Alloy.Models.app.get("customizeLearningEnabled");
var ageFilterSet = Alloy.Models.app.get("customizeLearningSet");
var viewService = setPathForLibDirectory('customCalls/viewService');
viewService = new viewService();
var buttonService = setPathForLibDirectory('customCalls/buttonService');
buttonService = new buttonService();
var dialogService = setPathForLibDirectory('customCalls/dialogService');
dialogService = new dialogService();
var languageService = setPathForLibDirectory('languageService/languageService');
languageService = new languageService();
var TutorialService = setPathForLibDirectory('tutorialService/tutorialService');
var tutorialService = new TutorialService();
var retriever = Alloy.Globals.setPathForLibDirectory('dataRetriever/dataRetriever');
Alloy.Models.app.on('change:tutorialOn', updateTutorialUI);
Alloy.Models.app.on('change:customizeLearningSet', activateFiltersWithSet);
Alloy.Models.app.on('change:customizeLearningEnabled', activateFiltersWithEnable);
function setPathForLibDirectory(libFile) {
if ( typeof Titanium == 'undefined') {
lib = require("../../lib/" + libFile);
} else {
lib = require(libFile);
}
return lib;
};
function activateFiltersWithSet() {
ageFilterSet = Alloy.Models.app.get('customizeLearningSet');
if (ageFilterSet) {
activateFiltersWithEnable();
} else {
//This spot is for a reset function that will "reset filtering to startup conditions". This does not seem relevant.
}
}
function activateFiltersWithEnable() {
ageFilterOn = Alloy.Models.app.get('customizeLearningEnabled');
if (ageFilterSet && ageFilterOn) {
enableAgeFilter();
} else if (!ageFilterSet && ageFilterOn) {
disableAgeFilter();
}
}
function toggleCustomLearning() {
if (ageFilterOn) {
Alloy.Models.app.set('customizeLearningEnabled', false);
APICalls.info("Customized Learning Disabled");
formatRowEnable();
} else {
Alloy.Models.app.set('customizeLearningEnabled', true);
APICalls.info("Customized Learning Enabled");
formatRowDisable();
}
closeMenu();
}
function closeMenu(e) {
return Alloy.Globals.navController.toggleMenu(false);
}
function openHomePage(e) {
Alloy.Globals.navController.home();
closeMenu();
}
function openExhibitsPage(e) {
Alloy.Globals.navController.open(Alloy.createController("exhibitLanding"));
closeMenu();
}
function openMapPage(e) {
closeMenu();
var controller = Alloy.createController("map", eval([json]));
Alloy.Globals.navController.open(controller);
}
function openInfoPage(e) {
closeMenu();
var controller = Alloy.createController("info", eval([json]));
Alloy.Globals.navController.open(controller);
}
function setCustomLearn(e) {
var ready = Alloy.Collections.filter.ready;
if (ready) {
Alloy.Models.app.set('customizeLearningSet', true);
Alloy.createController('filterActivationModal').getView().open();
enableAgeFilter();
} else {
Alloy.Models.app.retrieveFilters();
alert('Attempting to retrieve filters. Try again in a moment.');
}
}
function enableAgeFilter() {
$.agesLabel.text = "Turn Filter Off";
$.customLearnRow.backgroundColor = Alloy.CFG.excl.colors.flyoutAccentColor;
showEditAgeOption();
}
function disableAgeFilter() {
$.agesLabel.text = "Turn Filter On";
$.customLearnRow.backgroundColor = Alloy.CFG.excl.colors.flyoutColor;
hideEditAgeOption();
}
function showEditAgeOption() {
$.viewRowCollapsible.height = "50dip";
$.toggleView.show();
}
function hideEditAgeOption() {
$.viewRowCollapsible.height = 0;
$.toggleView.hide();
}
function rowFilterEventListener() {
if (ageFilterSet && ageFilterOn) {
Ti.API.info("Filter disabled");
Alloy.Models.app.set("customizeLearningEnabled", false);
disableAgeFilter();
closeMenu();
} else if (ageFilterSet && !ageFilterOn) {
Ti.API.info("Filter enabled");
Alloy.Models.app.set("customizeLearningEnabled", true);
enableAgeFilter();
closeMenu();
} else if (!ageFilterSet && !ageFilterOn) {
Ti.API.info("Custom Learning Set");
Alloy.Models.app.set("customizeLearningEnabled", true);
setCustomLearn();
} else {
Ti.API.info("Unrecognized filter set/enable combination");
}
ageFilterSet = Alloy.Models.app.get('customizeLearningSet');
ageFilterOn = Alloy.Models.app.get('customizeLearningEnabled');
Ti.API.info("Filter Fired (fly): set: " + ageFilterSet + ", on: " + ageFilterOn);
}
function tutorialToggler(e) {
if (!Alloy.Models.app.get("tutorialOn")) {
var dialog = Ti.UI.createAlertDialog({
cancel : 1,
buttonNames : ['Yes', 'Nevermind'],
message : 'Would you like to begin the tutorial again? This will start you at the home screen of the app.',
title : 'Tutorial Mode'
});
dialog.addEventListener('click', function(e) {
if (e.index !== e.source.cancel) {
tutorialService.resetTutorialMode();
}
});
dialog.show();
} else {
tutorialService.endTutorialMode();
}
updateTutorialUI();
}
function updateTutorialUI() {
if (Alloy.Models.app.get("tutorialOn")) {
$.tutorialLabel.text = "Turn Tutorial Off";
} else {
$.tutorialLabel.text = "Turn Tutorial On";
}
}
function languageHandler(e) {
languageService.displayDialog();
}
function detectFilterConditions() {
//Can't Ti.API.info variables here
ageFilterSet = Alloy.Models.app.get('customizeLearningSet');
ageFilterOn = Alloy.Models.app.get('customizeLearningEnabled');
if (ageFilterSet && ageFilterOn) {
enableAgeFilter();
} else if (ageFilterSet && !ageFilterOn) {
disableAgeFilter();
} else if (!ageFilterSet && !ageFilterOn) {
//setCustomLearn();
} else {
Ti.API.info("Unrecognized filter set/enable combination");
}
Ti.API.info("Filter StartUp (fly): set: " + ageFilterSet + ", on: " + ageFilterOn);
}
function initialize() {
detectFilterConditions();
updateTutorialUI();
}
initialize();