activeadmin_select_many 0.1.2 → 0.1.4

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: 71d37813e5fbcb67285b3c1e8413e4880e79e69d
4
- data.tar.gz: 8cb5b71339e21a10c4e84cc059f0d5ede4e2a220
3
+ metadata.gz: 45fd55dbb9b440057b38aeef68aca5494f89247b
4
+ data.tar.gz: afa5035de499e0997a1fb2e8c81c3b21dd343e07
5
5
  SHA512:
6
- metadata.gz: b8eabd05b1cf8e08453b0e5ae2bf169c11840f61bbc7066787c15725dcc943df14cdaea09e63de3577a8f4efe550f09f31790bdfc94066db862808b035421714
7
- data.tar.gz: a4c4220404ecc844dade9e6b2656c15792315bb1cc2e639a6d4515ad722d27223f45621c4dc69e7baf72876dd7d8103fdfe4f0f2a4ef4593214709c934f4f9f8
6
+ metadata.gz: b71c96131788ee4b9b883ed73186abad17ff7fc85d05b985f674f5561ff1f89681b7395e64636aca366c2f38a9829f639f24b0ba9aa677ff86d35aab278a3c53
7
+ data.tar.gz: 5d9f79c90856223aa9cd45810bc1679a6fde32cc39b8b21b93205f081fe5b38c3a22fcc202a2a29e75f0fc4e2f732ab5c8c94dd4a5caf195e0d4502701eaf24d
@@ -1,3 +1,14 @@
1
+ function smActivate( target ) {
2
+ if( target.tagName.toLowerCase() == 'option' ) {
3
+ var parent = $(this).closest( '.select_many' );
4
+ var opt = $(target);
5
+ var dst = parent.find( $(this).data( 'select' ) == 'src' ? '[data-select="dst"]' : '[data-select="src"]' );
6
+ dst.append( $('<option>', { value: opt.val(), text: opt.text() }) );
7
+ opt.remove();
8
+ smUpdateValues( parent );
9
+ }
10
+ }
11
+
1
12
  function smDebounce( func, wait, immediate ) {
2
13
  var timeout;
3
14
  return function() {
@@ -14,23 +25,18 @@ function smDebounce( func, wait, immediate ) {
14
25
  };
15
26
 
16
27
  function smUpdateValues( parent ) {
17
- var values = parent.find( '.values' );
28
+ var cnt = 0, values = parent.find( '.values' );
18
29
  values.empty();
19
30
  parent.find( '[data-select="dst"] option' ).each( function() {
20
31
  values.append( $('<input>', { type: 'hidden', name: values.data( 'name' ), value: $(this).val() }) );
32
+ cnt++;
21
33
  });
34
+ if( cnt == 0 ) values.append( $('<input>', { type: 'hidden', name: values.data( 'name' ) }) );
22
35
  }
23
36
 
24
37
  $(document).ready( function() {
25
38
  $('.select_many.input select').on( 'dblclick', function( event ) {
26
- if( event.target.tagName.toLowerCase() == 'option' ) {
27
- var parent = $(this).closest( '.select_many' );
28
- var opt = $(event.target);
29
- var dst = parent.find( $(this).data( 'select' ) == 'src' ? '[data-select="dst"]' : '[data-select="src"]' );
30
- dst.append( $('<option>', { value: opt.val(), text: opt.text() }) );
31
- opt.remove();
32
- smUpdateValues( parent );
33
- }
39
+ $.proxy( smActivate, $(this) )( event.target );
34
40
  });
35
41
 
36
42
  var onLocalSelect = smDebounce( function() {
@@ -70,6 +76,16 @@ $(document).ready( function() {
70
76
  $('.select_many.input .search-select').each( function() {
71
77
  $(this).on( 'keyup', $(this).data( 'remote' ) ? onRemoteSelect : onLocalSelect );
72
78
  });
79
+ $('.select_many .add').on( 'click', function() {
80
+ var select = $(this).parent().prev();
81
+ var current = select.find( 'option:selected' )[0];
82
+ if( current ) $.proxy( smActivate, select )( current );
83
+ });
84
+ $('.select_many .remove').on( 'click', function() {
85
+ var select = $(this).parent().next();
86
+ var current = select.find( 'option:selected' )[0];
87
+ if( current ) $.proxy( smActivate, select )( current );
88
+ });
73
89
  $('.select_many [sortable] .move_up').on( 'click', function() {
74
90
  var select = $(this).parent().next();
75
91
  var current = select.find( 'option:selected' )[0];
@@ -5,14 +5,17 @@ body.active_admin
5
5
  text-align: center
6
6
  width: 22px
7
7
  a
8
- background: #ddd
8
+ background: #d4d4d4
9
9
  border: 1px solid #eee
10
+ border-radius: 4px
10
11
  display: block
11
12
  font-weight: bold
12
13
  line-height: 16px
13
14
  text-decoration: none
14
15
  &.move_up, &.move_down
15
16
  display: none
17
+ &:hover
18
+ background: #e0e0e0
16
19
  .search-select
17
20
  margin-bottom: 1px
18
21
  .selects
@@ -23,7 +26,10 @@ body.active_admin
23
26
  width: calc(50% - 12px);
24
27
  > span
25
28
  padding: 3px 6px 1px 6px
29
+ .available
30
+ font-style: italic
26
31
  .selected
32
+ font-style: italic
27
33
  padding-left: 30px
28
34
  [sortable] >.buttons
29
35
  a.move_up, a.move_down
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SelectMany
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -35,8 +35,8 @@ module Formtastic
35
35
 
36
36
  def buttons_html
37
37
  template.content_tag( :div, class: 'buttons' ) do
38
- # template.link_to( '&rarr;'.html_safe, 'Javascript:void(0)', class: 'add' ) +
39
- # template.link_to( '&larr;'.html_safe, 'Javascript:void(0)', class: 'remove' ) +
38
+ template.link_to( '&rarr;'.html_safe, 'Javascript:void(0)', class: 'add' ) +
39
+ template.link_to( '&larr;'.html_safe, 'Javascript:void(0)', class: 'remove' ) +
40
40
  template.link_to( '&uarr;'.html_safe, 'Javascript:void(0)', class: 'move_up' ) +
41
41
  template.link_to( '&darr;'.html_safe, 'Javascript:void(0)', class: 'move_down' )
42
42
  end
data/screenshot.png CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_select_many
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton