@@ -80,7 +80,7 @@ function getStoredCheckboxRefs(checkbox) {
8080 }
8181}
8282
83- function setBomCheckboxState ( checkbox , element , references ) {
83+ function getCheckboxState ( checkbox , references ) {
8484 var storedRefsSet = getStoredCheckboxRefs ( checkbox ) ;
8585 var currentRefsSet = new Set ( references ) ;
8686 // Get difference of current - stored
@@ -90,17 +90,22 @@ function setBomCheckboxState(checkbox, element, references) {
9090 }
9191 if ( difference . size == 0 ) {
9292 // All the current refs are stored
93- element . checked = true ;
93+ return "checked" ;
9494 } else if ( difference . size == currentRefsSet . size ) {
9595 // None of the current refs are stored
96- element . checked = false ;
96+ return "unchecked" ;
9797 } else {
9898 // Some of the refs are stored
99- element . checked = false ;
100- element . indeterminate = true ;
99+ return "indeterminate" ;
101100 }
102101}
103102
103+ function setBomCheckboxState ( checkbox , element , references ) {
104+ var state = getCheckboxState ( checkbox , references ) ;
105+ element . checked = ( state == "checked" ) ;
106+ element . indeterminate = ( state == "indeterminate" ) ;
107+ }
108+
104109function createCheckboxChangeHandler ( checkbox , references ) {
105110 return function ( ) {
106111 refsSet = getStoredCheckboxRefs ( checkbox ) ;
@@ -241,14 +246,19 @@ function populateBomHeader() {
241246 td . classList . add ( "numCol" ) ;
242247 tr . appendChild ( td ) ;
243248 checkboxes = bomCheckboxes . split ( "," ) . filter ( ( e ) => e ) ;
244- for ( var checkbox of checkboxes ) {
245- if ( checkbox ) {
246- td = document . createElement ( "TH" ) ;
247- td . classList . add ( "bom-checkbox" ) ;
248- td . innerHTML = checkbox ;
249- tr . appendChild ( td ) ;
249+ var checkboxClosure = function ( checkbox ) {
250+ return ( a , b ) => {
251+ var stateA = getCheckboxState ( checkbox , a [ 3 ] ) ;
252+ var stateB = getCheckboxState ( checkbox , b [ 3 ] ) ;
253+ if ( stateA > stateB ) return - 1 ;
254+ if ( stateA < stateB ) return 1 ;
255+ return 0 ;
250256 }
251257 }
258+ for ( var checkbox of checkboxes ) {
259+ tr . appendChild ( createColumnHeader (
260+ checkbox , "bom-checkbox" , checkboxClosure ( checkbox ) ) ) ;
261+ }
252262 tr . appendChild ( createColumnHeader ( "References" , "References" , ( a , b ) => {
253263 var i = 0 ;
254264 while ( i < a [ 3 ] . length && i < b [ 3 ] . length ) {
0 commit comments