activeadmin_select_many 0.2.6 → 0.2.8
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: 3a289f4b6418d0af92538f32caed2af60a8149d6
|
4
|
+
data.tar.gz: 37deed25511b1de438cae523b52a0f4c627d2d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7774b3c4765e20abf7a18379a86f7faf0482c771fac313320bacb555e4a69c440c765da602c1ead8d93952e68a2acfc98d4ec0d626c22cc53f851f55d2242c9
|
7
|
+
data.tar.gz: f7c76a2763f1a7977ea28e17eafbf1f7dde25a784f715d399f2f7b550f370573dd54161de5326e6e0c21ecd11660e6197f06cf3a90b79080ec4406583e42fc22
|
@@ -32,6 +32,7 @@ function smUpdateValues( parent ) {
|
|
32
32
|
cnt++;
|
33
33
|
});
|
34
34
|
if( cnt == 0 ) values.append( $('<input>', { type: 'hidden', name: values.data( 'name' ) }) );
|
35
|
+
parent.find( '.selected span' ).text( ' [' + cnt + ']' );
|
35
36
|
}
|
36
37
|
|
37
38
|
$(document).ready( function() {
|
@@ -40,10 +41,13 @@ $(document).ready( function() {
|
|
40
41
|
});
|
41
42
|
|
42
43
|
var onLocalSelect = smDebounce( function() {
|
43
|
-
var search = $(this).val().toLowerCase();
|
44
|
+
var cnt = 0, search = $(this).val().toLowerCase();
|
44
45
|
$(this).closest( '.select_many' ).find( '[data-select="src"] option' ).each( function() {
|
45
|
-
|
46
|
+
var found = $(this).text().toLowerCase().indexOf( search ) >= 0;
|
47
|
+
$(this).toggle( found );
|
48
|
+
if( found ) cnt++;
|
46
49
|
});
|
50
|
+
$(this).parent().find( '.available span' ).text( ' [' + cnt + ']' );
|
47
51
|
}, 250 );
|
48
52
|
var onRemoteSelect = smDebounce( function() {
|
49
53
|
var search = $(this).val().trim();
|
@@ -53,6 +57,7 @@ $(document).ready( function() {
|
|
53
57
|
var data = {}
|
54
58
|
var text_key = $(this).data('text');
|
55
59
|
var value_key = $(this).data('value');
|
60
|
+
var counter_limit = $(this).data('counter-limit') ? Number( $(this).data('counter-limit') ) : 0;
|
56
61
|
data['q['+$(this).data('search')+']'] = search;
|
57
62
|
$.ajax({
|
58
63
|
context: _this,
|
@@ -62,18 +67,21 @@ $(document).ready( function() {
|
|
62
67
|
$(this).data( 'searching', '' );
|
63
68
|
},
|
64
69
|
success: function( data, status, req ) {
|
65
|
-
// TODO: limit... 100 ?
|
66
70
|
var select = $(this).closest( '.select_many' ).find( '[data-select="src"]' );
|
67
71
|
select.empty();
|
68
72
|
data.forEach( function( item ) {
|
69
73
|
select.append( $('<option>', { value: item[value_key], text: item[text_key] }) );
|
70
74
|
});
|
75
|
+
$(this).parent().find( '.available span' ).text( ' [' + ( ( counter_limit > 0 && data.length >= counter_limit ) ? ( counter_limit + '+' ) : data.length ) + ']' );
|
71
76
|
},
|
72
77
|
});
|
73
78
|
}
|
74
79
|
}, 400 );
|
75
80
|
|
76
81
|
$('.select_many.input .search-select').each( function() {
|
82
|
+
var parent = $(this).parent();
|
83
|
+
parent.find( '.available' ).append( '<span> [' + parent.find( '[data-select="src"] option' ).length + ']</span>' );
|
84
|
+
parent.find( '.selected' ).append( '<span> [' + parent.find( '[data-select="dst"] option' ).length + ']</span>' );
|
77
85
|
$(this).on( 'keyup', $(this).data( 'remote-collection' ) ? onRemoteSelect : onLocalSelect );
|
78
86
|
});
|
79
87
|
$('.select_many .add').on( 'click', function() {
|
@@ -126,7 +134,7 @@ $(document).ready( function() {
|
|
126
134
|
data.forEach( function( item ) {
|
127
135
|
sel.append( $('<option>', { value: item[value_key], text: item[text_key] }) );
|
128
136
|
});
|
129
|
-
sel.parent().find( '.status' ).text( '[' +
|
137
|
+
sel.parent().find( '.status' ).text( '[' + ( ( counter_limit > 0 && data.length >= counter_limit ) ? ( counter_limit + '+' ) : data.length ) + ']' );
|
130
138
|
},
|
131
139
|
});
|
132
140
|
}
|
@@ -40,7 +40,7 @@ module Formtastic
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def search_box_html
|
43
|
-
@opts ||= {id: nil, class: 'search-select', placeholder: options.delete( :placeholder ), 'data-remote-collection': options[:'data-remote-collection'], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:member_label] ? options[:member_label] : ( options[:text_key] ? options[:text_key] : 'name' ), 'data-value': options[:value_key] ? options[:value_key] : 'id'}
|
43
|
+
@opts ||= {id: nil, class: 'search-select', placeholder: options.delete( :placeholder ), 'data-remote-collection': options[:'data-remote-collection'], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:member_label] ? options[:member_label] : ( options[:text_key] ? options[:text_key] : 'name' ), 'data-value': options[:value_key] ? options[:value_key] : 'id', 'data-counter-limit': options[:counter_limit].to_i}
|
44
44
|
template.text_field_tag( nil, '', @opts )
|
45
45
|
end
|
46
46
|
|
@@ -26,7 +26,7 @@ module Formtastic
|
|
26
26
|
|
27
27
|
def search_box
|
28
28
|
# TODO: remove text_key in next major version
|
29
|
-
@opts ||= {id: nil, class: 'search-select', placeholder: options[:placeholder], 'data-remote-collection': options[:remote_collection], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:member_label] ? options[:member_label] : ( options[:text_key] ? options[:text_key] : 'name' ), 'data-value': options[:value_key] ? options[:value_key] : 'id', 'data-msg': options[:msg_items], 'data-counter-limit': options[:counter_limit].to_i
|
29
|
+
@opts ||= {id: nil, class: 'search-select', placeholder: options[:placeholder], 'data-remote-collection': options[:remote_collection], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:member_label] ? options[:member_label] : ( options[:text_key] ? options[:text_key] : 'name' ), 'data-value': options[:value_key] ? options[:value_key] : 'id', 'data-msg': options[:msg_items], 'data-counter-limit': options[:counter_limit].to_i}
|
30
30
|
template.text_field_tag( nil, '', @opts )
|
31
31
|
end
|
32
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_select_many
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|