administrate_batch_actions 0.2.0 → 0.3.1

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: a33ac2550f09f1b8cb9a9bae773380bf14c55d7d5422835a2b170e31c716f983
4
+ data.tar.gz: 3ee144b51a5b9a404421c34a9113395a8975fc2cee971025c89ea6df614b924c
5
5
  SHA512:
6
- metadata.gz: c22b56f02ec93e6812a33acc572853ade75adf090ecf7c2dd00469c279bdeed3f7ba49bd542190647f51b428fbfa78c235e1f5076e00f591b65571fe0f1aac23
7
- data.tar.gz: dcad88ea590e8ca5cf640d8848138c342845d8afe2b968536dd2061636df94582309c64e1d009ee9a2f9533e87b5c97f8f80ddf82e509c0e7878fc60ddf5def7
6
+ metadata.gz: 2385cd89b2487180784f61766d531666d95d5b31f192744a2d35553672477676cb2e03a4872d2d8b58f45f94df2d60084bc3d15ce514cc5cc2d317082e4a30b7
7
+ data.tar.gz: bdf87209596907b29b653c66e18b056b393dce3b3775184f0d4b5f00c4870a52e4ac63bacf055b0d62d3755d07ea832018c03b3f39eac8fc6466941f8083b34f
@@ -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
  <td>
2
- <input type="checkbox" value="<%= value %>" data-batch-action-option="checkbox" />
2
+ <input type="checkbox" value="<%= value %>" name='batch_action_ids[]' data-batch-action-option="checkbox" />
3
3
  </td>
@@ -1,3 +1,3 @@
1
1
  module AdministrateBatchActions
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.1"
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.1
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: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler