simple_form-polymorphic_associations 0.0.4 → 0.0.5

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: a66629243386a0ec87cbebee5cc282a84369ce2c35782c9f250d0e6f3d8b870f
4
- data.tar.gz: f441759360c45c16677e9387c7787676b7986a5cd50f372b9437c57b0867d8f4
3
+ metadata.gz: '0886162b184227281cbda58946bcaebe1b4c9414d4b63f8f27457e786714a293'
4
+ data.tar.gz: 6498888d3b5c2e4cb0706731a34d395f4523cb675a702258b41fbb5138bdd430
5
5
  SHA512:
6
- metadata.gz: c857cd4b2b97e18dc5fcc35308931798ed918de3d2358e72b58cd493474c963c10ace1c28f26bdbcfab97b25e3a50fd108b7114241187557332eb6e54487feaa
7
- data.tar.gz: 179263afafb4328101147694ee8c948b2203fb6cb70ad6b6cd84f36fcec2dba3e70687fd5e7eac05340be2a8a45c9f484c3f694466136643ff00a98690043497
6
+ metadata.gz: d34e50a1cfd8ac921abe43a93667bcba3cd744c2742de5b67675a144f15cfe2a6943b4b9fb64a93ee5ee6ad862323a997b2c9340b6b8d6f6e1536bffc1f47a70
7
+ data.tar.gz: 97932eb80112cb60eb6f98da0a542f09515e3289ee63980ee66e0db5831597095519a0e22f31eebab754eb11221e10b3db2066c0c61ddf98d251e0c669fe95da
@@ -1,7 +1,32 @@
1
- $ ->
2
- $('.polymorphic-association-resource-select').select2 ajax:
3
- url: ->
4
- klass = $(@.siblings('.polymorphic-association-class-select')[0]).val()
5
- $(@).parent().find(".polymorphic-association-autocomplete-link[data-class='#{klass}']").attr('href')
6
- dataType: 'json',
1
+ window.SimpleFormPolymorphicAssociations = window.SimpleFormPolymorphicAssociations ? {}
2
+
3
+ # When dynamically adding a new polymorphic association, we need to rebind the
4
+ # autocomplete to the new select2 element. This is done by calling the constructor
5
+ # on the new element.
6
+ #
7
+ # Example:
8
+ #
9
+ # :javascript
10
+ # var resourceSelect = $("#some-form").find(".polymorphic-association-resource-select")
11
+ # if (window.SimpleFormPolymorphicAssociations) {
12
+ # new window.SimpleFormPolymorphicAssociations.Autocomplete(resourceSelect);
13
+ # } else {
14
+ # console.error('window.SimpleFormPolymorphicAssociations.Autocomplete is not defined');
15
+ # }
16
+ #
17
+ class SimpleFormPolymorphicAssociations.Autocomplete
18
+ constructor: (@element) ->
19
+ @getUrl = @getUrl.bind(this)
20
+ @element.select2 ajax: @getAjaxOptions()
21
+
22
+ getAjaxOptions: ->
23
+ url: @getUrl
24
+ dataType: 'json'
7
25
  delay: 500
26
+
27
+ getUrl: ->
28
+ klass = @element.siblings('.polymorphic-association-class-select').first().val()
29
+ @element.parent().find(".polymorphic-association-autocomplete-link[data-class='#{klass}']").attr('href')
30
+
31
+ $ ->
32
+ new SimpleFormPolymorphicAssociations.Autocomplete($('.polymorphic-association-resource-select'))
@@ -1 +1 @@
1
- //= require simple_form-polymorphic_associations/application
1
+ //= require simple_form-polymorphic_associations/application
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleFormPolymorphicAssociations
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form-polymorphic_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-19 00:00:00.000000000 Z
11
+ date: 2023-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form