-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityDetail.lua
More file actions
468 lines (348 loc) · 10.5 KB
/
ActivityDetail.lua
File metadata and controls
468 lines (348 loc) · 10.5 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
--
-- Project: CareControlMobile2
-- Description:
--
-- Version: 1.0
-- Managed with http://CoronaProjectManager.com
--
-- Copyright 2014 . All Rights Reserved.
--
--
-- Project: CareControlPortal
-- Description:
--
-- Version: 1.0
-- Managed with http://CoronaProjectManager.com
--
-- Copyright 2014 . All Rights Reserved.
--
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local func = require("functions")
local http = require("httpwork")
local lfs = require("lfs")
--local CCDB = require("Offline")
local group
local RunDate, RunDateValue
local ShowCalendar
local ActivityID
local InPast
local LoadDataSet
local SaveButton
local fadeScreen
local calName
local KidData = {}
local KidList
local InfoScreen
local LockFlag
local LockSet
local LockFlagYN
local RefreshDataSet = function()
http.MakeNetworkCall(LoadDataSet, "GetKidsActivity",RunDateValue,ActivityID )
end
local SaveDataSet = function(Response)
if fadeScreen ~= nil then
fadeScreen:removeSelf()
fadeScreen = nil
end
if (Response.isError) then
native.showAlert("Network Connection Error","There seems to be a problem connecting to Care Control. Please try again.",{"OK"})
else
if Response.response == "COMPLETED" then
func.ShowSimpleAlert("Save Completed","Everything Saved!")
RefreshDataSet()
else
func.ShowSimpleAlert("Something is Wrong","That save did not work. Have you got a signal?")
end
end
end
local SaveDataSet = function()
local SaveString = ""
fadeScreen = func.FadeScreen()
group:insert(fadeScreen)
for i = 1,#KidData do
if tonumber(KidData[i][7]) == 1 then
SaveString = SaveString .. KidData[i][1] .. ";"
end
end
http.MakeNetworkCall(SaveDataSet, "SaveKidsActivity",RunDateValue,ActivityID,SaveString, _G.CoachID, LockFlag )
end
local SaveCheck = function(event)
local PostData
if "clicked" == event.action then
local i = event.index
if 1 == i then
SaveDataSet()
end
end
return true
end
local ActionButton = function(event)
if event.phase == "ended" then
if event.target.id == "BackBtn" then
func.GoBack()
end
if event.target.id == "CloseBtn" then
if InfoScreen ~= nil then
InfoScreen:removeSelf()
InfoScreen = nil
end
if fadeScreen ~= nil then
fadeScreen:removeSelf()
fadeScreen = nil
end
end
if event.target.id == "SaveBtn" then
if LockFlag == 1 then
func.NativeReplaceQuestion( "Finalise Records", "If you finalise the records they cannot be changed?", { "Yes", "No" }, SaveCheck )
else
SaveDataSet()
end
end
end
return true
end
local lpad = function(str, len, char)
if char == nil then char = ' ' end
return string.rep(char, len - string.len(str)) .. str
end
local CalendarSelected = function(event)
local button = event.buttonPressed
local cal
cal = event.name
local newDate
if fadeScreen ~= nil then
fadeScreen:removeSelf()
fadeScreen = nil
end
if button == "DAY" then
newDate = lpad(event.day,2,'0') .. "/" .. lpad(event.month,2,'0') .. "/" ..event.year
if string.find(cal, "RunDate") then
if RunDate ~= nil then
RunDate:removeSelf()
RunDate = nil
end
RunDateValue = newDate
RunDate = func.SuperLabel({Border=1,id="RunDate",listener=ShowCalendar,Caption=newDate,FontSize=30,Left=250,Width=170,Height=25,Top=110,Red=0/255,Green=0/255,Blue=0/255})
group:insert(RunDate)
end
event.Widget:show(false, true)
_G.GUI.GetHandle(cal):destroy()
RefreshDataSet()
end
end
local ClearCal = function(event)
if event.phase == "ended" then
if _G.GUI.GetHandle(calName) ~= nil then
_G.GUI.GetHandle(calName):destroy()
end
if fadeScreen ~= nil then
fadeScreen:removeSelf()
fadeScreen = nil
end
end
return true
end
ShowCalendar = function(event)
if event.phase == "ended" then
fadeScreen = func.FadeScreen(nil,ClearCal)
group:insert(fadeScreen)
--_G.GUI.GetHandle(cal):destroy()
calName = "MY_CALENDAR_" .. event.target.id
_G.GUI.NewCalendar(
{
x = display.contentWidth/2 -290,
y = "center",
scale = 2,
name = calName,
parentGroup = nil,
theme = _G.theme,
border = {"shadow", 8,8, .25},
onRelease = CalendarSelected,
}
)
_G.GUI.GetHandle(calName):setDate()
end
return true
end
local TickKid = function(event)
if event.phase == "ended" then
local id
id = tonumber(event.target.id)
if tonumber(KidData[id][7]) == 1 then
KidData[id][7] = 0
else
KidData[id][7] = 1
end
KidList:reloadData()
end
return true
end
local RingNumber2 = function(event)
local ev = event.target
if event.phase == "ended" then
local id = tonumber(ev.id)
local tel = KidData[id][5]
system.openURL( "tel:" .. tel )
end
return true
end
local RingNumber1 = function(event)
local ev = event.target
if event.phase == "ended" then
local id = tonumber(ev.id)
local tel = KidData[id][4]
system.openURL( "tel:" .. tel )
end
return true
end
local LoadInfo = function(event)
if event.phase == "ended" then
local id = event.target.id
fadeScreen = func.FadeScreen()
group:insert(fadeScreen)
InfoScreen = display.newGroup()
InfoScreen:insert(func.StandardImage("editText2.png",320,300))
group:insert(InfoScreen)
InfoScreen:insert(func.SuperLabel({Caption="Child Details",Underline=1,FontSize=36,Bold=1,Left=30,Height=20,Top=150,Red=99/255,Green=37/255,Blue=35/255}))
InfoScreen:insert(func.SuperLabel({Caption="Emgergency Contact:",Underline=0,FontSize=30,Bold=0,Left=30,Height=20,Top=250,Red=99/255,Green=37/255,Blue=35/255}))
InfoScreen:insert(func.SuperLabel({Caption=KidData[id][3],Underline=0,FontSize=30,Bold=0,Left=140,Height=20,Top=300,Red=99/255,Green=37/255,Blue=35/255}))
InfoScreen:insert(func.SuperLabel({id=id,Caption=KidData[id][4],Underline=1,FontSize=30,Bold=0,Left=140,Height=20,Top=350,Red=0/255,Green=0/255,Blue=255/255,listener=RingNumber1}))
InfoScreen:insert(func.SuperLabel({id=id,Caption=KidData[id][5],Underline=1,FontSize=30,Bold=0,Left=140,Height=20,Top=400,Red=0/255,Green=0/255,Blue=255/255, listener=RingNumber2}))
InfoScreen:insert(func.WideButton2("Close",ActionButton,"CloseBtn", 550, 400))
end
return true
end
local ResRowRender = function( event )
local row = event.row
local id = row.index
row:insert(func.StandardImage("info.png", 35,40,LoadInfo,id))
if string.len(KidData[id][9]) > 0 then
row:insert(func.StandardLabelBold(KidData[id][2] .. " (" .. KidData[id][9] .. ")",70,40,24,0,0,0))
else
row:insert(func.StandardLabelBold(KidData[id][2] ,70,40,24,0,0,0))
end
row:insert(func.CreateYesNoButton(550,25,id,KidData[id][7],TickKid))
return true
end
local ResRowClick = function(event)
if event.phase == "release" then
local row = event.row
local id = tonumber(row.index)
if tonumber(KidData[id][7]) == 1 then
KidData[id][7] = 0
else
KidData[id][7] = 1
end
KidList:reloadData()
end
return true
end
LockSet = function(event)
if event.phase == "ended" then
if LockFlag == 0 then
LockFlag = 1
else
LockFlag = 0
end
if LockFlagYN ~= nil then
LockFlagYN:removeSelf()
LockFlagYN = nil
end
LockFlagYN = func.CreateYesNoButton(220,1075,id,LockFlag,LockSet)
group:insert(LockFlagYN)
end
return true
end
local LoadSaveOption = function()
if SaveButton ~= nil then
SaveButton:removeSelf()
SaveButton = nil
end
if #KidData == 0 then
func.ShowSimpleAlert("No Activity","There was no activity for this day.")
func.GoBack()
else
if tonumber(KidData[1][8]) == 0 then
LockFlagYN = func.CreateYesNoButton(220,1075,id,LockFlag,LockSet)
group:insert(LockFlagYN)
group:insert(func.StandardLabelBold("Finalise Records" ,270,1090,24,0,0,0))
SaveButton = func.WideButton2("Save Details",ActionButton,"SaveBtn", 550, 1090)
group:insert(SaveButton)
else
func.ShowSimpleAlert("Data Set Locked","You cannot make changes to this data set.")
end
end
end
local LoadList = function()
if KidList ~= nil then
KidList:deleteAllRows()
KidList:removeSelf()
KidList = nil
end
KidList = func.CreateListView(20, 190, 610, 830,ResRowRender, ResRowClick, true )
group:insert(KidList)
local MaleCol = {133/255,170/255,186/255}
local FemaleCol = {228/255,160/255,234/255}
local RowCol
for i = 1, #KidData do
if KidData[i][6] == "Male" then
RowCol = MaleCol
else
RowCol = FemaleCol
end
KidList:insertRow
{
rowHeight = 80,
lineColor={212/255,212/255, 212/255},
rowColor =
{
default = RowCol,
},
}
end
LoadSaveOption()
_G.HaltNav = nil
end
LoadDataSet = function(DataSet)
func.LoadDataSet(DataSet,KidData,"|","¬")
LoadList()
end
function scene:enterScene(event)
LockFlag = 0
RunDateValue = os.date("%d/%m/%Y")
group:insert(func.SuperLabel({Caption="Activity Date:",Underline=0,FontSize=30,Bold=1,Left=20,Height=20,Top=110,Red=99/255,Green=37/255,Blue=35/255}))
RunDate = func.SuperLabel({Border=1,id="RunDate",listener=ShowCalendar,Caption=RunDateValue,FontSize=30,Left=250,Width=170,Height=25,Top=110,Red=0/255,Green=0/255,Blue=0/255})
group:insert(RunDate)
group:insert(func.CreateBox2(10,1090,display.contentWidth-20,90,242/255,242/255,242/255,nil,1,0,0,0))
group:insert(func.WideButton2("<< Back",ActionButton,"BackBtn", 100, 1090))
if ActivityID == 1 then
group:insert(func.StandardImage("SaturdayCoachingSmall.png", 570,90))
elseif ActivityID == 2 then
group:insert(func.StandardImage("SaturdayRideSmall.png", 570,90))
elseif ActivityID == 3 then
group:insert(func.StandardImage("RollersSmall.png", 570,90))
end
--group:insert(func.DrawLine(40,190,600,190,2,0,0,0))
InPast = 0
RefreshDataSet()
end
function scene:createScene( event )
group = self.view
local prior_scene = storyboard.getPrevious()
storyboard.removeScenePurgeAll( prior_scene )
ActivityID = tonumber(event.params.ActivityID)
group:insert(func.CreateStandardHeader(nil, nil))
end
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.removeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
---------------------------------------------------------------------------------
return scene