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: df9c0fdce5dcfbe5a11167c48279203992d73efe
4
- data.tar.gz: 6f6e07b5c3b117f828cc28ff1ffd216ea99c2598
3
+ metadata.gz: 3a289f4b6418d0af92538f32caed2af60a8149d6
4
+ data.tar.gz: 37deed25511b1de438cae523b52a0f4c627d2d4e
5
5
  SHA512:
6
- metadata.gz: b2e87f285a9d022b4e63239b51e1563db27ae778e55cadd55f0cc4700ed7829bc2948a48bbae39051778cbaedb5f3a37bb9c7b42a54d11c08130a7927d1fbdb7
7
- data.tar.gz: ef1b41ed90aba47e1aa8acfd5c2a4e69f94ec98a9d48b76fe799bd2357344d05330ff02a5bb431953bb0782f5901a9677ba734e282e63b2981fa6246ef52c29f
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
- $(this).toggle( $(this).text().toLowerCase().indexOf( search ) >= 0 );
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( '[' + data.length + ( counter_limit > 0 && data.length >= counter_limit ? '+' : '' ) + ']' );
137
+ sel.parent().find( '.status' ).text( '[' + ( ( counter_limit > 0 && data.length >= counter_limit ) ? ( counter_limit + '+' ) : data.length ) + ']' );
130
138
  },
131
139
  });
132
140
  }
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SelectMany
3
- VERSION = '0.2.6'
3
+ VERSION = '0.2.8'
4
4
  end
5
5
  end
@@ -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.6
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-10 00:00:00.000000000 Z
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin