active_admin_auto_select 0.1.8 → 0.1.9

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
  SHA1:
3
- metadata.gz: f65f484028ebffcea2a78c959958181aceb6ee9c
4
- data.tar.gz: 20c01a150d126ce73255890707d373c22195e944
3
+ metadata.gz: eb807c9098ae35252ffa0c72703a0c102a0a091c
4
+ data.tar.gz: 5423078c35c2e10a45f9ef6638c5a6756b4d0479
5
5
  SHA512:
6
- metadata.gz: 3dd6ab5ee513510768cd3597aaf2023be8dc8d9045e66873019185b2e3435e7eb1496c25f718e867900671eb8ff6f91babffd06ab6812eff761832b794512353
7
- data.tar.gz: 0981a825913afa8866fcd9c5b206a758b93b25d0543a78798f41925daf94a6bcfc4d5f06f2070da04f0203431081565e48ce2687a23f7d030d48aceea4a360ad
6
+ metadata.gz: 3b97ef4ca1f7761563faa8b26b3e8ee44ad5aebba46bf569cc75da0c284bdb0274a681ef98e6d76c97b4b3fbcc266cc4b842fe0ba85eca84bc394460b5291428
7
+ data.tar.gz: ce1754441997f2589e1d3ab4ad2b486fa0834cc6b8fffe01408c35f590250906481d1e3566425f374f54416c83a6c9446b7c769c4fa3819d1b69252d7de2547f
@@ -54,11 +54,12 @@ AutoSelect = (function() {
54
54
  })(this),
55
55
  initSelection: (function(_this) {
56
56
  return function(e, callback) {
57
- var id;
58
- id = $(e).val();
59
- if (id !== "") {
57
+ var value, ids;
58
+ value = $(e).val();
59
+ ids = value.split(' ');
60
+ if (value !== "") {
60
61
  return $.getJSON(url, {
61
- id: id
62
+ ids: ids
62
63
  }).done(function(data) {
63
64
  callback(data);
64
65
  return _this.$input.trigger("autocomplete:ajax:success", data);
@@ -11,7 +11,7 @@ module AutoSelectable
11
11
  collection_action :autoselect, :method => :get do
12
12
  select_fields = "#{resource.table_name}.id, " << fields.join(', ')
13
13
  if (Module.const_get(:CanCanCan) rescue false) ? authorized?(:read, resource) :true
14
- term = ([ params[:id], params[:q]].compact).try(:first)
14
+ term = params[:q].to_s
15
15
  term.gsub!('%', '\\\%')
16
16
  term.gsub!('_', '\\\_')
17
17
  first_term = term.try(:match, /\w \w/) ? (term.split(' '))[0] : term
@@ -23,11 +23,12 @@ module AutoSelectable
23
23
  effective_scope = options[params[:scope]] || options['default_scope'] || ->{ resource }
24
24
 
25
25
  #This param exists when we have a filtered result
26
- if params[:id]
27
- first_resource = effective_scope.call.
28
- where("#{resource.table_name}.id = ?", params[:id].to_i).
29
- select(select_fields).first
30
- render json: first_resource and return
26
+ if params[:ids].present?
27
+ resources = effective_scope.call.
28
+ where("#{resource.table_name}.id IN (?)", params[:ids]).
29
+ select(select_fields)
30
+ resources = resources.first if resources.size == 1
31
+ render json: resources and return
31
32
  else
32
33
  concat_fields = fields.join(" || ' '::text || ")
33
34
  concat_cols = "((#{concat_fields})" << " || ' '::text || #{resource.table_name}.id::text)"
@@ -1,3 +1,3 @@
1
1
  module AdminAutoSelect
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_auto_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - spyrbri