active_admin-cep_auto_complete 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a0f2756dbc2714d8688c41be6a780a0ab8e4454
4
- data.tar.gz: bcfb6a341311832bfc04dd1d4048ab8c476207e3
3
+ metadata.gz: b85ab31bbf5b9995a30db2c013bf1982844668dd
4
+ data.tar.gz: b525f8a03d0bfa96061da52b80aa0070f7fa2fbb
5
5
  SHA512:
6
- metadata.gz: ca06d1ce00d2ac9db9dec956e8540bf95d037aebbab9ab8269588b40b50cfa7e6c4657fef0366a8fa9bc0e3295192afc4c9b824eedf4c58d4c39b1837eb03cd6
7
- data.tar.gz: 7b3eebaedb96a34e20a9686e8edb3c721617c03f029705458dbf7dc3d3da15a64c382c98d5027fa8da24192856144598ace43f8350031f384bd9b57d74aa87d1
6
+ metadata.gz: 0d9c36a0dfc45ac45fe27c90adaaba0ef283914440d2d3b05ab7b52e6b782c4c512eb4d4768fac93265243bbb90d44a6d12567613f61b96886e4aee27449f931
7
+ data.tar.gz: 82c95f59a2c394f7f98b34966b345988f273549f6c247c2e5ebd8e95cc35f1c0b4498ca829b120b63a78197d0bb1e2791841cf2e99d001f9e0658e55c1e50626
data/README.md CHANGED
@@ -11,7 +11,7 @@ gem 'active_admin-cep_auto_complete'
11
11
  **1. Create a custom page in `app/admin/cep.rb`**
12
12
  ```ruby
13
13
  ActiveAdmin.register_page 'CEP' do
14
- include ActiveAdmin::CepAutoComplete::Page
14
+ setup_cep_auto_complete
15
15
  end
16
16
  ```
17
17
 
@@ -14,6 +14,7 @@
14
14
  }.bind(this), {});
15
15
  this.cepRegex = new RegExp(this.input.data('cepRegex'));
16
16
  this.onChange = scope.Utils.debounce(this.onChange.bind(this), 300);
17
+ this.lastValue = null;
17
18
  this.lastQuery = null;
18
19
  this.attachEvents();
19
20
  }
@@ -35,8 +36,10 @@
35
36
  },
36
37
 
37
38
  onChange: function(e) {
38
- if (this.isValid(e.delegateTarget.value)) {
39
- this.query(e.delegateTarget.value);
39
+ var value = e.delegateTarget.value;
40
+
41
+ if (this.isValid(value) && this.hasChanged(value)) {
42
+ this.query(value);
40
43
  }
41
44
  },
42
45
 
@@ -44,12 +47,17 @@
44
47
  return !!value.match(this.cepRegex);
45
48
  },
46
49
 
50
+ hasChanged: function(value) {
51
+ return this.lastValue !== value;
52
+ },
53
+
47
54
  query: function(value) {
48
55
  if (this.lastQuery !== null) {
49
56
  this.lastQuery.abort();
50
57
  }
51
58
 
52
59
  this.lockFields();
60
+ this.lastValue = value;
53
61
  this.lastQuery = $.get(this.url, { cep: value })
54
62
  .then(function(data) {
55
63
  this.render(data);
@@ -3,7 +3,7 @@ module ActiveAdmin
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 2
6
- PATCH = 1
6
+ PATCH = 2
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin-cep_auto_complete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dhyego Fernando
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-10 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties