├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── activeadmin-select2.gemspec ├── app └── assets │ ├── javascripts │ └── active_admin │ │ ├── select2.js.coffee │ │ └── select2 │ │ └── select2.js.coffee │ └── stylesheets │ └── active_admin │ └── select2 │ ├── _base.scss │ ├── _filter.scss │ └── _form.scss └── lib ├── activeadmin-select2.rb ├── activeadmin ├── inputs │ └── filter_select2_multiple_input.rb ├── select2.rb └── select2 │ ├── engine.rb │ ├── filter_select_input_extension.rb │ └── version.rb └── formtastic └── inputs ├── select2_input.rb ├── select2_multiple_input.rb └── select2_tags_input.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .ruby-version 2 | .ruby-gemset 3 | Gemfile.lock 4 | /pkg/* 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Mark Fariburn, Praxitar Ltd 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. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ActiveAdmin Select2 2 | 3 | ## Description 4 | 5 | Incorporate Select2 JQuery into your ActiveAdmin apps. 6 | 7 | ## Installation 8 | 9 | Add `activeadmin`, `jquery-rails` and `select2-rails` to your Gemfile: 10 | 11 | ```ruby 12 | gem 'activeadmin' 13 | gem 'jquery-rails' 14 | gem 'select2-rails' 15 | ``` 16 | 17 | And add `activeadmin-select2` to your Gemfile: 18 | 19 | ```ruby 20 | gem 'activeadmin-select2', github: 'mfairburn/activeadmin-select2' 21 | ``` 22 | 23 | Add the activeadmin-select2 calls to the active_admin stylesheets and javascripts with: 24 | 25 | ```active_admin.css.scss 26 | @import "active_admin/select2/base"; 27 | ``` 28 | 29 | ```active_admin.js.coffee 30 | #= require active_admin/select2 31 | ``` 32 | 33 | 34 | ## Usage 35 | 36 | ### Filters 37 | 38 | Standard :select filters will automagically be converted to Select2 filters. If you want a multi-select combo-box then use: 39 | 40 | ```ruby 41 | ActiveAdmin.register Products do 42 | 43 | filter :fruits, as: :select2_multiple, collection: [:apples, :bananas, :oranges] 44 | 45 | end 46 | ``` 47 | 48 | ### Select Lists 49 | 50 | To use a Select2 style list simply change from :select to :select2 or :select2_multiple 51 | 52 | ```ruby 53 | ActiveAdmin.register Products do 54 | 55 | form do |f| 56 | f.input :fruit, as: :select2 57 | end 58 | 59 | form do |f| 60 | f.inputs "Product" do 61 | f.has_many :fruits, allow_destroy: true, new_record: "Add Fruit" do |e| 62 | e.input :fruit, as: :select2_multiple 63 | end 64 | end 65 | end 66 | 67 | end 68 | ``` 69 | 70 | ## Acknowledgements 71 | 72 | 73 | ## Copyright 74 | 75 | Copyright (c) 2014 Mark Fairburn, Praxitar Ltd 76 | See the file LICENSE.txt for details. 77 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require "bundler/gem_tasks" 4 | -------------------------------------------------------------------------------- /activeadmin-select2.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | lib = File.expand_path('../lib', __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'activeadmin/select2/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = "activeadmin-select2" 9 | spec.version = ActiveAdmin::Select2::VERSION 10 | spec.summary = %q{Incorporate Select2 jquery into ActiveAdmin} 11 | spec.description = %q{With ActiveAdmin-Select2 you are able to chose Select2 as a drop-down entry option in Forms and Filters} 12 | spec.license = "MIT" 13 | spec.authors = ["Mark Fairburn"] 14 | spec.email = "mark@praxitar,com" 15 | spec.homepage = "https://github.com/mfairburn/activeadmin-select2#readme" 16 | 17 | spec.files = `git ls-files -z`.split("\x0") 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_development_dependency "bundler", "~> 1.5" 21 | spec.add_development_dependency "rake" 22 | 23 | spec.add_runtime_dependency 'activeadmin' 24 | spec.add_runtime_dependency 'jquery-rails' 25 | spec.add_runtime_dependency 'select2-rails' 26 | 27 | end 28 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/select2.js.coffee: -------------------------------------------------------------------------------- 1 | #= require select2 2 | 3 | #= require_tree ./select2 4 | -------------------------------------------------------------------------------- /app/assets/javascripts/active_admin/select2/select2.js.coffee: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | initSelect2 = (inputs, extra = {}) -> 4 | inputs.each -> 5 | item = $(this) 6 | # reading from data allows to be passed to select2 7 | options = $.extend(allowClear: true, extra, item.data('select2')) 8 | # because select2 reads from input.data to check if it is select2 already 9 | item.data('select2', null) 10 | item.select2(options) 11 | 12 | $(document).on 'has_many_add:after', '.has_many_container', (e, fieldset) -> 13 | initSelect2(fieldset.find('.select2-input')) 14 | 15 | $(document).on 'ready page:load turbolinks:load', -> 16 | initSelect2($(".select2-input"), placeholder: "") 17 | return 18 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_admin/select2/_base.scss: -------------------------------------------------------------------------------- 1 | @import "select2"; 2 | @import "filter"; 3 | @import "form"; 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_admin/select2/_filter.scss: -------------------------------------------------------------------------------- 1 | .sidebar_section { 2 | .select2-container { 3 | width: 100%; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /app/assets/stylesheets/active_admin/select2/_form.scss: -------------------------------------------------------------------------------- 1 | #main_content_wrapper { 2 | .select2-container { 3 | width: 50%; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /lib/activeadmin-select2.rb: -------------------------------------------------------------------------------- 1 | require 'activeadmin/select2' 2 | 3 | require 'activeadmin/inputs/filter_select2_multiple_input' 4 | require 'formtastic/inputs/select2_input' 5 | require 'formtastic/inputs/select2_multiple_input' 6 | require 'formtastic/inputs/select2_tags_input' 7 | 8 | -------------------------------------------------------------------------------- /lib/activeadmin/inputs/filter_select2_multiple_input.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Inputs 3 | class FilterSelect2MultipleInput < Formtastic::Inputs::SelectInput 4 | 5 | include ActiveAdmin::Inputs::Filters::Base 6 | 7 | def input_name 8 | "#{super}_in" 9 | end 10 | 11 | def extra_input_html_options 12 | { 13 | :class => 'select2-input', :multiple => true 14 | } 15 | end 16 | 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/activeadmin/select2.rb: -------------------------------------------------------------------------------- 1 | require 'activeadmin/select2/engine' 2 | require 'activeadmin/select2/filter_select_input_extension.rb' 3 | require 'activeadmin/inputs/filter_select2_multiple_input.rb' 4 | 5 | ActiveAdmin::Inputs::Filters::SelectInput.send :include, ActiveAdmin::Select2::Inputs::FilterSelectInputExtension 6 | -------------------------------------------------------------------------------- /lib/activeadmin/select2/engine.rb: -------------------------------------------------------------------------------- 1 | require 'active_admin' 2 | 3 | module ActiveAdmin 4 | module Select2 5 | 6 | class Engine < ::Rails::Engine 7 | engine_name "activeadmin_select2" 8 | end 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/activeadmin/select2/filter_select_input_extension.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Select2 3 | module Inputs 4 | module FilterSelectInputExtension 5 | 6 | def extra_input_html_options 7 | { 8 | :class => 'select2-input' 9 | } 10 | end 11 | 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/activeadmin/select2/version.rb: -------------------------------------------------------------------------------- 1 | module ActiveAdmin 2 | module Select2 3 | VERSION = "0.1.8" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/formtastic/inputs/select2_input.rb: -------------------------------------------------------------------------------- 1 | module Formtastic 2 | module Inputs 3 | 4 | class Select2Input < Formtastic::Inputs::SelectInput 5 | def extra_input_html_options 6 | { 7 | :class => 'select2-input' 8 | } 9 | end 10 | end 11 | 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/formtastic/inputs/select2_multiple_input.rb: -------------------------------------------------------------------------------- 1 | module Formtastic 2 | module Inputs 3 | 4 | class Select2MultipleInput < Formtastic::Inputs::SelectInput 5 | def extra_input_html_options 6 | { 7 | :class => 'select2-input', :multiple => true 8 | } 9 | end 10 | end 11 | 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/formtastic/inputs/select2_tags_input.rb: -------------------------------------------------------------------------------- 1 | require 'formtastic/inputs/string_input' 2 | 3 | module Formtastic 4 | module Inputs 5 | 6 | class Select2TagsInput < Formtastic::Inputs::StringInput 7 | def input_html_options 8 | { 9 | class: 'select2-input select2-tags-input', 10 | data: { select2: { tags: options[:collection] }} 11 | }.merge(super) 12 | end 13 | end 14 | 15 | end 16 | end 17 | --------------------------------------------------------------------------------