Skip to content

Commit

Permalink
Merge pull request #2917 from clurdish/toggle-checkboxes
Browse files Browse the repository at this point in the history
Toggle checkboxes
  • Loading branch information
mshibuya authored Aug 25, 2017
2 parents 19a1a5e + b343303 commit c3794fe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/views/rails_admin/main/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
export_action = nil unless export_action && authorized?(export_action.authorization_key, @abstract_model)
description = RailsAdmin.config(@abstract_model.model_name).description
properties = @model_config.list.with(controller: self.controller, view: self, object: @abstract_model.model.new).visible_fields
checkboxes = @model_config.list.checkboxes?
# columns paginate
sets = get_column_sets(properties)
properties = sets[params[:set].to_i] || []
other_left = ((params[:set].to_i - 1) >= 0) && sets[params[:set].to_i - 1].present?
other_right = sets[params[:set].to_i + 1].present?

- content_for :contextual_tabs do
= bulk_menu
- if checkboxes
= bulk_menu
- if filterable_fields.present?
%li.dropdown{style: 'float:right'}
%a.dropdown-toggle{href: '#', :'data-toggle' => "dropdown"}
Expand Down Expand Up @@ -75,8 +77,9 @@
%table.table.table-condensed.table-striped
%thead
%tr
%th.shrink
%input.toggle{type: "checkbox"}
- if checkboxes
%th.shrink
%input.toggle{type: "checkbox"}
- if other_left
%th.other.left.shrink= "..."
- properties.each do |property|
Expand All @@ -91,8 +94,8 @@
%tbody
- @objects.each do |object|
%tr{class: "#{@abstract_model.param_key}_row #{@model_config.list.with(object: object).row_css_class}"}
%td
= check_box_tag "bulk_ids[]", object.id, false
- if checkboxes
%td= check_box_tag "bulk_ids[]", object.id, false
- if @other_left_link ||= other_left && index_path(params.except('set').merge(params[:set].to_i != 1 ? {set: (params[:set].to_i - 1)} : {}))
%td.other.left= link_to "...", @other_left_link, class: 'pjax'
- properties.map{ |property| property.bind(:object, object) }.each do |property|
Expand Down
4 changes: 4 additions & 0 deletions lib/rails_admin/config/sections/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module Config
module Sections
# Configuration of the list view
class List < RailsAdmin::Config::Sections::Base
register_instance_option :checkboxes? do
true
end

register_instance_option :filters do
[]
end
Expand Down
40 changes: 40 additions & 0 deletions spec/integration/config/list/rails_admin_config_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,44 @@
is_expected.not_to have_link('embed 1')
end
end

describe 'checkboxes?' do
describe 'default is enabled' do
before do
RailsAdmin.config FieldTest do
list
end
end

it 'displays checkboxes on index' do
@records = FactoryGirl.create_list :field_test, 3

visit index_path(model_name: 'field_test')
checkboxes = all(:xpath, './/form[@id="bulk_form"]//input[@type="checkbox"]')
expect(checkboxes.length).to be > 0

expect(page).to have_content('Selected items')
end
end

describe 'false' do
before do
RailsAdmin.config FieldTest do
list do
checkboxes false
end
end
end

it 'does not display any checkboxes on index' do
@records = FactoryGirl.create_list :field_test, 3

visit index_path(model_name: 'field_test')
checkboxes = all(:xpath, './/form[@id="bulk_form"]//input[@type="checkbox"]')
expect(checkboxes.length).to eq 0

expect(page).not_to have_content('Selected items')
end
end
end
end

0 comments on commit c3794fe

Please sign in to comment.