administrate_batch_actions 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b8b4f2d80b3683b2ddf3d064389ea6743ea7c812cc90b5c81210f0ab34926ec
4
- data.tar.gz: 2e5844bd5838c30bdbb3ae337cf87d93b8c0b9cf3e4cecaec516611e92995782
3
+ metadata.gz: f7ba01dc33c559c35b0b7a3a1121edc34faacc91ce7083b3d638d285c16880f6
4
+ data.tar.gz: 9b18c836b879efad973cb3e7487cac118307e31a77fc6654a59f82d0e3f97402
5
5
  SHA512:
6
- metadata.gz: c22b56f02ec93e6812a33acc572853ade75adf090ecf7c2dd00469c279bdeed3f7ba49bd542190647f51b428fbfa78c235e1f5076e00f591b65571fe0f1aac23
7
- data.tar.gz: dcad88ea590e8ca5cf640d8848138c342845d8afe2b968536dd2061636df94582309c64e1d009ee9a2f9533e87b5c97f8f80ddf82e509c0e7878fc60ddf5def7
6
+ metadata.gz: 45035d8d3ba5485659aafe52adc564be0c1dc028913332ff5c06db6d47fde3c8b33053fb628abfbbacd883f610b94cdc6bc899ec7a85712ce07b624f67f0422a
7
+ data.tar.gz: 644c56ba9400a37c50d71bea381d86db68bfab7542afdd4612246069b805d32f516b7ff960544d849287378e88f56f2158a52590755d7148ff607fe972efbe2c
@@ -2,22 +2,29 @@ var buttons = document.querySelectorAll("[data-batch-action-option='button']");
2
2
  var checkboxes = document.querySelectorAll("[data-batch-action-option='checkbox']");
3
3
  var selectAllCheckboxes = document.querySelector("[data-batch-action-option='select_all']");
4
4
 
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
+
6
17
  selectAllCheckboxes.addEventListener('click', function(){
7
18
  checkboxes.forEach(function(checkbox) {
8
19
  checkbox.checked = selectAllCheckboxes.checked;
9
20
  });
21
+
22
+ checkAndToggleActionButtons();
10
23
  });
11
24
 
12
25
  buttons.forEach(function(button){
13
26
  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()
21
28
  });
22
29
  });
23
30
 
@@ -28,6 +35,29 @@ if (selectAllCheckboxes) {
28
35
 
29
36
  checkbox.addEventListener('click', function(event) {
30
37
  event.stopImmediatePropagation();
38
+
39
+ checkAndToggleActionButtons();
31
40
  })
32
41
  })
33
42
  }
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
+ }
@@ -1 +1 @@
1
- <%= link_to name, path, class: html_options[:class], data: { batch_action_option: 'button', confirm: html_options[:confirm] }, method: :post %>
1
+ <%= link_to name, path, class: "btn disabled #{html_options[:class]}", data: { batch_action_option: 'button', confirm: html_options[:confirm] }, method: :post %>
@@ -1,3 +1,3 @@
1
1
  module AdministrateBatchActions
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate_batch_actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourcelabs LLC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-22 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler