simple_form-polymorphic_associations 0.0.3 → 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: 0beb264dc98808fcc7bfa4a1ab6ec2bc5219663398877f1487731cf9059ee31b
4
- data.tar.gz: 86032e0623b65c0a3dd998cc7b5c6b84fc062fba9337139820bf3b85e524f8a6
3
+ metadata.gz: '0886162b184227281cbda58946bcaebe1b4c9414d4b63f8f27457e786714a293'
4
+ data.tar.gz: 6498888d3b5c2e4cb0706731a34d395f4523cb675a702258b41fbb5138bdd430
5
5
  SHA512:
6
- metadata.gz: '01261180fcd1e963563626f04bf25e4018e2b0d42b0a5474f827c37bed3f3e96a0959be69951094aaefa17423f71852fe1e8dbb066722124cb5e7ad76841aae0'
7
- data.tar.gz: e25ca8e8f9a4631fee36fb20fdc9816096ee7b3a67b9fd13e038694a1bd82a442d41980248bb88325011391b9901e87748a730d551d6a4f6d67bfc170b5b782f
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
@@ -30,7 +30,7 @@ module SimpleFormPolymorphicAssociations
30
30
  def polymorphic_select(record, label_method, options)
31
31
  select record.class.model_name.human, from: options[:from].gsub(/_id]$/, "_type]")
32
32
  first(".select2-container", minimum: 1).click
33
- find(".select2-search--dropdown input.select2-search__field").send_keys(user.send(label_method))
33
+ find(".select2-search--dropdown input.select2-search__field").send_keys(record.send(label_method))
34
34
  sleep(1)
35
35
  find(".select2-search--dropdown input.select2-search__field").send_keys(:enter)
36
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleFormPolymorphicAssociations
4
- VERSION = "0.0.3"
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.3
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-13 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
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.3.26
66
+ rubygems_version: 3.4.21
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Simple Form polymorphic associations.