rails_admin_select2 0.0.1.pre
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.
- data/MIT-LICENSE +20 -0
- data/Rakefile +21 -0
- data/app/views/rails_admin/main/_form_select2.html.erb +4 -0
- data/lib/rails_admin_select2/engine.rb +4 -0
- data/lib/rails_admin_select2/version.rb +7 -0
- data/lib/rails_admin_select2.rb +44 -0
- metadata +84 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsAdminSelect2'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<%= form.select(field.method_name, field.collection, { :include_blank => true }, { :class => 'select2', :style => 'width:75%', :multiple => field.multiple? }) %>
|
2
|
+
<script type="text/javascript">
|
3
|
+
$(<%= "#{field.abstract_model.to_s.underscore}_#{field.method_name}" %>).select2();
|
4
|
+
</script>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rails_admin_select2/engine'
|
2
|
+
|
3
|
+
module RailsAdminSelect2
|
4
|
+
end
|
5
|
+
|
6
|
+
module RailsAdmin
|
7
|
+
module Config
|
8
|
+
module Fields
|
9
|
+
module Types
|
10
|
+
# Add support for select2 input fields to RailsAdmin.
|
11
|
+
class Select2 < RailsAdmin::Config::Fields::Base
|
12
|
+
RailsAdmin::Config::Fields::Types::register(self)
|
13
|
+
def initialize(parent, name, properties)
|
14
|
+
super(parent, name, properties)
|
15
|
+
@meta = abstract_model.model.reflect_on_association(name)
|
16
|
+
if not [:belongs_to, :has_one, :has_many, :has_and_belongs_to_many].include? @meta.macro
|
17
|
+
raise RuntimeError.new('Cannot render select2 for association %s#%s of type %s.' % [@meta.class_name, @meta.name, @meta.macro])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
register_instance_option(:partial) do
|
21
|
+
:form_select2
|
22
|
+
end
|
23
|
+
register_instance_option(:multiple?) do
|
24
|
+
[:has_many, :has_and_belongs_to_many].include? @meta.macro
|
25
|
+
end
|
26
|
+
register_instance_option(:collection) do
|
27
|
+
@meta.class_name.safe_constantize.all.map{ |object| [ object.name, object.id ] }
|
28
|
+
end
|
29
|
+
# For Mongoid, the method_name required is <name>_id[s],
|
30
|
+
# e.g. children_ids or parent_id.
|
31
|
+
#
|
32
|
+
# To construct method_name, start with the association name and
|
33
|
+
# append '_id' or '_ids' for :belongs_to and all other types
|
34
|
+
# of associations, respectively.
|
35
|
+
#
|
36
|
+
# TODO Does this work in AR, too?
|
37
|
+
def method_name
|
38
|
+
'%s_%s' % [ @meta.name.to_s.singularize, multiple? ? 'ids' : 'id' ]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_select2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Gassner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails_admin
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: select2-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A custom field providing select2 support for rails_admin.
|
47
|
+
email:
|
48
|
+
- sebastian.gassner@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- app/views/rails_admin/main/_form_select2.html.erb
|
54
|
+
- lib/rails_admin_select2/version.rb
|
55
|
+
- lib/rails_admin_select2/engine.rb
|
56
|
+
- lib/rails_admin_select2.rb
|
57
|
+
- MIT-LICENSE
|
58
|
+
- Rakefile
|
59
|
+
homepage:
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>'
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.1
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.23
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Select2 for rails_admin
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|