@@ -21,6 +21,55 @@ function dbg(str) {
2121 dbgdiv . textContent = str ;
2222}
2323
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+
2473function createRowMouseEnterHandler ( refs ) {
2574 return function ( ) {
2675 highlightedRefs = refs ;
@@ -78,14 +127,7 @@ function highlightFilter(s) {
78127 return r ;
79128}
80129
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 ( ) {
89131 var tr = document . createElement ( "TR" ) ;
90132 var td = document . createElement ( "TH" ) ;
91133 td . classList . add ( "numCol" ) ;
@@ -116,7 +158,9 @@ function populateBomTable() {
116158 td . innerHTML = "Quantity" ;
117159 tr . appendChild ( td ) ;
118160 bomhead . appendChild ( tr ) ;
119- // Populate table body
161+ }
162+
163+ function populateBomBody ( ) {
120164 var first = true ;
121165 switch ( canvaslayout ) {
122166 case 'F' :
@@ -153,6 +197,8 @@ function populateBomTable() {
153197 td = document . createElement ( "TD" ) ;
154198 input = document . createElement ( "input" ) ;
155199 input . type = "checkbox" ;
200+ input . onchange = createCheckboxChangeHandler ( checkbox , references ) ;
201+ setBomCheckboxState ( checkbox , input , references ) ;
156202 td . appendChild ( input ) ;
157203 tr . appendChild ( td ) ;
158204 }
@@ -183,6 +229,17 @@ function populateBomTable() {
183229 }
184230}
185231
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+
186243function updateFilter ( input ) {
187244 filter = input . toLowerCase ( ) ;
188245 populateBomTable ( ) ;
0 commit comments