rails_admin_toggleable 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_admin_toggleable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gleb Tv
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # RailsAdminToggleable
2
+
3
+ Make any boolean field easily toggleable on\off from index view in rails admin
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails_admin_toggleable'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rails_admin_toggleable
18
+
19
+ ## Usage
20
+
21
+ Add the toggleable action:
22
+
23
+ RailsAdmin.config do |config|
24
+ config.actions do
25
+ ......
26
+ toggle
27
+ end
28
+ end
29
+
30
+ Make the field you need toggleable:
31
+
32
+ rails_admin do
33
+ list do
34
+ field :enabled, :toggle
35
+ ...
36
+ end
37
+ ...
38
+ end
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,52 @@
1
+ module RailsAdmin
2
+ module Config
3
+ module Actions
4
+ class Toggle < Base
5
+ RailsAdmin::Config::Actions.register(self)
6
+
7
+ # Is the action acting on the root level (Example: /admin/contact)
8
+ register_instance_option :root? do
9
+ false
10
+ end
11
+
12
+ register_instance_option :collection? do
13
+ false
14
+ end
15
+
16
+ # Is the action on an object scope (Example: /admin/team/1/edit)
17
+ register_instance_option :member? do
18
+ true
19
+ end
20
+
21
+ register_instance_option :controller do
22
+ Proc.new do |klass|
23
+ if params['id'].present?
24
+ begin
25
+ obj = @abstract_model.model.find(params['id'])
26
+ method = params[:method]
27
+ obj.send(method + '=', params[:on] == '1' ? true : false)
28
+ if obj.save
29
+ redirect_to :back, success: "OK"
30
+ else
31
+ redirect_to :back, error: obj.errors.full_messages.join(', ')
32
+ end
33
+ rescue Exception => e
34
+ redirect_to :back, error: "Error: #{e}"
35
+ end
36
+ else
37
+ redirect_to :back, error: 'No ID'
38
+ end
39
+ end
40
+ end
41
+
42
+ register_instance_option :link_icon do
43
+ 'icon-move'
44
+ end
45
+
46
+ register_instance_option :http_methods do
47
+ [:post]
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,50 @@
1
+ require 'builder'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class Toggle < RailsAdmin::Config::Fields::Base
8
+ # Register field type for the type loader
9
+ RailsAdmin::Config::Fields::Types::register(self)
10
+ include RailsAdmin::Engine.routes.url_helpers
11
+
12
+ register_instance_option :view_helper do
13
+ :check_box
14
+ end
15
+
16
+ register_instance_option :formatted_value do
17
+ case value
18
+ when nil
19
+ '-'
20
+ when false
21
+ 'On'
22
+ when true
23
+ 'Off'
24
+ end
25
+ end
26
+
27
+ register_instance_option :pretty_value do
28
+ case value
29
+ when nil
30
+ %{<span class="badge">-</span>}
31
+ when false
32
+ bindings[:view].link_to '&#x2718;'.html_safe, toggle_path(model_name: @abstract_model, id: bindings[:object].id, method: name, on: '1'), method: :post, class: 'badge badge-important'
33
+ when true
34
+ bindings[:view].link_to '&#x2713;'.html_safe, toggle_path(model_name: @abstract_model, id: bindings[:object].id, method: name, on: '0'), method: :post, class: 'badge badge-success'
35
+ end.html_safe
36
+ end
37
+
38
+ register_instance_option :export_value do
39
+ value.inspect
40
+ end
41
+
42
+ # Accessor for field's help text displayed below input field.
43
+ register_instance_option :help do
44
+ ""
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminToggleable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "rails_admin_toggleable/version"
2
+
3
+ module RailsAdminToggleable
4
+ end
5
+
6
+ require 'rails_admin/config/actions'
7
+ require 'rails_admin/config/model'
8
+
9
+ require 'rails_admin_toggleable/action'
10
+ require 'rails_admin_toggleable/field'
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_admin_toggleable/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rails_admin_toggleable"
8
+ gem.version = RailsAdminToggleable::VERSION
9
+ gem.authors = ["Gleb Tv"]
10
+ gem.email = ["glebtv@gmail.com"]
11
+ gem.description = %q{Toggleable field for rails admin}
12
+ gem.summary = %q{Make any boolean field easily toggleable on\off from index view in rails admin}
13
+ gem.homepage = "https://github.com/rs-pro/rails_admin_toggleable"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_toggleable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gleb Tv
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Toggleable field for rails admin
15
+ email:
16
+ - glebtv@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/rails_admin_toggleable.rb
27
+ - lib/rails_admin_toggleable/action.rb
28
+ - lib/rails_admin_toggleable/field.rb
29
+ - lib/rails_admin_toggleable/version.rb
30
+ - rails_admin_toggleable.gemspec
31
+ homepage: https://github.com/rs-pro/rails_admin_toggleable
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.24
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Make any boolean field easily toggleable on\off from index view in rails
55
+ admin
56
+ test_files: []