-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
202 lines (186 loc) · 4.03 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
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
//<debug>
Ext.Loader.setPath({
'Ext.ux': 'ux'
});
//</debug>
Ext.application({
name: 'SiteSelector',
requires: [
'Ext.MessageBox',
'Ext.device.*'
],
controllers: [
"Settings",
"Body",
"Log",
"BloodSugar",
"Reports"
],
views: [
"LogActionSheet",
"BodyList",
"LogViewer",
"Settings",
"SiteEdit"
],
models: [
"Site",
"Setting",
"BodyRegion",
"Log"
],
stores: [
"Sites",
"Settings",
"Logs",
"BloodSugars"
],
profiles: [
"Phone",
"Tablet"
],
firstLoad: true,
// getBloodSugarInUserUnits: true, // see model.Setting
// getUserBgInMgDl: true, // see model.Setting
bgStep: 1,
settings: function() {
this.settingsStore = Ext.data.StoreManager.get("Settings");
var settings = this.settingsStore.first();
if (this.firstLoad && (!settings || settings.data.version < 2.2)) {
var application = this;
if (!settings) {
var R = this.settingsStore.add({
usecgms: 1,
usepump: 1,
pumpreuse: 28,
cgmreuse: 14,
bolusreuse: 48,
basalreuse: 48,
pumplasts: 2,
cgmlasts: 3,
basallasts: 24,
carb_ratio: 15,
correction_factor: 50,
target_bg: 100,
usereminders: 1,
usezoom: Ext.os.is.phone? 1: 0,
version: 2.2,
bgunits: "mgdl"
});
settings = R[0];
}
var w_w = Ext.Viewport.windowWidth * 0.8, w_h = Ext.Viewport.windowHeight * 0.8;
var msg = "Please tailor these parameters to your body.", title = "Getting Started"
if (Ext.os.is.phone) {
w_w = Ext.Viewport.windowWidth;
w_h = Ext.Viewport.windowHeight;
}
switch (settings.data.version) {
case null:
case 1.0:
case 1.1:
settings.set({
pumplasts: 2,
cgmlasts: 3,
usezoom: Ext.os.is.phone? 1: 0,
carb_ratio: 15,
correction_factor: 50,
target_bg: 100,
usereminders: 1,
version: 2.0
});
Ext.data.StoreManager.get("Sites").backport_logs();
Ext.data.StoreManager.get("Sites").recompute_locations();
case 2.0:
settings.set({
version: 2.1
});
case 2.1:
settings.set({
bolusreuse: 48,
basalreuse: 48,
basallasts: 24,
bgunits: "mgdl",
version: 2.2
});
(function(bgstore) {
bgstore.each(function(r) {
r.set("unit", "mgdl");
});
bgstore.sync();
})(Ext.data.StoreManager.get("BloodSugars"))
this.settingsStore.sync();
msg = "Shot tracking is now available. Configure your healing time for each of basal and bolus. Also, blood sugar units can now be set to mmol/L";
title = "Thanks for upgrading!";
default:
/* this version */
}
// message box call is inside of the initialize() callback below
var settingsView = Ext.Viewport.add({
modal: true,
record: settings,
centered: true,
scrollable: true,
width: w_w,
height: w_h,
showAnimation: {
type: "popIn",
duration: 250,
easing: "ease-out"
},
hideAnimation: {
type: "popOut",
duration: 250,
easing: "ease-out"
},
xtype: "Settings",
listeners: {
initialize: function() {
console.log(settings);
window.setTimeout(function() {
Ext.Msg.alert(
title,
msg,
Ext.emptyFn
);
}, 10000);
},
saved: function() {
settingsView.destroy();
}
}
});
setTimeout(function() {
settingsView.show();
}, 500);
}
if (this.firstLoad) {
settings.updateUserBloodSugarUnits();
this.firstLoad = false;
}
return settings;
},
showHelp: false,
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
var stub = this.settings();
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function() {
window.location.reload();
}
);
},
onRender: function() {
if (this.firstLoad){
Ext.repaint();
this.firstLoad=false;
// alert("here");
window.scrollTo(0,0);
}
}
});