11< script >
2- $ ( document ) . ready ( function ( ) {
3- let add_to_btn = $ ( '# add-to-btn') ;
4- let add_to_btn_wrapper = add_to_btn . parent ( ) ;
2+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
3+ let add_to_btn = document . getElementById ( ' add-to-btn') ;
4+ let add_to_btn_wrapper = add_to_btn . parentElement ;
55
66 let handle_button_display = function ( ) {
7- let count = $ ( 'main input[type="checkbox"]:checked' ) . length ;
8- if ( count >= 1 ) {
9- add_to_btn . removeClass ( 'disabled' ) ;
10- add_to_btn_wrapper . attr ( 'data-bs-original-title' , '' ) ;
11- }
12- else {
13- add_to_btn . addClass ( 'disabled' ) ;
14- add_to_btn_wrapper . attr ( 'data-bs-original-title' , 'Select objects first' ) ;
15- }
7+ let checkedCheckboxes = document . querySelectorAll ( 'main input[type="checkbox"]:checked' ) ;
8+ if ( checkedCheckboxes . length >= 1 ) {
9+ add_to_btn . classList . remove ( 'disabled' ) ;
10+ add_to_btn_wrapper . setAttribute ( 'data-bs-original-title' , '' ) ;
11+ } else {
12+ add_to_btn . classList . add ( 'disabled' ) ;
13+ add_to_btn_wrapper . setAttribute ( 'data-bs-original-title' , 'Select objects first' ) ;
14+ }
1615 } ;
1716
18- $ ( 'main input[type="checkbox"]' ) . on ( 'change' , function ( ) {
19- handle_button_display ( ) ;
17+ // Adding change event listener to all checkboxes
18+ document . querySelectorAll ( 'main input[type="checkbox"]' ) . forEach ( function ( checkbox ) {
19+ checkbox . addEventListener ( 'change' , handle_button_display ) ;
2020 } ) ;
2121
22- // Runs on load to support the "back" button of the browser
22+ // Initial call to handle_button_display to set the correct state on page load
2323 handle_button_display ( ) ;
2424
25+ // Call handle_button_display when the page is shown (e.g., when navigating back)
26+ window . addEventListener ( 'pageshow' , function ( ) {
27+ handle_button_display ( ) ;
28+ } ) ;
29+
2530 $ ( '#add-to-product-modal, #add-to-component-modal' ) . on ( 'show.bs.modal' , function ( event ) {
26- let checked = $ ( 'main input[type="checkbox"]:checked' ) ;
31+ // Do not include the select-all as its value is not an id we want to keep
32+ let checked = $ ( 'main input[type="checkbox"]:checked' ) . not ( '#checkbox-select-all' ) ;
2733
2834 if ( checked . length < 1 ) {
2935 event . preventDefault ( ) ;
5258 }
5359 } ) ;
5460
61+ // Select all forms with id starting with "add-to-"
62+ const forms = document . querySelectorAll ( 'form[id^="add-to-"]' ) ;
63+ forms . forEach ( function ( form ) {
64+ form . addEventListener ( 'submit' , function ( ) {
65+ NEXB . displayOverlay ( "Adding objects..." ) ;
66+ } ) ;
67+ } ) ;
68+
5569 } ) ;
56- </ script >
70+ </ script >
0 commit comments