Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle checkboxes #2917

Merged
merged 2 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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