@@ -21,6 +21,55 @@ function dbg(str) {
21
21
dbgdiv . textContent = str ;
22
22
}
23
23
24
+ function getStoredCheckboxRefs ( checkbox ) {
25
+ existingRefs = readStorage ( "checkbox_" + checkbox ) ;
26
+ if ( ! existingRefs ) {
27
+ refsSet = new Set ( ) ;
28
+ } else {
29
+ refsSet = new Set ( existingRefs . split ( "," ) ) ;
30
+ }
31
+ return refsSet ;
32
+ }
33
+
34
+ function setBomCheckboxState ( checkbox , element , references ) {
35
+ var storedRefsSet = getStoredCheckboxRefs ( checkbox ) ;
36
+ var currentRefsSet = new Set ( references ) ;
37
+ // Get difference of current - stored
38
+ var difference = new Set ( currentRefsSet ) ;
39
+ for ( ref of storedRefsSet ) {
40
+ difference . delete ( ref ) ;
41
+ }
42
+ if ( difference . size == 0 ) {
43
+ // All the current refs are stored
44
+ element . checked = true ;
45
+ } else if ( difference . size == currentRefsSet . size ) {
46
+ // None of the current refs are stored
47
+ element . checked = false ;
48
+ } else {
49
+ // Some of the refs are stored
50
+ element . checked = false ;
51
+ element . indeterminate = true ;
52
+ }
53
+ }
54
+
55
+ function createCheckboxChangeHandler ( checkbox , references ) {
56
+ return function ( ) {
57
+ refsSet = getStoredCheckboxRefs ( checkbox ) ;
58
+ if ( this . checked ) {
59
+ // checkbox ticked
60
+ for ( ref of references ) {
61
+ refsSet . add ( ref ) ;
62
+ }
63
+ } else {
64
+ // checkbox unticked
65
+ for ( ref of references ) {
66
+ refsSet . delete ( ref ) ;
67
+ }
68
+ }
69
+ writeStorage ( "checkbox_" + checkbox , [ ...refsSet ] . join ( "," ) ) ;
70
+ }
71
+ }
72
+
24
73
function createRowMouseEnterHandler ( refs ) {
25
74
return function ( ) {
26
75
highlightedRefs = refs ;
@@ -78,14 +127,7 @@ function highlightFilter(s) {
78
127
return r ;
79
128
}
80
129
81
- function populateBomTable ( ) {
82
- while ( bom . firstChild ) {
83
- bom . removeChild ( bom . firstChild ) ;
84
- }
85
- while ( bomhead . firstChild ) {
86
- bomhead . removeChild ( bomhead . firstChild ) ;
87
- }
88
- // Populate header
130
+ function populateBomHeader ( ) {
89
131
var tr = document . createElement ( "TR" ) ;
90
132
var td = document . createElement ( "TH" ) ;
91
133
td . classList . add ( "numCol" ) ;
@@ -116,7 +158,9 @@ function populateBomTable() {
116
158
td . innerHTML = "Quantity" ;
117
159
tr . appendChild ( td ) ;
118
160
bomhead . appendChild ( tr ) ;
119
- // Populate table body
161
+ }
162
+
163
+ function populateBomBody ( ) {
120
164
var first = true ;
121
165
switch ( canvaslayout ) {
122
166
case 'F' :
@@ -153,6 +197,8 @@ function populateBomTable() {
153
197
td = document . createElement ( "TD" ) ;
154
198
input = document . createElement ( "input" ) ;
155
199
input . type = "checkbox" ;
200
+ input . onchange = createCheckboxChangeHandler ( checkbox , references ) ;
201
+ setBomCheckboxState ( checkbox , input , references ) ;
156
202
td . appendChild ( input ) ;
157
203
tr . appendChild ( td ) ;
158
204
}
@@ -183,6 +229,17 @@ function populateBomTable() {
183
229
}
184
230
}
185
231
232
+ function populateBomTable ( ) {
233
+ while ( bom . firstChild ) {
234
+ bom . removeChild ( bom . firstChild ) ;
235
+ }
236
+ while ( bomhead . firstChild ) {
237
+ bomhead . removeChild ( bomhead . firstChild ) ;
238
+ }
239
+ populateBomHeader ( ) ;
240
+ populateBomBody ( ) ;
241
+ }
242
+
186
243
function updateFilter ( input ) {
187
244
filter = input . toLowerCase ( ) ;
188
245
populateBomTable ( ) ;
0 commit comments