activeadmin_select_many 0.1.0
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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +54 -0
- data/Rakefile +3 -0
- data/activeadmin_select_many.gemspec +19 -0
- data/app/assets/javascripts/activeadmin/select_many.js +72 -0
- data/app/assets/stylesheets/activeadmin/_select_many.sass +13 -0
- data/config/locales/en.yml +5 -0
- data/lib/activeadmin/select_many/engine.rb +13 -0
- data/lib/activeadmin/select_many/version.rb +5 -0
- data/lib/activeadmin/select_many.rb +1 -0
- data/lib/activeadmin_select_many.rb +3 -0
- data/lib/formtastic/inputs/select_many_input.rb +66 -0
- data/screenshot.png +0 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b9189e230febfc9cfdbc1088a2638db3417c06d5
|
4
|
+
data.tar.gz: a48dfe85a5f14c48c42e71bc7666cc4624aef51a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdcb42047d735858663d7deac41e3af1520a3ae2a08dffbb4395a2fe72590a4a21df8b6fea36b3436a2aac3058c7810105397bbf404bfae580f5be0491e9baca
|
7
|
+
data.tar.gz: 591ea68f17f0ef69cd3dfbb151f296f75724d77e934995e5059953eb6b13007aa91b5b3d9817981cb8aa5a18aae90f2b978443ee300b35e6a0185e5839fef23b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2017 Mattia Roccoberton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# ActiveAdmin Select Many [](https://badge.fury.io/rb/activeadmin_select_many)
|
2
|
+
|
3
|
+
An Active Admin plugin which improves one-to-many and many-to-many associations selection (jQuery required).
|
4
|
+
|
5
|
+
Features:
|
6
|
+
- search box
|
7
|
+
- select on the left with available items
|
8
|
+
- select on the right with selected items
|
9
|
+
- local/remote collections
|
10
|
+
- double click to add/remove items
|
11
|
+
|
12
|
+

|
13
|
+
|
14
|
+
## Install
|
15
|
+
|
16
|
+
- Add to your Gemfile:
|
17
|
+
`gem 'activeadmin_select_many'`
|
18
|
+
- Execute bundle
|
19
|
+
- Add at the end of your ActiveAdmin styles (_app/assets/stylesheets/active_admin.scss_):
|
20
|
+
`@import 'activeadmin/select_many';`
|
21
|
+
- Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
|
22
|
+
`//= require activeadmin/select_many`
|
23
|
+
- Use the input with `as: :select_many` in Active Admin model conf
|
24
|
+
|
25
|
+
## Examples
|
26
|
+
|
27
|
+
Add to ActiveAdmin model config, in *form* block.
|
28
|
+
|
29
|
+
- Local collection (no AJAX calls):
|
30
|
+
`f.input :sections, as: :select_many`
|
31
|
+
- Remote collection (using AJAX):
|
32
|
+
`f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json )`
|
33
|
+
- Changing search param and text key:
|
34
|
+
`f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json ), search_param: 'category_contains', text_key: 'category', placeholder: 'Type something...'`
|
35
|
+
|
36
|
+
## Options
|
37
|
+
|
38
|
+
- **collection**: local collection
|
39
|
+
- **placeholder**: placeholder string for search box
|
40
|
+
- **remote_collection**: JSON path
|
41
|
+
- **search_param**: parameter to use as search key (ransack style)
|
42
|
+
- **text_key**: key to use as text for select options
|
43
|
+
|
44
|
+
## Do you like it? Star it!
|
45
|
+
|
46
|
+
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
|
47
|
+
|
48
|
+
## Contributors
|
49
|
+
|
50
|
+
- [Mattia Roccoberton](http://blocknot.es) - creator, maintainer
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
[MIT](LICENSE.txt)
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'activeadmin/select_many/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'activeadmin_select_many'
|
7
|
+
spec.version = ActiveAdmin::SelectMany::VERSION
|
8
|
+
spec.summary = 'SelectMany plugin for ActiveAdmin'
|
9
|
+
spec.description = 'An Active Admin plugin which improves one-to-many and many-to-many associations selection (jQuery required)'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
spec.authors = ['Mattia Roccoberton']
|
12
|
+
spec.email = 'mat@blocknot.es'
|
13
|
+
spec.homepage = 'https://github.com/blocknotes/activeadmin_select_many'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_runtime_dependency 'activeadmin', '~> 1.0'
|
19
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
function debounce( func, wait, immediate ) {
|
2
|
+
var timeout;
|
3
|
+
return function() {
|
4
|
+
var context = this, args = arguments;
|
5
|
+
var later = function() {
|
6
|
+
timeout = null;
|
7
|
+
if (!immediate) func.apply(context, args);
|
8
|
+
};
|
9
|
+
var callNow = immediate && !timeout;
|
10
|
+
clearTimeout(timeout);
|
11
|
+
timeout = setTimeout(later, wait);
|
12
|
+
if (callNow) func.apply(context, args);
|
13
|
+
};
|
14
|
+
};
|
15
|
+
|
16
|
+
$(document).ready( function() {
|
17
|
+
$('.select_many.input select').on( 'dblclick', function( event ) {
|
18
|
+
if( event.target.tagName.toLowerCase() == 'option' ) {
|
19
|
+
var parent = $(this).closest( '.select_many' );
|
20
|
+
var opt = $(event.target);
|
21
|
+
var dst = parent.find( $(this).data( 'select' ) == 'src' ? '[data-select="dst"]' : '[data-select="src"]' );
|
22
|
+
dst.append( $('<option>', { value: opt.val(), text: opt.text() }) );
|
23
|
+
opt.remove();
|
24
|
+
// Update values list
|
25
|
+
var values = parent.find( '.values' );
|
26
|
+
values.empty();
|
27
|
+
parent.find( '[data-select="dst"] option' ).each( function() {
|
28
|
+
values.append( $('<input>', { type: 'hidden', name: values.data( 'name' ), value: $(this).val() }) );
|
29
|
+
});
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
var onLocalSelect = debounce( function() {
|
34
|
+
var search = $(this).val().toLowerCase();
|
35
|
+
$(this).closest( '.select_many' ).find( '[data-select="src"] option' ).each( function() {
|
36
|
+
$(this).toggle( $(this).text().toLowerCase().indexOf( search ) >= 0 );
|
37
|
+
});
|
38
|
+
}, 250 );
|
39
|
+
var onRemoteSelect = debounce( function() {
|
40
|
+
var search = $(this).val().trim();
|
41
|
+
if( search != '' && $(this).data( 'searching' ) != '1' ) {
|
42
|
+
$(this).data( 'searching', '1' );
|
43
|
+
var _this = $(this);
|
44
|
+
var data = {}
|
45
|
+
var text_key = $(this).data('text');
|
46
|
+
var value_key = $(this).data('value');
|
47
|
+
data['q['+$(this).data('search')+']'] = search;
|
48
|
+
$.ajax({
|
49
|
+
context: _this,
|
50
|
+
data: data,
|
51
|
+
url: $(this).data( 'remote' ),
|
52
|
+
complete: function( req, status ) {
|
53
|
+
$(this).data( 'searching', '' );
|
54
|
+
},
|
55
|
+
success: function( data, status, req ) {
|
56
|
+
// TODO: limit... 100 ?
|
57
|
+
var select = $(this).closest( '.select_many' ).find( '[data-select="src"]' );
|
58
|
+
select.empty();
|
59
|
+
data.forEach( function( item ) {
|
60
|
+
select.append( $('<option>', { value: item[value_key], text: item[text_key] }) );
|
61
|
+
});
|
62
|
+
},
|
63
|
+
});
|
64
|
+
}
|
65
|
+
}, 400 );
|
66
|
+
|
67
|
+
// $('.select_many.input .search-select').on( 'keyup', onKeyup );
|
68
|
+
|
69
|
+
$('.select_many.input .search-select').each( function() {
|
70
|
+
$(this).on( 'keyup', $(this).data( 'remote' ) ? onRemoteSelect : onLocalSelect );
|
71
|
+
});
|
72
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_admin'
|
2
|
+
|
3
|
+
module ActiveAdmin
|
4
|
+
module SelectMany
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
engine_name 'activeadmin_select_many'
|
7
|
+
|
8
|
+
# config.before_initialize do
|
9
|
+
# config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
|
10
|
+
# end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'activeadmin/select_many/engine'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
class SelectManyInput < SelectInput
|
4
|
+
# def input_html_options
|
5
|
+
# super.merge( class: 'select-many' )
|
6
|
+
# end
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
input_wrapping do
|
10
|
+
label_html <<
|
11
|
+
hidden_input <<
|
12
|
+
template.content_tag( :div, class: 'selects' ) do
|
13
|
+
search_box +
|
14
|
+
template.content_tag( :span, '' ) +
|
15
|
+
template.content_tag( :span, template.t( 'inputs.select_many.available' ) + ':' ) +
|
16
|
+
template.content_tag( :span, template.t( 'inputs.select_many.selected' ) + ':' ) +
|
17
|
+
select_src_html +
|
18
|
+
select_dst_html
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def hidden_input
|
24
|
+
template.content_tag( :div, class: 'values', 'data-name': input_html_options[:name] ) do
|
25
|
+
object.send( input_name ).each do |value|
|
26
|
+
template.concat template.hidden_field_tag( input_html_options[:name], value, {id: nil} )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_box
|
32
|
+
@opts ||= {id: nil, class: 'search-select', placeholder: options[:placeholder], 'data-remote': options[:remote_collection], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:text_key] ? options[:text_key] : 'name', 'data-value': options[:value_key] ? options[:value_key] : 'id'}
|
33
|
+
template.text_field_tag( nil, '', @opts )
|
34
|
+
end
|
35
|
+
|
36
|
+
def select_src_html
|
37
|
+
coll = if options[:remote_collection]
|
38
|
+
[]
|
39
|
+
else
|
40
|
+
# TODO: add option unique ?
|
41
|
+
selected = object.send( input_name )
|
42
|
+
collection.select { |option| !selected.include?( option[1] ) }
|
43
|
+
end
|
44
|
+
opts = input_options.dup.merge( name: nil, id: nil, multiple: true, 'data-select': 'src' )
|
45
|
+
template.select_tag nil, template.options_for_select( coll ), opts
|
46
|
+
end
|
47
|
+
|
48
|
+
def select_dst_html
|
49
|
+
selected = object.send( input_name )
|
50
|
+
coll = collection.select { |option| selected.include?( option[1] ) }
|
51
|
+
opts = input_options.dup.merge( name: nil, id: nil, multiple: true, 'data-select': 'dst' )
|
52
|
+
template.select_tag nil, template.options_for_select( coll ), opts
|
53
|
+
end
|
54
|
+
|
55
|
+
# def select_html
|
56
|
+
# selected = object.send( input_name )
|
57
|
+
# coll = collection.select { |option| selected.include?( option[1] ) }
|
58
|
+
|
59
|
+
# opts = input_options.dup.merge( name: nil, id: nil, multiple: true )
|
60
|
+
# template.select_tag nil, template.options_for_select( coll ), opts
|
61
|
+
|
62
|
+
# # builder.select(input_name, coll, input_options, input_html_options)
|
63
|
+
# end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/screenshot.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeadmin_select_many
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mattia Roccoberton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeadmin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: An Active Admin plugin which improves one-to-many and many-to-many associations
|
28
|
+
selection (jQuery required)
|
29
|
+
email: mat@blocknot.es
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- activeadmin_select_many.gemspec
|
40
|
+
- app/assets/javascripts/activeadmin/select_many.js
|
41
|
+
- app/assets/stylesheets/activeadmin/_select_many.sass
|
42
|
+
- config/locales/en.yml
|
43
|
+
- lib/activeadmin/select_many.rb
|
44
|
+
- lib/activeadmin/select_many/engine.rb
|
45
|
+
- lib/activeadmin/select_many/version.rb
|
46
|
+
- lib/activeadmin_select_many.rb
|
47
|
+
- lib/formtastic/inputs/select_many_input.rb
|
48
|
+
- screenshot.png
|
49
|
+
homepage: https://github.com/blocknotes/activeadmin_select_many
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.6.13
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: SelectMany plugin for ActiveAdmin
|
73
|
+
test_files: []
|