-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1132 lines (873 loc) · 39.6 KB
/
index.html
File metadata and controls
1132 lines (873 loc) · 39.6 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
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8" />
<title>ICARDS Flash Cards</title>
<meta name="description" content="St John NZ ICARDS Flash Cards" />
<meta name="keywords" content="St John, icards, flash cards, drugs, indications, action, contraindications, cautions, dose, route, gtn, methoxy, adrenaline, aspirin, ondansetron, glucagon, paracetamol, salbutamol"/>
<meta name="author" content="Jarrod Oberto" />
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/skeleton.css" />
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png" />
<style>
@font-face {
font-family: "Raleway";
src:
url("fonts/Raleway/Raleway-VariableFont_wght.ttf")
format("truetype"),
font-weight: normal;
font-style: normal;
}
hr {
margin-top: 2rem;
/* border-top: 1px solid #eef1f3;*/
border-style: dashed;
}
h1 .sub {
font-size: 2rem;
vertical-align: middle;
}
h4 {
text-decoration: underline;
}
h6 {
font-weight: bold;
text-decoration: underline;
margin: 0 0 10px 0;
padding: 0;
}
textarea {
height: 200px;
}
.retest-cards {
cursor: pointer;
}
#show-icards-details li {
margin-bottom: 0px;
}
/* collapsible area */
.collapsible {
background-color: #f1f1f1;
color: #444;
cursor: pointer;
padding: 10px;
border: none;
text-align: left;
outline: none;
font-size: 18px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0;
}
.collapsible .options-text {
flex-grow: 1;
text-align: right;
}
.active, .collapsible:hover {
background-color: #ddd;
}
.content {
padding: 0 10px;
display: none;
overflow: hidden;
background-color: #f9f9f9;
}
.icon {
margin-left: 10px;
}
/* End collapsible area */
/* Adding icons to buttons */
ion-icon {
pointer-events: none;
}
.button ion-icon {
font-size: 20px;
vertical-align: middle;
padding-bottom: 3px;
}
.button.short {
padding: 0 15px !important; /* Use this if you're using only an icon in a button*/
}
.button.slim {
height:25px;
line-height: 25px;
}
.button.slim ion-icon {
font-size: 15px;
}
/* End adding icons to buttons */
/* Checkboxes */
#checkbox-container-icards, #checkbox-container-drugs, #checkbox-container-saved-sets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
padding: 15px;
}
#checkbox-container-icards input,
#checkbox-container-drugs input {
margin-bottom: 0.6rem;
}
.item {
display: flex;
align-items: center;
}
.item label {
margin-left: 5px;
/* margin-bottom: 1.5rem; */
font-weight: normal;
}
ul {
list-style-position: outside;
}
.li-header {
/* text-decoration: underline; */
font-weight: bold;
margin: 10px 0 15px 0;
display: inline-block;
}
/* End Checkboxes */
/* Tooltip */
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
padding: 0px;
margin: 0px;
border-radius: 5px;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 125%; /* Adjust as needed */
left: 50%;
transform: translateX(-50%);
opacity: 0;
transition: opacity 0.3s;
transition-delay: 1.5s; /* 3-second delay */
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
/* End Tooltips */
/* Additional button styles */
.button.button-secondary,
button.button-secondary,
input[type="submit"].button-secondary,
input[type="reset"].button-secondary,
input[type="button"].button-secondary {
color: #FFF;
background-color: #1abc9c;
border-color: #16a085; }
.button.button-secondary:hover,
button.button-secondary:hover,
input[type="submit"].button-secondary:hover,
input[type="reset"].button-secondary:hover,
input[type="button"].button-secondary:hover,
.button.button-secondary:focus,
button.button-secondary:focus,
input[type="submit"].button-secondary:focus,
input[type="reset"].button-secondary:focus,
input[type="button"].button-secondary:focus {
color: #FFF;
background-color: #16a085;
border-color: #117864; }
.button.button-tirtiary,
button.button-tirtiary,
input[type="submit"].button-tirtiary,
input[type="reset"].button-tirtiary,
input[type="button"].button-tirtiary {
color: #FFF;
background-color: #3498db;
border-color: #2980b9; }
.button.button-tirtiary:hover,
button.button-tirtiary:hover,
input[type="submit"].button-tirtiary:hover,
input[type="reset"].button-tirtiary:hover,
input[type="button"].button-tirtiary:hover,
.button.button-tirtiary:focus,
button.button-tirtiary:focus,
input[type="submit"].button-tirtiary:focus,
input[type="reset"].button-tirtiary:focus,
input[type="button"].button-tirtiary:focus {
color: #FFF;
background-color: #2980b9;
border-color: #1f618d; }
/* End Additional button styles */
/* red (alt: #ff6f61) */
.red {
color: #e74c3c;
}
/* blue */
.blue {
color: #3498db;
}
</style>
<script
type="module"
src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"
></script>
<script
nomodule
src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"
></script>
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row" style="margin-top: 20px">
<div class="column">
<h1 class="u-pull-left">ICARDS <span class="sub">St John NZ - ICARDS Flash Cards</span></h1>
</div>
</div>
<button class="collapsible">
<div class="options-text" style="font-size: 10px">Options</div>
<!-- -->
<ion-icon name="chevron-down-outline" aria-hidden="true" class="icon"></ion-icon>
</button>
<div class="content">
<!-- iCards -->
<div style="margin-top:20px"><input type="checkbox" id="" data-name="icards" onclick="toggleAllCheckboxes(this, '.item-icards input')"> <h6 style="display: inline-block">ICARDS</h6> </div>
<div id="checkbox-container-icards"></div>
<!-- drugs -->
<div><input type="checkbox" id="" data-name="drugs" onclick="toggleAllCheckboxes(this, '.item-drugs input')"> <h6 style="display: inline-block">Drugs</h6> </div>
<div id="checkbox-container-drugs"></div>
<!-- Saved sets -->
<div> <h6 style="display: inline-block">Saved Sets</h6> </div>
<div id="checkbox-container-saved-sets"></div>
<div style="padding: 15px;">
<!-- <a href="#" onclick="saveSet();return false;">Save</a> -->
<!-- <a href="#" onclick="removeSet(this);return false;" class="u-pull-right" id="remove-current-set" data-current-set-name="">Delete current set (<span id="current-set-name"></span>)</a> -->
<a class="button short slim blue"
id="add-to-retest-btn"
aria-hidden="true"
title=""
onclick="saveSet();return false;"><ion-icon name="bookmark"></ion-icon>Save set
</a>
<a class="button short slim u-pull-right red"
id="remove-current-set"
data-current-set-name=""
aria-hidden="true"
title=""
onclick="removeSet(this);return false;"><ion-icon name="trash"></ion-icon>Delete current set (<span id="current-set-name"></span>)
</a>
</div>
<!-- Footer -->
<div><span class="u-pull-right" style="color: #ccc">v1.3.1</span></div>
</div>
<div class="row" style="margin-top: 20px">
<div class="one-half column">
<div><strong>Drug:</strong> <span id="drug"></span></div>
<div><strong>ICARD:</strong> <span id="icard"></span></div>
</div>
<div class="one-half column">
<a class="button button-secondary u-pull-right"
id="next-question-btn"
onclick="getNextQuestion()">Next question</a>
<label class="retest-cards u-pull-right" style="clear:both">
<input type="checkbox" id="retestCheckbox">
<span class="label-body tooltipx">Retest cards (<span id="retest-card-count"></span>)
<!-- <span class="tooltiptext">Only use marked cards</span> -->
</span>
</label>
</div>
</div>
<hr />
<div class="row" style="margin-top: 30px">
<div class="one-half column">
<textarea
class="u-full-width"
placeholder="Your answer"
id="your-answer-tarea"
></textarea>
<div class="u-pull-right">
<a class="button button-tirtiary"
id="show-answer-btn"
onclick="toggleAnswer()"
>Show answer</a>
</div>
</div>
<div class="one-half column">
<div id="answer-container" style="display: none">
<div id="answer"></div>
<a class="button short u-pull-right tooltip"
id="add-to-retest-btn"
aria-hidden="true"
title=""
onclick="addToRetest()"><ion-icon name="add-circle-outline" id="add-to-retest-icon"></ion-icon>
<span class="tooltiptext">Retest later</span>
</a>
</div>
</div>
</div>
<div class="row" id="show-icards-container" style="margin-top: 20px; display:none;">
<div class="column">
<div><h4 id="show-icards-drug-name"></h4></div>
<div id="show-icards-details"></div>
</div>
</div>
<hr />
<div class="row" id="footer" style="margin-top: 20px; color: #ccc; font-size: 12px;">
<div class="column" >
<span>Contact: <a href="mailto:jarrod.oberto@stjohn.org.nz">Email me</a></span> <br />
<span><a href="listdata.html" target="_blank">View all data</a></span> -
<span>Last updated: Mar 2025</span><br />
</div>
</div>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<!-- Main script that imports helper.js -->
<script src="./data/drugs.js"></script>
<script src="./data/icards.js"></script>
<script src="./js/utils.js"></script>
<script src="./js/local-storage.js"></script>
<script>
// window.addEventListener("DOMContentLoaded", function () {
var _storeObj = LocalStorage;
let drugs = Utils.sortByName(drugData.getAllDrugs());
let icards = icardData.getAllIcards();
console.log('%c> icards:', "color:pink", icards);
var _currentSelection = {
drug: {},
icard: {},
}
reset();
drawCheckboxes(
icards,
document.getElementById("checkbox-container-icards"),
"icards",
);
drawCheckboxes(
drugs,
document.getElementById("checkbox-container-drugs"),
"drugs",
);
CheckOffSelectedItems(icards, "icards");
CheckOffSelectedItems(drugs, "drugs");
drawSavedSets(
document.getElementById("checkbox-container-saved-sets"),
"saved-sets"
);
getNextQuestion();
document.getElementById('remove-current-set').style.display = 'none';
function getNextQuestion()
{
const checkbox = document.querySelector('#retestCheckbox');
// If "to learn" (Re-test) checkbox is selected
if (checkbox.checked) {
console.log('%c> getToLearnQuestion()', "color:#f1107a");
var dataset = getToLearnQuestion();
} else {
console.log('%c> getRandomQuestion()', "color:#f1107a");
var dataset = getRandomQuestion();
}
if (typeof dataset === "undefined") {
console.log('%c> ** No drugs/icards **', "color:skyblue");
return;
}
let randomDrugObj = dataset.drug;
let randomIcardObj = dataset.icard;
_currentSelection.drug = randomDrugObj;
_currentSelection.icard = randomIcardObj;
populateQuestion(randomDrugObj, randomIcardObj);
}
function showSelectedQuestion()
{
let retestItemObj = getRetestItem();
populateQuestion(retestItemObj.drug, retestItemObj.icard);
}
function populateQuestion(drugObj, icardObj)
{
// Reset the elements
reset();
console.log('%c> randomDrugObj:', 'color:orange', drugObj);
console.log('%c> randomIcard:', 'color:orange', icardObj);
// Update the HTML with selected drug + icard
document.getElementById("drug").innerHTML = '<a id="showDrugIcard" href="#" >' + drugObj.name + '</a>';
// Add an event listener to the dynamically created link - this will show the whole icard for the drug
document.getElementById("showDrugIcard").addEventListener("click", function(event) {
event.preventDefault();
// Show the row
let containerElement = document.getElementById("show-icards-container");
if (containerElement.style.display === "none") {
drawDrugIcardClick(drugObj, icards)
containerElement.style.display = "block";
} else {
containerElement.style.display = "none";
}
});
document.getElementById("icard").innerHTML = icardObj.name;
// Get the answer from the obj
const answerArr = drugObj[icardObj.id];
// Format the answer
formattedAnswer = formatAnswer(answerArr);
// Update the HTML with answer
document.getElementById("answer").innerHTML = formattedAnswer;
}
function getRandomQuestion()
{
// Get pool of user selected icard items
var icardsUserSelected = getUserSelectedItems(icards);
// Get pool of user selected drugs items -> JI: this could also be getUserToLearnItems
var drugsUserSelected = getUserSelectedItems(drugs);
// Validate at lease 1 ICARD has been selected
if (icardsUserSelected.length == 0) {
console.log("No ICARDS selected");
return;
}
// Validate at lease 1 drug has been selected
if (drugsUserSelected.length == 0) {
console.log("No drugs selected");
return;
}
// Get a random drug from our object
const randomDrugObj =
drugsUserSelected[
Math.floor(Math.random() * drugsUserSelected.length)
];
// Get a random icard property
const randomIcardObj =
icardsUserSelected[
Math.floor(Math.random() * icardsUserSelected.length)
];
return {
'drug': randomDrugObj,
'icard': randomIcardObj
}
}
function getToLearnQuestion()
{
// const toLearnObjs = JSON.parse(localStorage.getItem("tolearn")) || [];
const toLearnObjs = _storeObj.decode(_storeObj.load('tolearn')) || [];
// Validate at lease 1 ICARD has been selected
if (toLearnObjs.length == 0) {
console.log("No cards to learn");
return;
}
// if (toLearnObjs.length == 0) {
// return {
// 'drug': '',
// 'icard': ''
// };
// }
console.log('%c> toLearnObjs:', 'color:orange', toLearnObjs);
/*
// Example object
let toTestObj = {
drug: {
"name": "Salbutamol",
"id": "salbutamol",
"dd": [
"1-2 hours"
],
},
icard: {id: 'dd', name: 'Duration'}
};
*/
// Get from local storage -> return array of objects [{},{},{}] (each object will look like `toTestObj`)
// toLearnObjs = [{},{},{}];
//
// Get a random "to learn" object
const toTestObj =
toLearnObjs[
Math.floor(Math.random() * toLearnObjs.length)
];
console.log('%c> toTestObj:', 'color:orange', toTestObj);
const randomDrugObj = toTestObj.drug;
const randomIcardObj = toTestObj.icard;
return {
'drug': randomDrugObj,
'icard': randomIcardObj
}
}
function reset()
{
// Reset the answer box (hide it)
let element = document.getElementById("answer-container");
element.style.display = "none";
// Reset the "Show Answer button"
let answerButton = document.getElementById("show-answer-btn");
answerButton.innerText = "Show answer";
// Reset the answer text area (clear it)
document.getElementById("your-answer-tarea").value = "";
// Hide the row that shows the whole icard
let containerElement = document.getElementById("show-icards-container");
containerElement.style.display = "none";
/* =============================================================================
* Rest the "Retest cards" stuff
* ===========================================================================*/
updateRetestCards();
}
function updateRetestCards()
{
// Get the button and the icon
const button = document.getElementById('add-to-retest-btn');
const icon = document.getElementById('add-to-retest-icon');
let toLearnCount = _storeObj.getDrugCount('tolearn');
// Update the inner text with the new count
const retestCardCountElement = document.getElementById('retest-card-count');
retestCardCountElement.textContent = toLearnCount;
if (toLearnCount > 0) {
// Show this
document.querySelector('.retest-cards').style.display = '';
} else {
// Hide this
document.querySelector('.retest-cards').style.display = 'none';
// Uncheck
// document.getElementById("retestCheckbox").checked = false;
document.querySelector('#retestCheckbox').checked = false;
}
// ~~~ ++ ~~~ END
let item = _storeObj.getDrugById('tolearn', _currentSelection.drug.id, _currentSelection.icard.id);
// Set button icon
if (typeof item === "undefined") {
icon.setAttribute('name', 'add-circle-outline');
} else {
icon.setAttribute('name', 'remove-circle-outline');
}
}
function drawCheckboxes(items, checkboxContainer, classname)
{
items.forEach((item) => {
let div = document.createElement("div");
div.classList.add("item");
div.classList.add("item-" + classname);
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = item.id;
checkbox.checked = true;
checkbox.addEventListener("change", saveSelectedItems);
checkbox.setAttribute("data-name", classname);
let label = document.createElement("label");
label.htmlFor = item.id;
label.textContent = item.name;
div.appendChild(checkbox);
div.appendChild(label);
checkboxContainer.appendChild(div);
});
}
function formatAnswer(answerArr)
{
let html = "";
html += "<ul>";
for (i = 0, len = answerArr.length; i < len; i++) {
var answer = answerArr[i];
if (answer.indexOf("no-bullet") >= 0) {
html += answer;
} else {
html += "<li>" + answer + "</li>";
}
}
html += "</ul>";
return html;
}
function showAnswer() {
let element = document.getElementById("answer-container");
element.style.display = "block";
}
function toggleAnswer() {
let element = document.getElementById("answer-container");
let button = document.getElementById("show-answer-btn");
if (
element.style.display === "none" ||
element.style.display === ""
) {
element.style.display = "block";
button.innerText = "Hide answer"; // Change button text
} else {
element.style.display = "none";
button.innerText = "Show answer"; // Reset button text
}
}
function getUserSelectedItems(items) {
const selectedItems = [];
items.forEach((item) => {
let checkbox = document.getElementById(item.id);
if (checkbox.checked) {
// selectedItems.push({
// id: item.id,
// name: item.name,
// });
selectedItems.push(item);
}
});
return selectedItems;
}
function saveSelectedItems() {
let name = this.getAttribute("data-name");
_saveSelectedItems(name)
}
// Save selected items to local storage
function _saveSelectedItems(name) {
const selectedItems = [];
if (name == "icards") {
icards.forEach((item) => {
let checkbox = document.getElementById(item.id);
if (checkbox.checked) {
selectedItems.push({
id: item.id,
name: item.name,
});
}
});
} else if (name == "drugs") {
drugs.forEach((item) => {
let checkbox = document.getElementById(item.id);
if (checkbox.checked) {
selectedItems.push({
id: item.id,
name: item.name,
});
}
});
}
localStorage.setItem(name, JSON.stringify(selectedItems));
}
// Load selected items from local storage
function CheckOffSelectedItems(items, name) {
const savedItems = JSON.parse(localStorage.getItem(name)) || [];
if (savedItems == "") {
return;
}
// Clear previous selections
items.forEach((item) => {
let checkbox = document.getElementById(item.id);
checkbox.checked = false; // Uncheck all checkboxes
});
// Repopulate checkboxes based on saved items
savedItems.forEach((savedItem) => {
let checkbox = document.getElementById(savedItem.id);
if (checkbox) {
checkbox.checked = true; // Check the saved checkboxes
}
});
// alert("Checkboxes loaded from local storage.");
}
function addToRetest()
{
console.log('%c> _currentSelection:', "color:orange", _currentSelection);
// Get the button and the icon
const button = document.getElementById('add-to-retest-btn');
const icon = document.getElementById('add-to-retest-icon');
// See if this is already in our "toLearn" list.
let item = _storeObj.getDrugById('tolearn', _currentSelection.drug.id, _currentSelection.icard.id);
/**
* If an item is returned, then it already exists. If it's undefined,
* then it doesn't so we can add it.
*/
if (typeof item === "undefined") {
console.log('%c> >>> Add to Retest List', "color:#f1107a");
// Do this first to feel more responsive
// icon.setAttribute('name', 'remove-circle-outline');
// Add
_storeObj.addItem('tolearn', _currentSelection);
} else {
console.log('%c> >>> Remove from Retest List', "color:#f1107a");
// Do this first to feel more responsive
// icon.setAttribute('name', 'add-circle-outline');
// remove
_storeObj.deleteDrugById('tolearn', _currentSelection.drug.id, _currentSelection.icard.id);
}
updateRetestCards();
}
document.addEventListener("DOMContentLoaded", function () {
var collapsible = document.querySelector(".collapsible");
var content = document.querySelector(".content");
var icon = document.querySelector("ion-icon");
collapsible.addEventListener("click", function () {
this.classList.toggle("active");
// Toggle content visibility
if (content.style.display === "block") {
content.style.display = "none";
icon.setAttribute("name", "chevron-down-outline");
} else {
content.style.display = "block";
icon.setAttribute("name", "chevron-up-outline");
}
});
});
// Toggle all checkboxes based on the "Select All" checkbox state
function toggleAllCheckboxes(selectAllCheckbox, ele) {
console.log('%c> aaaa)', "color:#f1107a");
// const checkboxes = document.querySelectorAll('.item-icards input');
const checkboxes = document.querySelectorAll(ele);
checkboxes.forEach(checkbox => {
console.log('%c> ^', "color:#f1107a");
checkbox.checked = selectAllCheckbox.checked;
});
let name = selectAllCheckbox.getAttribute("data-name");
_saveSelectedItems(name);
}
function drawDrugIcardClick(drugObj, icardsObj)
{
console.log('%c> drugObj_:', "color:orange", drugObj);
console.log('%c> icardsObj_:', "color:orange", icardsObj);
// Add the header
let headerElement = document.getElementById("show-icards-drug-name");
headerElement.innerHTML = drugObj.name;
var icardsDetails = ''
icardsObj.forEach((item) => {
icardsDetails += '<h6>' + item.name + '</h6>';
const answerArr = drugObj[item.id];
console.log('%c> answerArr:', "color:orange", answerArr);
icardsDetails += formatAnswer(answerArr);
});
// Add the icards contents
let detailsElement = document.getElementById("show-icards-details");
detailsElement.innerHTML = icardsDetails;
// // Show the row
// let containerElement = document.getElementById("show-icards-container");
// containerElement.style.display = "block";
}
function removeSet(ele) {
let name = ele.getAttribute("data-current-set-name");
console.log('%c> name to remove:', 'color:orange', name);
_storeObj.deleteSavedSetById('savedSets', name);
// Refresh the displayed list
drawSavedSets(
document.getElementById("checkbox-container-saved-sets"),
"saved-sets"
);
// Hide remove button
ele.style.display = 'none';
}
function saveSet() {
// Get saved sets
const savedSetsArr = _storeObj.decode(_storeObj.load('savedSets'), '[]') || [];
// Validate at least has been found
if (savedSetsArr.length == 0) {
console.log("No saved sets");
}
// Get the icards that are selected
const selectedIcardItems = [];
icards.forEach((item) => {
let checkbox = document.getElementById(item.id);
if (checkbox.checked) {
selectedIcardItems.push({
id: item.id,
name: item.name,
});
}
});
// Get the drugs that are selected
const selectedDrugItems = [];
drugs.forEach((item) => {
let checkbox = document.getElementById(item.id);
if (checkbox.checked) {
selectedDrugItems.push({
id: item.id,