Skip to content

Commit c3794fe

Browse files
authored
Merge pull request #2917 from clurdish/toggle-checkboxes
Toggle checkboxes
2 parents 19a1a5e + b343303 commit c3794fe

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

app/views/rails_admin/main/index.html.haml

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
export_action = nil unless export_action && authorized?(export_action.authorization_key, @abstract_model)
1111
description = RailsAdmin.config(@abstract_model.model_name).description
1212
properties = @model_config.list.with(controller: self.controller, view: self, object: @abstract_model.model.new).visible_fields
13+
checkboxes = @model_config.list.checkboxes?
1314
# columns paginate
1415
sets = get_column_sets(properties)
1516
properties = sets[params[:set].to_i] || []
1617
other_left = ((params[:set].to_i - 1) >= 0) && sets[params[:set].to_i - 1].present?
1718
other_right = sets[params[:set].to_i + 1].present?
1819

1920
- content_for :contextual_tabs do
20-
= bulk_menu
21+
- if checkboxes
22+
= bulk_menu
2123
- if filterable_fields.present?
2224
%li.dropdown{style: 'float:right'}
2325
%a.dropdown-toggle{href: '#', :'data-toggle' => "dropdown"}
@@ -75,8 +77,9 @@
7577
%table.table.table-condensed.table-striped
7678
%thead
7779
%tr
78-
%th.shrink
79-
%input.toggle{type: "checkbox"}
80+
- if checkboxes
81+
%th.shrink
82+
%input.toggle{type: "checkbox"}
8083
- if other_left
8184
%th.other.left.shrink= "..."
8285
- properties.each do |property|
@@ -91,8 +94,8 @@
9194
%tbody
9295
- @objects.each do |object|
9396
%tr{class: "#{@abstract_model.param_key}_row #{@model_config.list.with(object: object).row_css_class}"}
94-
%td
95-
= check_box_tag "bulk_ids[]", object.id, false
97+
- if checkboxes
98+
%td= check_box_tag "bulk_ids[]", object.id, false
9699
- if @other_left_link ||= other_left && index_path(params.except('set').merge(params[:set].to_i != 1 ? {set: (params[:set].to_i - 1)} : {}))
97100
%td.other.left= link_to "...", @other_left_link, class: 'pjax'
98101
- properties.map{ |property| property.bind(:object, object) }.each do |property|

lib/rails_admin/config/sections/list.rb

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module Config
55
module Sections
66
# Configuration of the list view
77
class List < RailsAdmin::Config::Sections::Base
8+
register_instance_option :checkboxes? do
9+
true
10+
end
11+
812
register_instance_option :filters do
913
[]
1014
end

spec/integration/config/list/rails_admin_config_list_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,44 @@
434434
is_expected.not_to have_link('embed 1')
435435
end
436436
end
437+
438+
describe 'checkboxes?' do
439+
describe 'default is enabled' do
440+
before do
441+
RailsAdmin.config FieldTest do
442+
list
443+
end
444+
end
445+
446+
it 'displays checkboxes on index' do
447+
@records = FactoryGirl.create_list :field_test, 3
448+
449+
visit index_path(model_name: 'field_test')
450+
checkboxes = all(:xpath, './/form[@id="bulk_form"]//input[@type="checkbox"]')
451+
expect(checkboxes.length).to be > 0
452+
453+
expect(page).to have_content('Selected items')
454+
end
455+
end
456+
457+
describe 'false' do
458+
before do
459+
RailsAdmin.config FieldTest do
460+
list do
461+
checkboxes false
462+
end
463+
end
464+
end
465+
466+
it 'does not display any checkboxes on index' do
467+
@records = FactoryGirl.create_list :field_test, 3
468+
469+
visit index_path(model_name: 'field_test')
470+
checkboxes = all(:xpath, './/form[@id="bulk_form"]//input[@type="checkbox"]')
471+
expect(checkboxes.length).to eq 0
472+
473+
expect(page).not_to have_content('Selected items')
474+
end
475+
end
476+
end
437477
end

0 commit comments

Comments
 (0)