-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_logic.bsh
838 lines (750 loc) · 33.7 KB
/
ui_logic.bsh
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
User user; // dont touch
String userid;
/*** control ***/
onEvent("control", "show", "refreshBuildings();removeNavigationButtons();");
onEvent("control/building/BuildingList", "click", "loadBuilding();");
onEvent("control/building/newBuilding", "click", "newBuilding();");
refreshBuildings() {
fetchEntityList("Building", new FetchCallback() {
onFetch(entities) {
populateList("control/building/BuildingList", entities);
}
});
}
startSync() {
setSyncEnabled(true);
setFileSyncEnabled(true);
}
stopSync() {
setSyncEnabled(false);
setFileSyncEnabled(false);
}
setSyncMinInterval(10.0f);
setSyncMaxInterval(20.0f);
setSyncDelay(5.0f);
startSync();
addActionBarItem("sync", new ToggleActionButtonCallback() {
actionOnLabel() {
"Disable Sync";
}
actionOn() {
setSyncEnabled(false);
setFileSyncEnabled(false);
showToast("Sync disabled.");
}
isActionOff() {
isSyncEnabled();
}
actionOffLabel() {
"Enable Sync";
}
actionOff() {
setSyncEnabled(true);
setFileSyncEnabled(true);
showToast("Sync enabled.");
}
});
removeNavigationButtons() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
}
/*** ArchEnt: Building ***/
onEvent("Building", "show", "addBuildingNavigation();");
onFocus("Building/Building/Street_address", null, "activateAutoSaveBuilding();");
onEvent("Building/Building/Has_Alterations", "click", "showAlterationTab();");
onEvent("Building/Building/Has_Verandah", "click", "showVerandahTab();");
onEvent("Building/Alterations", "show", "refreshRelatedAlterations()");
onEvent("Building/Alterations/newAlteration", "click", "newAlterationFromBuilding()");
onEvent("Building/Alterations/AlterationList", "click", "loadAlteration()");
onEvent("Building/Dates", "show", "refreshRelatedDates()");
onEvent("Building/Dates/generateDates", "delayclick", "generateDates()");
onEvent("Building/Dates/newDate", "click", "newDateFromBuilding()");
onEvent("Building/Dates/DateList", "click", "loadDate()");
onEvent("Building/Building/attachPhoto", "click", "attachPictureTo(\"Building/Building/Photo\")");
onEvent("Building/Building/attachPlan_sketch", "click", "attachFileTo(\"Building/Building/Plan_sketch\")");
onEvent("Building/Roof/attachGable_sketch", "click", "attachFileTo(\"Building/Roof/Gable_form_other\")");
onEvent("Building/Roof/attachFinial_sketch", "click", "attachFileTo(\"Building/Roof/Finial_other\")");
onEvent("Building/Verandah/attachVerandahRoof_sketch", "click", "attachFileTo(\"Building/Verandah/Verandah_roof_form_other\")");
onEvent("Building/Verandah/attachVerandahPosts_sketch", "click", "attachFileTo(\"Building/Verandah/Verandah_posts_other\")");
onEvent("Building/Components/attachWindowOther_sketch", "click", "attachFileTo(\"Building/Components/Windows_other\")");
onEvent("Building/Components/attachWindowArch_sketch", "click", "attachFileTo(\"Building/Components/Window_arch_lintel_other\")");
onEvent("Building/Components/attachWindowHead_sketch", "click", "attachFileTo(\"Building/Components/Window_head_other\")");
onEvent("Building/Components/attachDoorForm_sketch", "click", "attachFileTo(\"Building/Components/Door_form_other\")");
onEvent("Building/Building/viewattached", "click", "viewArchEntAttachedFiles(building_id)");
onEvent("Building/Roof/viewattached", "click", "viewArchEntAttachedFiles(building_id)");
onEvent("Building/Verandah/viewattached", "click", "viewArchEntAttachedFiles(building_id)");
onEvent("Building/Components/viewattached", "click", "viewArchEntAttachedFiles(building_id)");
String building_id = null;
newBuilding() {
newTabGroup("Building");
building_id = null;
setTimestamp("Building/Building/Date");
// Make sure the Alteration and Verandah tabs are not showing
onEvent("Building", "show", "showTab(\"Building/Alterations\");showTab(\"Building/Verandah\");cancelTab(\"Building/Verandah\", false);cancelTab(\"Building/Alterations\", false);showTab(\"Building/Building\");");
}
loadBuilding() {
building_id = getListItemValue();
loadBuildingFrom(building_id);
}
loadBuildingFrom(archent_id) {
if (isNull(archent_id)) {
showToast("No record selected");
return;
}
showTabGroup("Building", archent_id, new FetchCallback() {
onFetch(result) {
building_id = archent_id;
matchVocab("Building/Building/Has_Verandah", "{Yes}", new FetchCallback() {
onFetch(result) {
if(!isNull(result)) {
showTab("Building/Verandah");
showTab("Building/Building");
} else {
showTab("Building/Verandah");
cancelTab("Building/Verandah", false);
showTab("Building/Building");
}
}
});
matchVocab("Building/Building/Has_Alterations", "{Yes}", new FetchCallback() {
onFetch(result) {
if(!isNull(result)) {
showTab("Building/Alterations");
showTab("Building/Building");
} else {
showTab("Building/Alterations");
cancelTab("Building/Alterations", false);
showTab("Building/Building");
}
}
});
saveTabGroup("Building", building_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
building_id = uuid;
}
}, true);
}
});
}
activateAutoSaveBuilding() {
if(!isNull(building_id)) return;
if(isNull(getFieldValue("Building/Building/Street_address"))) return;
saveTabGroup("Building", building_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
building_id = uuid;
saveTabGroup("Building", building_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
building_id = uuid;
}
}, true);
}
});
}
isBuildingSaved() {
if(isNull(building_id)) {
if (isNull(getFieldValue("Building/Building/Street_address"))) {
showWarning("Validation Error", "Cannot save Building without Street Address.");
} else {
showToast("Please wait for this {Building} to finish saving.");
}
return false;
}
return true;
}
newAlterationFromBuilding() {
if(isBuildingSaved()) newAlteration();
}
newDateFromBuilding() {
if(isBuildingSaved()) newDate();
}
deleteBuilding() {
if (!isNull(building_id)) {
showAlert("Confirm Deletion", "Press OK to Delete this {Building} Record!", "reallyDeleteBuilding()", "doNotDelete()");
} else {
cancelTabGroup("Building", false);
}
}
reallyDeleteBuilding() {
deleteArchEnt(building_id, new DeleteCallback() {
onDelete(uuid) {
cancelTabGroup("Building", false);
}
});
}
loadBuildingAttributes() {
makeVocab("DropDown", "Building/Building/Original_purpose", "Original purpose");
makeVocab("RadioGroup", "Building/Building/Change_of_purpose", "Change of purpose");
makeVocab("DropDown", "Building/Building/Scale", "Scale");
makeVocab("RadioGroup", "Building/Building/Qualities", "Qualities");
makeVocab("DropDown", "Building/Building/Orientation_of_facade", "Orientation of facade");
makeVocab("DropDown", "Building/Building/Orientation_facade_faces", "Orientation facade faces");
makeVocab("DropDown", "Building/Building/Forecourt_space", "Forecourt space");
makeVocab("DropDown", "Building/Building/Forecourt_decoration", "Forecourt decoration");
makeVocab("DropDown", "Building/Building/Outbuildings", "Outbuildings");
makePictureGallery("Building/Building/Plan", "Plan");
makeVocab("RadioGroup", "Building/Building/Has_Verandah", "Has Verandah");
makeVocab("RadioGroup", "Building/Building/Has_Alterations", "Has Alterations");
makeVocab("RadioGroup", "Building/Roof/Gable_detail_bargeboard", "Gable detail bargeboard");
makePictureGallery("Building/Roof/Gable_form", "Gable form");
populateHierarchicalPictureGallery("Building/Roof/Finial", "Finial");
makeVocab("DropDown", "Building/Roof/Chimney_form", "Chimney form");
makeVocab("DropDown", "Building/Roof/Chimney_orientation", "Chimney orientation");
makeVocab("DropDown", "Building/Roof/Chimney_decorative_detail", "Chimney decorative detail");
makePictureGallery("Building/Roof/Roof_form", "Roof form");
makeVocab("RadioGroup", "Building/Verandah/Location", "Location");
makeVocab("RadioGroup", "Building/Verandah/Verandah_status", "Verandah status");
makeVocab("DropDown", "Building/Verandah/Verandah_decorative_detail", "Verandah decorative detail");
makePictureGallery("Building/Verandah/Verandah_posts", "Verandah posts");
makePictureGallery("Building/Verandah/Verandah_roof_form", "Verandah roof form");
makeVocab("DropDown", "Building/Walls/Wall_material", "Wall material");
makePictureGallery("Building/Walls/Wall_brick", "Wall brick");
makeVocab("RadioGroup", "Building/Walls/Wall_rendered", "Wall rendered");
makePictureGallery("Building/Walls/Wall_timber", "Wall timber");
makePictureGallery("Building/Walls/Decorative_Timber", "Decorative Timber");
makePictureGallery("Building/Walls/Wall_masonry", "Wall masonry");
makePictureGallery("Building/Walls/Wall_quoins", "Wall quoins");
makeVocab("DropDown", "Building/Components/Window_sash", "Window sash");
makeVocab("DropDown", "Building/Components/Window_casement", "Window casement");
makeVocab("DropDown", "Building/Components/Window_bay", "Window bay");
makePictureGallery("Building/Components/Window_Type", "Window Type");
makePictureGallery("Building/Components/Window_head", "Window head");
makeVocab("DropDown", "Building/Components/Bay_form", "Bay form");
makeVocab("DropDown", "Building/Components/Window_dormer", "Window dormer");
makeVocab("DropDown", "Building/Components/Replacements", "Replacements");
populateHierarchicalPictureGallery("Building/Components/Window_arch_lintel", "Window arch lintel");
makeVocab("CheckBoxGroup", "Building/Components/Window_decorative_detail", "Window decorative detail");
makeVocab("DropDown", "Building/Components/Window_glazing", "Window glazing");
makeVocab("DropDown", "Building/Components/Door_lintel_arch", "Door lintel/arch");
makeVocab("DropDown", "Building/Components/Door_lintel_form", "Door lintel form");
makeVocab("DropDown", "Building/Components/Door_glazing", "Door glazing");
makeVocab("DropDown", "Building/Components/Door_glazing_detail", "Door glazing detail");
makePictureGallery("Building/Components/Door_form", "Door form");
makeVocab("RadioGroup", "Building/Summary_data/Archaeological_materials", "Archaeological materials");
populateHierarchicalDropDown("Building/Summary_data/Heritage_listed", "Heritage listed");
makeVocab("RadioGroup", "Building/Summary_data/Substantially_original", "Substantially original");
}
addBuildingNavigation() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
addNavigationButton("duplicate", new ActionButtonCallback() {
actionOnLabel() {
"Duplicate {Building}";
}
actionOn() {
if(isBuildingSaved()) {
showTabGroup("Building", building_id, new FetchCallback() {
onFetch(result) {
building_id = null;
populateCameraPictureGallery("Building/Building/Photo", new ArrayList());
populateFileList("Building/Building/Plan_sketch", new ArrayList());
populateFileList("Building/Roof/Gable_form_other", new ArrayList());
populateFileList("Building/Roof/Finial_other", new ArrayList());
populateFileList("Building/Verandah/Verandah_roof_form_other", new ArrayList());
populateFileList("Building/Verandah/Verandah_posts_other", new ArrayList());
populateFileList("Building/Components/Windows_other", new ArrayList());
populateFileList("Building/Components/Window_arch_lintel_other", new ArrayList());
populateFileList("Building/Components/Window_head_other", new ArrayList());
populateFileList("Building/Components/Door_form_other", new ArrayList());
setTimestamp("Building/Building/Date");
saveTabGroup("Building", building_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
building_id = uuid;
saveTabGroup("Building", building_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
building_id = uuid;
}
}, true);
}
});
}
});
}
}
}, "success");
addNavigationButton("new", new ActionButtonCallback() {
actionOnLabel() {
"New {Building}";
}
actionOn() {
if(!isNull(building_id)) {
newBuilding();
} else {
showAlert("Warning", "You will lose any unsaved changes!", "newBuilding()", "");
}
}
}, "success");
addNavigationButton("close", new ActionButtonCallback() {
actionOnLabel() {
"Close {Building}";
}
actionOn() {
if(!isNull(building_id)) {
cancelTabGroup("Building", false);
} else {
cancelTabGroup("Building", true);
}
}
}, "success");
addNavigationButton("delete", new ActionButtonCallback() {
actionOnLabel() {
"Delete {Building}";
}
actionOn() {
deleteBuilding();
}
}, "danger");
}
refreshRelatedAlterations() {
if(!isNull(building_id)) {
fetchAll("select uuid, group_concat(coalesce(measure || ' ' || vocabname || '(' ||freetext||')', measure || ' (' || freetext ||')', vocabname || ' (' || freetext ||')', measure || ' ' || vocabname , vocabname || ' (' || freetext || ')', measure || ' (' || freetext || ')', measure, vocabname, freetext, measure, vocabname, freetext), ' - ') as response, valuetimestamp\n"+
" FROM ( SELECT uuid, attributeid, vocabid, attributename, vocabname, measure, freetext, certainty, attributetype, valuetimestamp, aenttypename\n"+
" FROM latestNonDeletedArchentIdentifiers\n"+
" WHERE aenttypename = 'Alteration'\n"+
" AND uuid in (select uuid\n"+
" FROM latestNonDeletedAentReln\n"+
" where relationshipid in (select relationshipid\n"+
" FROM latestNonDeletedAentReln\n"+
" JOIN relationship using (relationshipid)\n"+
" JOIN relntype using (relntypeid)\n"+
" where uuid = "+building_id+"\n"+
" and relntypeName = 'BuildingAlteration')\n"+
" and uuid != "+building_id+")\n"+
" ORDER BY uuid, attributename DESC)\n"+
"group by uuid\n"+
"order by valuetimestamp desc, uuid, attributename;", new FetchCallback() {
onFetch(result) {
populateList("Building/Alterations/AlterationList", result);
}
});
} else {
populateList("Building/Alterations/AlterationList", new ArrayList());
}
}
refreshRelatedDates() {
if (!isNull(building_id)) {
fetchAll("select uuid, group_concat(coalesce(measure || ' ' || vocabname || '(' ||freetext||')', measure || ' (' || freetext ||')', vocabname || ' (' || freetext ||')', measure || ' ' || vocabname , vocabname || ' (' || freetext || ')', measure || ' (' || freetext || ')', measure, vocabname, freetext, measure, vocabname, freetext), ' - ') as response, valuetimestamp\n" +
" FROM ( SELECT uuid, attributeid, vocabid, attributename, vocabname, measure, freetext, certainty, attributetype, valuetimestamp, aenttypename\n"+
" FROM latestNonDeletedArchentIdentifiers\n"+
" WHERE aenttypename = 'Date'\n"+
" AND uuid in (select uuid\n"+
" FROM latestNonDeletedAentReln\n"+
" where relationshipid in (select relationshipid\n"+
" FROM latestNonDeletedAentReln\n"+
" JOIN relationship using (relationshipid)\n"+
" JOIN relntype using (relntypeid)\n"+
" where uuid = "+building_id+"\n"+
" and relntypeName = 'BuildingDate')\n"+
" and uuid != "+building_id+")\n"+
" ORDER BY uuid, case attributename when 'Date Description' then 1 when 'Min date' then 2 when 'Max date' then 3 end)\n"+
"group by uuid\n"+
"order by valuetimestamp desc, uuid, attributename;", new FetchCallback() {
onFetch(result) {
print(result);
populateList("Building/Dates/DateList", result);
}
});
} else {
populateList("Building/Dates/DateList", new ArrayList());
}
}
showAlterationTab() {
matchVocab("Building/Building/Has_Alterations", "{Yes}", new FetchCallback() {
onFetch(result) {
if(!isNull(result)) showTab("Building/Alterations");
}
});
}
showVerandahTab() {
matchVocab("Building/Building/Has_Verandah", "{Yes}", new FetchCallback() {
onFetch(result) {
if(!isNull(result)) showTab("Building/Verandah");
}
});
}
/** RelnEnt: Alteration **/
onEvent("Alteration", "show", "addAlterationNavigation();");
String alteration_id = null;
newAlteration() {
newTabGroup("Alteration");
alteration_id = null;
setTimestamp("Alteration/hidden/timestamp");
saveTabGroup("Alteration", alteration_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
alteration_id = uuid;
if(newRecord) {
saveEntitiesToRel("BuildingAlteration", building_id, uuid);
}
saveTabGroup("Alteration", alteration_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
alteration_id = uuid;
}
}, true);
}
});
}
loadAlteration() {
alteration_id = getListItemValue();
loadAlterationFrom(alteration_id);
}
loadAlterationFrom(archent_id) {
if (isNull(archent_id)) return;
showTabGroup("Alteration", archent_id, new FetchCallback() {
onFetch(result) {
alteration_id = archent_id;
saveTabGroup("Alteration", alteration_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
alteration_id = uuid;
}
}, true);
}
});
}
deleteAlteration() {
if (!isNull(alteration_id)) {
showAlert("Confirm Deletion", "Press OK to Delete this {Alteration} Record!", "reallyDeleteAlteration()", "doNotDelete()");
} else {
cancelTabGroup("Alteration", false);
showTab("Building/Alterations");
}
}
reallyDeleteAlteration() {
deleteArchEnt(alteration_id, new DeleteCallback() {
onDelete(uuid) {
cancelTabGroup("Alteration", false);
showTab("Building/Alterations");
}
});
}
loadAlterationAttributes() {
makeVocab("DropDown", "Alteration/Alteration/Alteration", "Alteration");
}
addAlterationNavigation() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
addNavigationButton("save", new ActionButtonCallback() {
actionOnLabel() {
"Duplicate {Alteration}";
}
actionOn() {
showTabGroup("Alteration", alteration_id, new FetchCallback() {
onFetch(result) {
alteration_id = null;
setTimestamp("Alteration/hidden/timestamp");
saveTabGroup("Alteration", alteration_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
alteration_id = uuid;
if(newRecord) {
saveEntitiesToRel("BuildingAlteration", building_id, uuid);
}
saveTabGroup("Alteration", alteration_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
alteration_id = uuid;
}
}, true);
}
});
}
});
}
}, "success");
addNavigationButton("new", new ActionButtonCallback() {
actionOnLabel() {
"New {Alteration}";
}
actionOn() {
newAlteration();
}
}, "success");
addNavigationButton("close", new ActionButtonCallback() {
actionOnLabel() {
"Close {Alteration}";
}
actionOn() {
cancelTabGroup("Alteration", false);
showTab("Building/Alterations");
}
}, "success");
addNavigationButton("delete", new ActionButtonCallback() {
actionOnLabel() {
"Delete {Alteration}";
}
actionOn() {
deleteAlteration();
}
}, "danger");
}
/*** RelnEnt: Date ***/
onEvent("Date", "show", "addDateNavigation();");
String date_id = null;
newDate() {
newTabGroup("Date");
date_id = null;
setTimestamp("Date/hidden/timestamp");
saveTabGroup("Date", date_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
date_id = uuid;
if(newRecord) {
saveEntitiesToRel("BuildingDate", building_id, uuid);
}
saveTabGroup("Date", date_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
date_id = uuid;
}
}, true);
}
});
}
loadDate() {
date_id = getListItemValue();
loadDateFrom(date_id);
}
loadDateFrom(archent_id) {
if (isNull(archent_id)) return;
showTabGroup("Date", archent_id, new FetchCallback() {
onFetch(result) {
date_id = archent_id;
saveTabGroup("Date", date_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
date_id = uuid;
}
}, true);
}
});
}
deleteDate() {
if (!isNull(date_id)) {
showAlert("Confirm Deletion", "Press OK to Delete this {Date} Record!", "reallyDeleteDate()", "doNotDelete()");
} else {
cancelTabGroup("Date", false);
showTab("Building/Dates");
}
}
reallyDeleteDate() {
deleteArchEnt(date_id, new DeleteCallback() {
onDelete(uuid) {
cancelTabGroup("Date", false);
showTab("Building/Dates");
}
});
}
loadDateAttributes() {
makeVocab("DropDown", "Date/Date/Date", "Date");
}
addDateNavigation() {
removeNavigationButton("duplicate");
removeNavigationButton("new");
removeNavigationButton("close");
removeNavigationButton("delete");
addNavigationButton("duplicate", new ActionButtonCallback() {
actionOnLabel() {
"Duplicate {Date}";
}
actionOn() {
showTabGroup("Date", date_id, new FetchCallback() {
onFetch(result) {
date_id = null;
setTimestamp("Date/hidden/timestamp");
saveTabGroup("Date", date_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
date_id = uuid;
if(newRecord) {
saveEntitiesToRel("BuildingDate", building_id, uuid);
}
saveTabGroup("Date", date_id, null, null, new SaveCallback() {
onSave(uuid, newRecord) {
date_id = uuid;
}
}, true);
}
});
}
});
}
}, "success");
addNavigationButton("new", new ActionButtonCallback() {
actionOnLabel() {
"New {Date}";
}
actionOn() {
newDate();
}
}, "success");
addNavigationButton("close", new ActionButtonCallback() {
actionOnLabel() {
"Close {Date}";
}
actionOn() {
cancelTabGroup("Date", false);
showTab("Building/Dates");
}
}, "success");
addNavigationButton("delete", new ActionButtonCallback() {
actionOnLabel() {
"Delete {Date}";
}
actionOn() {
deleteDate();
}
}, "danger");
}
generateDates() {
if(isNull(building_id)) {
showWarning("Warning", "Please fill in the Street Address.");
return;
}
showAlert("Confirm", "Are you sure? This will delete all of your current dates!", "reallyGenerateDates()", "doNotDelete()");
}
reallyGenerateDates() {
// Fetch all related dates
fetchAll("select uuid " +
" FROM ( SELECT uuid, attributeid, vocabid, attributename, vocabname, measure, freetext, certainty, attributetype, valuetimestamp, aenttypename\n"+
" FROM latestNonDeletedArchentIdentifiers\n"+
" WHERE aenttypename = 'Date'\n"+
" AND uuid in (select uuid\n"+
" FROM latestNonDeletedAentReln\n"+
" where relationshipid in (select relationshipid\n"+
" FROM latestNonDeletedAentReln\n"+
" JOIN relationship using (relationshipid)\n"+
" JOIN relntype using (relntypeid)\n"+
" where uuid = "+building_id+"\n"+
" and relntypeName = 'BuildingDate')\n"+
" and uuid != "+building_id+")\n"+
" ORDER BY uuid, attributename DESC)\n"+
"group by uuid\n"+
"order by valuetimestamp desc, uuid, attributename;", new FetchCallback() {
onFetch(result) {
for(date : result) {
deleteArchEnt(date.get(0));
}
//create dates based on the values of the fields require
if (!isNull(getFieldValue("Building/Roof/Roof_form"))) createDate("Building/Roof/Roof_form", "Date obtained from finials:");
if (!isNull(getFieldValue("Building/Roof/Finial"))) createDate("Building/Roof/Finial", "Date obtained from finials:");
if (!isNull(getFieldValue("Building/Components/Door_form"))) createDate("Building/Components/Door_form", "Date obtained from doors:");
if (!isNull(getFieldValue("Building/Verandah/Verandah_roof_form"))) createDate("Building/Verandah/Verandah_roof_form", "Date obtained from verandah roof form:");
if (!isNull(getFieldValue("Building/Verandah/Verandah_posts"))) createDate("Building/Verandah/Verandah_posts", "Date obtained from verandah posts:");
if (!isNull(getFieldValue("Building/Summary_data/Sources"))) createDate("Building/Summary_data/Sources", "Date obtained from historical sources:");
if (!isNull(getFieldValue("Building/Walls/Wall_quoins"))) createDate("Building/Walls/Wall_quoins", "Date obtained from quoins:");
if (!isNull(getFieldValue("Building/Roof/Chimney_form"))) createDate("Building/Roof/Chimney_form", "Date obtained from chimneys:");
refreshRelatedDates();
}
});
}
createDate(String path, String date_string) {
fetchOne("select vocabname from vocabulary where vocabid = '" + getFieldValue(path) + "';", new FetchCallback() {
onFetch(result) {
vocabname = result.get(0);
String low_date = null;
String high_date = null;
Pattern r = Pattern.compile("([0-9]{4,4})");
Matcher m = r.matcher(vocabname);
int count = 0;
while(m.find()) count++;
if(count == 1) {
m = r.matcher(vocabname);
m.find();
low_date = m.group();
high_date = "Present";
} else if (count == 2) {
m = r.matcher(vocabname);
m.find();
low_date = m.group();
m.find();
high_date = m.group();
}
if(count != 0) {
fetchOne("select vocabid from vocabulary where vocabname = '" + date_string + "';", new FetchCallback() {
onFetch(result) {
List attributes = createAttributeList();
attributes.add(createEntityAttribute("Date", null, result.get(0), null, "1.0"));
attributes.add(createEntityAttribute("Date Description", null, null, vocabname, "1.0"));
attributes.add(createEntityAttribute("Min date", null, null, low_date, "1.0"));
attributes.add(createEntityAttribute("Max date", null, null, high_date, "1.0"));
saveArchEnt(null, "Date", null, attributes, new SaveCallback() {
onSave(uuid, newRecord) {
date_id = uuid;
saveEntitiesToRel("BuildingDate", building_id, date_id);
}
});
}
});
}
}
});
}
// MISC FUNCTIONS
saveEntitiesToRel(String type, String entity1, String entity2) {
if (isNull(entity1) || isNull(entity2)) return;
saveRel(null, type, null, null, new SaveCallback() {
onSave(rel_id, newRecord) {
addReln(entity1, rel_id, null);
addReln(entity2, rel_id, null);
}
});
}
makeVocab(String type, String path, String attrib) {
fetchAll("select vocabid, vocabname from vocabulary join attributekey using (attributeid) where attributename = '"+attrib+"' order by vocabcountorder",
new FetchCallback() {
onFetch(result) {
if(type.equals("CheckBoxGroup")) {
populateCheckBoxGroup(path, result);
} else if(type.equals("DropDown")) {
populateDropDown(path, result);
} else if(type.equals("RadioGroup")) {
populateRadioGroup(path, result);
} else if(type.equals("List")) {
populateList(path, result);
}
}
});
}
matchVocab(String path, String vocabName, FetchCallback callback) {
fetchOne("select vocabname from vocabulary where vocabname = '" + vocabName + "' and vocabid = '" + getFieldValue(path) + "';", callback);
}
makePictureGallery(String path, String attrib) {
fetchAll("select vocabid, vocabname, pictureurl from vocabulary left join attributekey using (attributeid) where attributename = '" + attrib + "' order by vocabcountorder;",
new FetchCallback() {
onFetch(result) {
populatePictureGallery(path, result);
}
});
}
setTimestamp(String path) {
setFieldValue(path, new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(new Date()));
}
doNotDelete() {
showToast("Delete Cancelled.");
}
/*** Uneditable - you can edit the code below with extreme precaution ***/
/*** USER ***/
loadUsers() {
fetchAll("select userid, fname || ' ' || lname from user where userdeleted is null", new FetchCallback() {
onFetch(result) {
populateList("user/usertab/users", result);
}
});
}
loadUsers();
String username = "";
login() {
fetchOne("select userid,fname,lname,email from user where userid='" + getListItemValue() + "';", new FetchCallback() {
onFetch(result) {
user = new User(result.get(0),result.get(1),result.get(2),result.get(3));
setUser(user);
username = result.get(1) + " " + result.get(2);
showTabGroup("control");
}
});
}
onEvent("user/usertab/users", "click", "login()");
loadBuildingAttributes();
loadAlterationAttributes();
loadDateAttributes();