active_admin_auto_select 0.1.8 → 0.1.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb807c9098ae35252ffa0c72703a0c102a0a091c
|
4
|
+
data.tar.gz: 5423078c35c2e10a45f9ef6638c5a6756b4d0479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
58
|
-
|
59
|
-
|
57
|
+
var value, ids;
|
58
|
+
value = $(e).val();
|
59
|
+
ids = value.split(' ');
|
60
|
+
if (value !== "") {
|
60
61
|
return $.getJSON(url, {
|
61
|
-
|
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 =
|
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[:
|
27
|
-
|
28
|
-
where("#{resource.table_name}.id
|
29
|
-
select(select_fields)
|
30
|
-
|
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)"
|