@@ -2,22 +2,29 @@ var buttons = document.querySelectorAll("[data-batch-action-option='button']");
22var checkboxes = document . querySelectorAll ( "[data-batch-action-option='checkbox']" ) ;
33var selectAllCheckboxes = document . querySelector ( "[data-batch-action-option='select_all']" ) ;
44
5- if ( selectAllCheckboxes ) {
5+ if ( selectAllCheckboxes && checkboxes && buttons ) {
6+
7+ window . onpageshow = function ( event ) {
8+ if ( selectedItemIds ( ) ) {
9+ checkboxes . forEach ( function ( checkbox ) {
10+ checkbox . checked = false ;
11+ } ) ;
12+
13+ selectAllCheckboxes . checked = false ;
14+ }
15+ } ;
16+
617 selectAllCheckboxes . addEventListener ( 'click' , function ( ) {
718 checkboxes . forEach ( function ( checkbox ) {
819 checkbox . checked = selectAllCheckboxes . checked ;
920 } ) ;
21+
22+ checkAndToggleActionButtons ( ) ;
1023 } ) ;
1124
1225 buttons . forEach ( function ( button ) {
1326 button . addEventListener ( 'click' , function ( event ) {
14- var ids = Array . prototype . filter . call ( checkboxes , function ( checkbox ) {
15- if ( checkbox . checked ) { return checkbox }
16- } ) . map ( function ( checkbox ) {
17- return 'batch_action_ids[]=' + checkbox . value
18- } ) . join ( '&' ) ;
19-
20- button . href += '?' + ids
27+ button . href += '?' + selectedItemIds ( )
2128 } ) ;
2229 } ) ;
2330
@@ -28,6 +35,29 @@ if (selectAllCheckboxes) {
2835
2936 checkbox . addEventListener ( 'click' , function ( event ) {
3037 event . stopImmediatePropagation ( ) ;
38+
39+ checkAndToggleActionButtons ( ) ;
3140 } )
3241 } )
3342}
43+
44+ function selectedItemIds ( ) {
45+ var ids = Array . prototype . filter . call ( checkboxes , function ( checkbox ) {
46+ if ( checkbox . checked ) { return checkbox }
47+ } ) . map ( function ( checkbox ) {
48+ return 'batch_action_ids[]=' + checkbox . value
49+ } ) . join ( '&' ) ;
50+ return ids ;
51+ }
52+
53+ function checkAndToggleActionButtons ( ) {
54+ if ( selectedItemIds ( ) ) {
55+ buttons . forEach ( function ( button ) {
56+ button . classList . remove ( 'disabled' ) ;
57+ } ) ;
58+ } else {
59+ buttons . forEach ( function ( button ) {
60+ button . classList . add ( 'disabled' ) ;
61+ } ) ;
62+ }
63+ }
0 commit comments