Skip to content

Commit e596b6b

Browse files
committed
Merge branch 'master' of git://github.com/sferik/rails_admin
Conflicts: app/views/rails_admin/main/_form_filtering_multiselect.html.haml lib/rails_admin/config/fields/types/has_many_association.rb
2 parents e746e7f + b8465f7 commit e596b6b

File tree

25 files changed

+449
-242
lines changed

25 files changed

+449
-242
lines changed

app/assets/javascripts/rails_admin/jquery.ui.timepicker.js

Lines changed: 222 additions & 218 deletions
Large diffs are not rendered by default.

app/assets/javascripts/rails_admin/ui.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -68,3 +68,10 @@ $(document).on 'rails_admin.dom_ready', ->
68
$(this).siblings('.control-group').hide()
68
$(this).siblings('.control-group').hide()
69

69

70
$(".table").tooltip selector: "th[rel=tooltip]"
70
$(".table").tooltip selector: "th[rel=tooltip]"
71+
72+
$(document).on 'click', '#fields_to_export label input#check_all', () ->
73+
elems = $('#fields_to_export label input')
74+
if $('#fields_to_export label input#check_all').is ':checked'
75+
$(elems).prop('checked', true)
76+
else
77+
$(elems).prop('checked',false)

app/assets/stylesheets/rails_admin/base/theming.scss

Lines changed: 2 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -47,7 +47,8 @@ body.rails_admin {
47
.controls .nav {
47
.controls .nav {
48
margin-bottom:5px;
48
margin-bottom:5px;
49
}
49
}
50-
.remove_nested_fields {
50+
.remove_nested_fields,
51+
.remove_nested_one_fields {
51
position:absolute;
52
position:absolute;
52
}
53
}
53
margin:0px;
54
margin:0px;

app/controllers/rails_admin/main_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_sort_hash(model_config)
62
"#{abstract_model.table_name}.#{params[:sort]}"
62
"#{abstract_model.table_name}.#{params[:sort]}"
63
elsif field.sortable == false # use default sort, asked field is not sortable
63
elsif field.sortable == false # use default sort, asked field is not sortable
64
"#{abstract_model.table_name}.#{model_config.list.sort_by}"
64
"#{abstract_model.table_name}.#{model_config.list.sort_by}"
65-
elsif field.sortable.is_a?(String) && field.sortable.include?('.') # just provide sortable, don't do anything smart
65+
elsif (field.sortable.is_a?(String) || field.sortable.is_a?(Symbol)) && field.sortable.to_s.include?('.') # just provide sortable, don't do anything smart
66
field.sortable
66
field.sortable
67
elsif field.sortable.is_a?(Hash) # just join sortable hash, don't do anything smart
67
elsif field.sortable.is_a?(Hash) # just join sortable hash, don't do anything smart
68
"#{field.sortable.keys.first}.#{field.sortable.values.first}"
68
"#{field.sortable.keys.first}.#{field.sortable.values.first}"

app/helpers/rails_admin/application_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -79,9 +79,10 @@ def navigation nodes_stack, nodes, level=0
79
model_param = node.abstract_model.to_param
79
model_param = node.abstract_model.to_param
80
url = url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)
80
url = url_for(:action => :index, :controller => 'rails_admin/main', :model_name => model_param)
81
level_class = " nav-level-#{level}" if level > 0
81
level_class = " nav-level-#{level}" if level > 0
82+
nav_icon = node.navigation_icon ? %{<i class="#{node.navigation_icon}"></i>}.html_safe : ''
82

83

83
li = content_tag :li, "data-model"=>model_param do
84
li = content_tag :li, "data-model"=>model_param do
84-
link_to node.label_plural, url, :class => "pjax#{level_class}"
85+
link_to nav_icon + node.label_plural, url, :class => "pjax#{level_class}"
85
end
86
end
86
li + navigation(nodes_stack, nodes_stack.select{ |n| n.parent.to_s == node.abstract_model.model_name}, level+1)
87
li + navigation(nodes_stack, nodes_stack.select{ |n| n.parent.to_s == node.abstract_model.model_name}, level+1)
87
end.join.html_safe
88
end.join.html_safe

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

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -41,7 +41,7 @@
41

41

42
- selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv
42
- selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv
43
= form.select field.method_name, collection, { :selected => selected_ids, :object => form.object }, field.html_attributes.reverse_merge({:data => { :filteringmultiselect => true, :options => js_data.to_json }, :multiple => true})
43
= form.select field.method_name, collection, { :selected => selected_ids, :object => form.object }, field.html_attributes.reverse_merge({:data => { :filteringmultiselect => true, :options => js_data.to_json }, :multiple => true})
44-
- if authorized?(:new, config.abstract_model) && !field.parent_readonly
44+
- if authorized?(:new, config.abstract_model) && !field.parent_readonly && field.inline_add
45
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
45
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
46
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
46
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
47
= link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "create btn btn-info", :style => 'margin-left:10px'
47
= link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "create btn btn-info", :style => 'margin-left:10px'

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

Lines changed: 2 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -28,10 +28,10 @@
28
- selected_id = (hdv = field.html_default_value).nil? ? selected_id : hdv
28
- selected_id = (hdv = field.html_default_value).nil? ? selected_id : hdv
29
= form.select field.method_name, collection, { :selected => selected_id, :include_blank => true }, field.html_attributes.reverse_merge({ :data => { :filteringselect => true, :options => js_data.to_json }, :placeholder => t('admin.misc.search') })
29
= form.select field.method_name, collection, { :selected => selected_id, :include_blank => true }, field.html_attributes.reverse_merge({ :data => { :filteringselect => true, :options => js_data.to_json }, :placeholder => t('admin.misc.search') })
30

30

31-
- if authorized? :new, config.abstract_model
31+
- if authorized?(:new, config.abstract_model) && field.inline_add
32
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
32
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
33
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
33
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
34
= link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "btn btn-info create", :style => 'margin-left:10px'
34
= link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', :data => { :link => new_path(path_hash) }, :class => "btn btn-info create", :style => 'margin-left:10px'
35

35

36-
- if edit_url.present?
36+
- if edit_url.present? && field.inline_edit
37
= link_to "<i class=\"icon-pencil icon-white\"></i> ".html_safe + wording_for(:link, :edit, config.abstract_model), '#', :data => { :link => edit_url }, :class => "btn btn-info update #{field.value.nil? && 'disabled'}", :style => 'margin-left:10px'
37
= link_to "<i class=\"icon-pencil icon-white\"></i> ".html_safe + wording_for(:link, :edit, config.abstract_model), '#', :data => { :link => edit_url }, :class => "btn btn-info update #{field.value.nil? && 'disabled'}", :style => 'margin-left:10px'

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

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -2,7 +2,7 @@
2
.btn-group
2
.btn-group
3
%a.btn.btn-info.toggler{:'data-toggle' => "button", :'data-target' => "#{form.jquery_namespace(field)} > .tab-content, #{form.jquery_namespace(field)} > .controls > .nav", :class => (field.active? ? 'active' : '')}
3
%a.btn.btn-info.toggler{:'data-toggle' => "button", :'data-target' => "#{form.jquery_namespace(field)} > .tab-content, #{form.jquery_namespace(field)} > .controls > .nav", :class => (field.active? ? 'active' : '')}
4
%i.icon-white
4
%i.icon-white
5-
- unless field.nested_form[:update_only]
5+
- unless field.nested_form[:update_only] || !field.inline_add
6
= form.link_to_add "<i class=\"icon-plus icon-white\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".html_safe, field.name, { :class => 'btn btn-info' }
6
= form.link_to_add "<i class=\"icon-plus icon-white\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".html_safe, field.name, { :class => 'btn btn-info' }
7
= form.errors_for(field)
7
= form.errors_for(field)
8
= form.help_for(field)
8
= form.help_for(field)

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

Lines changed: 6 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -4,7 +4,12 @@
4
= form_tag export_path(params.merge(:all => true)), :method => 'post', :class => 'form-horizontal denser' do
4
= form_tag export_path(params.merge(:all => true)), :method => 'post', :class => 'form-horizontal denser' do
5

5

6
%input{:name => "send_data", :type => "hidden", :value => "true"}/
6
%input{:name => "send_data", :type => "hidden", :value => "true"}/
7-
%fieldset
7+
%fieldset{:id => 'fields_to_export'}
8+
%div.control-group
9+
%div.controls
10+
%label.checkbox{:for => 'check_all'}
11+
= 'Select All Fields'
12+
= check_box_tag 'all', 'all', true, { :id => 'check_all' }
8
%legend
13
%legend
9
%i.icon-chevron-down
14
%i.icon-chevron-down
10
= t('admin.export.select')
15
= t('admin.export.select')

lib/rails_admin/adapters/active_record.rb

Lines changed: 4 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -107,6 +107,10 @@ def embedded?
107
false
107
false
108
end
108
end
109

109

110+
def cyclic?
111+
false
112+
end
113+
110
def adapter_supports_joins?
114
def adapter_supports_joins?
111
true
115
true
112
end
116
end

lib/rails_admin/adapters/mongoid.rb

Lines changed: 14 additions & 6 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -6,7 +6,7 @@ module RailsAdmin
6
module Adapters
6
module Adapters
7
module Mongoid
7
module Mongoid
8
STRING_TYPE_COLUMN_NAMES = [:name, :title, :subject]
8
STRING_TYPE_COLUMN_NAMES = [:name, :title, :subject]
9-
DISABLED_COLUMN_TYPES = ['Range']
9+
DISABLED_COLUMN_TYPES = ['Range', 'Moped::BSON::Binary']
10
ObjectId = (::Mongoid::VERSION >= '3' ? ::Moped::BSON::ObjectId : ::BSON::ObjectId)
10
ObjectId = (::Mongoid::VERSION >= '3' ? ::Moped::BSON::ObjectId : ::BSON::ObjectId)
11

11

12
def new(params = {})
12
def new(params = {})
@@ -105,6 +105,10 @@ def embedded?
105
@embedded ||= !!model.associations.values.find{|a| a.macro.to_sym == :embedded_in }
105
@embedded ||= !!model.associations.values.find{|a| a.macro.to_sym == :embedded_in }
106
end
106
end
107

107

108+
def cyclic?
109+
@cyclic ||= !!model.cyclic?
110+
end
111+
108
def object_id_from_string(str)
112
def object_id_from_string(str)
109
ObjectId.from_string(str)
113
ObjectId.from_string(str)
110
end
114
end
@@ -327,7 +331,7 @@ def association_foreign_inverse_of_lookup(association)
327

331

328
def association_nested_attributes_options_lookup(association)
332
def association_nested_attributes_options_lookup(association)
329
nested = model.nested_attributes_options.try { |o| o[association.name.to_sym] }
333
nested = model.nested_attributes_options.try { |o| o[association.name.to_sym] }
330-
if !nested && [:embeds_one, :embeds_many].include?(association.macro.to_sym)
334+
if !nested && [:embeds_one, :embeds_many].include?(association.macro.to_sym) && !association.cyclic
331
raise <<-MSG.gsub(/^\s+/, '')
335
raise <<-MSG.gsub(/^\s+/, '')
332
Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,
336
Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin,
333
because embedded model doesn't have top-level access.
337
because embedded model doesn't have top-level access.
@@ -426,10 +430,14 @@ def perform_search_on_associated_collection(field_name, conditions)
426
def sort_by(options, scope)
430
def sort_by(options, scope)
427
return scope unless options[:sort]
431
return scope unless options[:sort]
428

432

429-
field_name, collection_name = options[:sort].to_s.split('.').reverse
433+
case options[:sort]
430-
if collection_name && collection_name != table_name
434+
when String
431-
# sorting by associated model column is not supported, so just ignore
435+
field_name, collection_name = options[:sort].split('.').reverse
432-
return scope
436+
if collection_name && collection_name != table_name
437+
raise "sorting by associated model column is not supported in Non-Relational databases"
438+
end
439+
when Symbol
440+
field_name = options[:sort].to_s
433
end
441
end
434
if options[:sort_reverse]
442
if options[:sort_reverse]
435
scope.asc field_name
443
scope.asc field_name

lib/rails_admin/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -315,7 +315,7 @@ def reset_model(model)
315
# @see RailsAdmin::Config::Hideable
315
# @see RailsAdmin::Config::Hideable
316

316

317
def visible_models(bindings)
317
def visible_models(bindings)
318-
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model) && !m.abstract_model.embedded?}.sort do |a, b|
318+
models.map{|m| m.with(bindings) }.select{|m| m.visible? && bindings[:controller].authorized?(:index, m.abstract_model) && (!m.abstract_model.embedded? || m.abstract_model.cyclic?)}.sort do |a, b|
319
(weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
319
(weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
320
end
320
end
321
end
321
end

lib/rails_admin/config/fields/base.rb

Lines changed: 20 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -215,10 +215,28 @@ def virtual?
215

215

216
def editable?
216
def editable?
217
return false if @properties && @properties[:read_only]
217
return false if @properties && @properties[:read_only]
218-
active_model_attr_accessible = !bindings[:object].class.active_authorizer[bindings[:view].controller.send(:_attr_accessible_role)].deny?(self.method_name)
218+
role = bindings[:view].controller.send(:_attr_accessible_role)
219+
active_model_attr_accessible = !bindings[:object].class.active_authorizer[role].deny?(self.method_name)
220+
219
return true if active_model_attr_accessible
221
return true if active_model_attr_accessible
220
if RailsAdmin::Config.yell_for_non_accessible_fields
222
if RailsAdmin::Config.yell_for_non_accessible_fields
221-
Rails.logger.debug "\n\n[RailsAdmin] Please add 'attr_accessible :#{self.method_name}' in your '#{bindings[:object].class}' model definition if you want to make it editable.\nYou can also explicitely mark this field as read-only: \n\nconfig.model #{bindings[:object].class} do\n field :#{self.name} do\n read_only true\n end\nend\n\nAdd 'config.yell_for_non_accessible_fields = false' in your 'rails_admin.rb' initializer if you do not want to see these warnings\n\n"
223+
accessible = "attr_accessible :#{self.method_name}#{role == :default ? '' : ", :as => :#{role}"}"
224+
225+
Rails.logger.debug <<-MESSAGE.strip_heredoc
226+
227+
228+
[RailsAdmin] Please add '#{accessible}' in your '#{bindings[:object].class}' model definition if you want to make it editable.
229+
You can also explicitely mark this field as read-only:
230+
231+
config.model #{bindings[:object].class} do
232+
field :#{self.name} do
233+
read_only true
234+
end
235+
end
236+
237+
Add 'config.yell_for_non_accessible_fields = false' in your 'rails_admin.rb' initializer if you do not want to see these warnings
238+
239+
MESSAGE
222
end
240
end
223
false
241
false
224
end
242
end

lib/rails_admin/config/fields/types/belongs_to_association.rb

Lines changed: 8 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -23,6 +23,14 @@ class BelongsToAssociation < RailsAdmin::Config::Fields::Association
23
nested_form ? :form_nested_one : :form_filtering_select
23
nested_form ? :form_nested_one : :form_filtering_select
24
end
24
end
25

25

26+
register_instance_option :inline_add do
27+
true
28+
end
29+
30+
register_instance_option :inline_edit do
31+
true
32+
end
33+
26
def selected_id
34
def selected_id
27
bindings[:object].send(foreign_key)
35
bindings[:object].send(foreign_key)
28
end
36
end

lib/rails_admin/config/fields/types/has_many_association.rb

Lines changed: 4 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -22,6 +22,10 @@ class HasManyAssociation < RailsAdmin::Config::Fields::Association
22
self.associated_model_config.excluded?
22
self.associated_model_config.excluded?
23
end
23
end
24

24

25+
register_instance_option :inline_add do
26+
true
27+
end
28+
25
def method_name
29
def method_name
26
nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids
30
nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids
27
end
31
end

lib/rails_admin/config/fields/types/has_one_association.rb

Lines changed: 9 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -17,6 +17,15 @@ class HasOneAssociation < RailsAdmin::Config::Fields::Association
17
(o = value) && o.send(associated_model_config.object_label_method)
17
(o = value) && o.send(associated_model_config.object_label_method)
18
end
18
end
19

19

20+
register_instance_option :inline_add do
21+
true
22+
end
23+
24+
register_instance_option :inline_edit do
25+
true
26+
end
27+
28+
20
def editable?
29
def editable?
21
(nested_form || abstract_model.model.new.respond_to?("#{self.name}_id=")) && super
30
(nested_form || abstract_model.model.new.respond_to?("#{self.name}_id=")) && super
22
end
31
end

lib/rails_admin/config/fields/types/serialized.rb

Lines changed: 3 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -13,7 +13,9 @@ class Serialized < RailsAdmin::Config::Fields::Types::Text
13
end
13
end
14

14

15
def parse_input(params)
15
def parse_input(params)
16-
params[name] = (params[name].blank? ? nil : YAML.safe_load(params[name])) if params[name].is_a?(::String)
16+
if params[name].is_a?(::String)
17+
params[name] = (params[name].blank? ? nil : (YAML.safe_load(params[name]) || nil))
18+
end
17
end
19
end
18
end
20
end
19
end
21
end

lib/rails_admin/config/model.rb

Lines changed: 4 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -82,6 +82,10 @@ def pluralize(count)
82
@navigation_label ||= (parent_module = abstract_model.model.parent) != Object ? parent_module.to_s : nil
82
@navigation_label ||= (parent_module = abstract_model.model.parent) != Object ? parent_module.to_s : nil
83
end
83
end
84

84

85+
register_instance_option :navigation_icon do
86+
nil
87+
end
88+
85
# Act as a proxy for the base section configuration that actually
89
# Act as a proxy for the base section configuration that actually
86
# store the configurations.
90
# store the configurations.
87
def method_missing(m, *args, &block)
91
def method_missing(m, *args, &block)

lib/rails_admin/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -2,7 +2,7 @@ module RailsAdmin
2
class Version
2
class Version
3
MAJOR = 0 unless defined? MAJOR
3
MAJOR = 0 unless defined? MAJOR
4
MINOR = 4 unless defined? MINOR
4
MINOR = 4 unless defined? MINOR
5-
PATCH = 5 unless defined? PATCH
5+
PATCH = 7 unless defined? PATCH
6
PRE = nil unless defined? PRE
6
PRE = nil unless defined? PRE
7

7

8
class << self
8
class << self

spec/controllers/rails_admin/main_controller_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -38,6 +38,24 @@
38
end
38
end
39

39

40
describe "#get_sort_hash" do
40
describe "#get_sort_hash" do
41+
context "options sortable is a hash" do
42+
before do
43+
RailsAdmin.config('Player') do
44+
configure :team do
45+
sortable do
46+
:'team.name'
47+
end
48+
end
49+
end
50+
end
51+
52+
it "returns the option with no changes" do
53+
controller.params = { :sort => "team", :model_name =>"players" }
54+
expect(controller.send(:get_sort_hash, RailsAdmin.config(Player))).to eq({:sort=>:"team.name", :sort_reverse=>true})
55+
end
56+
end
57+
58+
41
it "works with belongs_to associations with label method virtual" do
59
it "works with belongs_to associations with label method virtual" do
42
controller.params = { :sort => "parent_category", :model_name =>"categories" }
60
controller.params = { :sort => "parent_category", :model_name =>"categories" }
43
expect(controller.send(:get_sort_hash, RailsAdmin.config(Category))).to eq({:sort=>"categories.parent_category_id", :sort_reverse=>true})
61
expect(controller.send(:get_sort_hash, RailsAdmin.config(Category))).to eq({:sort=>"categories.parent_category_id", :sort_reverse=>true})

spec/dummy_app/app/mongoid/field_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -11,6 +11,7 @@ class FieldTest
11
field :big_decimal_field, :type => BigDecimal
11
field :big_decimal_field, :type => BigDecimal
12
field :boolean_field, :type => Boolean
12
field :boolean_field, :type => Boolean
13
field :bson_object_id_field, :type => RailsAdmin::Adapters::Mongoid::ObjectId
13
field :bson_object_id_field, :type => RailsAdmin::Adapters::Mongoid::ObjectId
14+
field :bson_binary_field, :type => Moped::BSON::Binary
14
field :date_field, :type => Date
15
field :date_field, :type => Date
15
field :datetime_field, :type => DateTime
16
field :datetime_field, :type => DateTime
16
field :time_with_zone_field, :type => ActiveSupport::TimeWithZone
17
field :time_with_zone_field, :type => ActiveSupport::TimeWithZone
@@ -30,7 +31,7 @@ class FieldTest
30
field :protected_field, :type => String
31
field :protected_field, :type => String
31
has_mongoid_attached_file :paperclip_asset, :styles => { :thumb => "100x100>" }
32
has_mongoid_attached_file :paperclip_asset, :styles => { :thumb => "100x100>" }
32

33

33-
basic_accessible_fields = [:comment_attributes, :nested_field_tests_attributes, :embed_attributes, :embeds_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :carrierwave_asset, :carrierwave_asset_cache, :remove_carrierwave_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :array_field, :big_decimal_field, :boolean_field, :bson_object_id_field, :date_field, :datetime_field, :time_with_zone_field, :default_field, :float_field, :hash_field, :integer_field, :object_field, :range_field, :string_field, :symbol_field, :text_field, :time_field, :created_at, :updated_at, :format]
34+
basic_accessible_fields = [:comment_attributes, :nested_field_tests_attributes, :embed_attributes, :embeds_attributes, :dragonfly_asset, :remove_dragonfly_asset, :retained_dragonfly_asset, :carrierwave_asset, :carrierwave_asset_cache, :remove_carrierwave_asset, :paperclip_asset, :delete_paperclip_asset, :comment_id, :name, :array_field, :big_decimal_field, :boolean_field, :bson_object_id_field, :bson_binary_field, :date_field, :datetime_field, :time_with_zone_field, :default_field, :float_field, :hash_field, :integer_field, :object_field, :range_field, :string_field, :symbol_field, :text_field, :time_field, :created_at, :updated_at, :format]
34
attr_accessible *basic_accessible_fields
35
attr_accessible *basic_accessible_fields
35
attr_accessible *(basic_accessible_fields + [:restricted_field, {:as => :custom_role}])
36
attr_accessible *(basic_accessible_fields + [:restricted_field, {:as => :custom_role}])
36
attr_accessible *(basic_accessible_fields + [:protected_field, {:as => :extra_safe_role}])
37
attr_accessible *(basic_accessible_fields + [:protected_field, {:as => :extra_safe_role}])

spec/integration/config/edit/rails_admin_config_edit_spec.rb

Lines changed: 74 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -593,6 +593,79 @@ class HelpTest < Tableless
593
expect(find("#team_division_id_field .help-block")).to have_content("Optional")
593
expect(find("#team_division_id_field .help-block")).to have_content("Optional")
594
expect(find("#team_name_field .help-block")).to have_content("Required")
594
expect(find("#team_name_field .help-block")).to have_content("Required")
595
end
595
end
596+
597+
it "can hide the add button on an associated field" do
598+
RailsAdmin.config Player do
599+
edit do
600+
field :team do
601+
inline_add false
602+
end
603+
field :draft do
604+
inline_add false
605+
end
606+
field :comments do
607+
inline_add false
608+
end
609+
end
610+
end
611+
visit new_path(:model_name => "player")
612+
should have_no_selector('a', :text => 'Add a new Team')
613+
should have_no_selector('a', :text => 'Add a new Draft')
614+
should have_no_selector('a', :text => 'Add a new Comment')
615+
end
616+
617+
it "can show the add button on an associated field" do
618+
RailsAdmin.config Player do
619+
edit do
620+
field :team do
621+
inline_add true
622+
end
623+
field :draft do
624+
inline_add true
625+
end
626+
field :comments do
627+
inline_add true
628+
end
629+
end
630+
end
631+
visit new_path(:model_name => "player")
632+
should have_selector('a', :text => 'Add a new Team')
633+
should have_selector('a', :text => 'Add a new Draft')
634+
should have_selector('a', :text => 'Add a new Comment')
635+
end
636+
637+
it "can hide the edit button on an associated field" do
638+
RailsAdmin.config Player do
639+
edit do
640+
field :team do
641+
inline_edit false
642+
end
643+
field :draft do
644+
inline_edit false
645+
end
646+
end
647+
end
648+
visit new_path(:model_name => "player")
649+
should have_no_selector('a', :text => 'Edit this Team')
650+
should have_no_selector('a', :text => 'Edit this Draft')
651+
end
652+
653+
it "can show the edit button on an associated field" do
654+
RailsAdmin.config Player do
655+
edit do
656+
field :team do
657+
inline_edit true
658+
end
659+
field :draft do
660+
inline_edit true
661+
end
662+
end
663+
end
664+
visit new_path(:model_name => "player")
665+
should have_selector('a', :text => 'Edit this Team')
666+
should have_selector('a', :text => 'Edit this Draft')
667+
end
668+
596
end
669
end
597

670

598
describe "bindings" do
671
describe "bindings" do
@@ -1023,4 +1096,5 @@ def color_enum
1023
should have_selector(".color_type input")
1096
should have_selector(".color_type input")
1024
end
1097
end
1025
end
1098
end
1099+
1026
end
1100
end

0 commit comments

Comments
 (0)