rails_admin 0.0.5 → 0.1.0

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.
Files changed (87) hide show
  1. data/Gemfile +5 -30
  2. data/README.md +20 -2
  3. data/app/assets/javascripts/rails_admin/ra.filtering-select.js +2 -2
  4. data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +1 -1
  5. data/app/assets/javascripts/rails_admin/ra.remote-form.js +1 -1
  6. data/app/assets/javascripts/rails_admin/ra.widgets.coffee +43 -3
  7. data/app/assets/javascripts/rails_admin/ui.js.coffee +2 -0
  8. data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +3 -0
  9. data/app/assets/stylesheets/rails_admin/ra.widgets.css.scss +8 -0
  10. data/app/controllers/rails_admin/main_controller.rb +3 -3
  11. data/app/helpers/rails_admin/application_helper.rb +15 -4
  12. data/app/helpers/rails_admin/form_builder.rb +35 -35
  13. data/app/views/layouts/rails_admin/application.html.haml +2 -1
  14. data/app/views/rails_admin/main/_delete_notice.html.haml +9 -8
  15. data/app/views/rails_admin/main/_form_datetime.html.haml +1 -1
  16. data/app/views/rails_admin/main/_form_enumeration.html.haml +18 -1
  17. data/app/views/rails_admin/main/_form_file_upload.html.haml +2 -2
  18. data/app/views/rails_admin/main/_form_text.html.haml +7 -1
  19. data/app/views/rails_admin/main/dashboard.html.haml +26 -25
  20. data/app/views/rails_admin/main/index.html.haml +1 -1
  21. data/config/initializers/active_record_extensions.rb +2 -2
  22. data/config/locales/rails_admin.en.yml +1 -0
  23. data/lib/generators/rails_admin/install_generator.rb +1 -1
  24. data/lib/generators/rails_admin/templates/initializer.erb +66 -67
  25. data/lib/rails_admin/abstract_model.rb +7 -7
  26. data/lib/rails_admin/adapters/active_record.rb +17 -8
  27. data/lib/rails_admin/adapters/mongoid.rb +38 -42
  28. data/lib/rails_admin/adapters/mongoid/extension.rb +1 -1
  29. data/lib/rails_admin/config.rb +15 -1
  30. data/lib/rails_admin/config/actions/base.rb +16 -2
  31. data/lib/rails_admin/config/actions/dashboard.rb +17 -11
  32. data/lib/rails_admin/config/fields.rb +0 -1
  33. data/lib/rails_admin/config/fields/association.rb +2 -3
  34. data/lib/rails_admin/config/fields/base.rb +18 -6
  35. data/lib/rails_admin/config/fields/types/enum.rb +4 -0
  36. data/lib/rails_admin/config/fields/types/string.rb +6 -4
  37. data/lib/rails_admin/config/fields/types/text.rb +19 -2
  38. data/lib/rails_admin/config/model.rb +17 -0
  39. data/lib/rails_admin/config/sections/base.rb +17 -0
  40. data/lib/rails_admin/engine.rb +4 -0
  41. data/lib/rails_admin/extensions/history/auditing_adapter.rb +1 -1
  42. data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +4 -4
  43. data/lib/rails_admin/support/csv_converter.rb +3 -3
  44. data/lib/rails_admin/version.rb +2 -2
  45. data/lib/tasks/rails_admin.rake +36 -6
  46. data/spec/controllers/main_controller_spec.rb +52 -9
  47. data/spec/dummy_app/Gemfile +7 -16
  48. data/spec/dummy_app/app/active_record/another_field_test.rb +4 -0
  49. data/spec/dummy_app/app/active_record/ball.rb +1 -1
  50. data/spec/dummy_app/app/active_record/nested_field_test.rb +2 -1
  51. data/spec/dummy_app/app/active_record/team.rb +3 -2
  52. data/spec/dummy_app/app/active_record/user.rb +6 -2
  53. data/spec/dummy_app/app/mongoid/another_field_test.rb +6 -0
  54. data/spec/dummy_app/app/mongoid/ball.rb +1 -1
  55. data/spec/dummy_app/app/mongoid/nested_field_test.rb +2 -1
  56. data/spec/dummy_app/app/mongoid/team.rb +1 -1
  57. data/spec/dummy_app/config/environments/development.rb +2 -2
  58. data/spec/dummy_app/db/migrate/20120720075608_create_another_field_tests.rb +8 -0
  59. data/spec/dummy_app/db/seeds.rb +3 -3
  60. data/spec/dummy_app/db/test.sqlite3 +0 -0
  61. data/spec/dummy_app/log/test.log +53792 -0
  62. data/spec/helpers/application_helper_spec.rb +37 -0
  63. data/spec/helpers/form_builder_spec.rb +17 -0
  64. data/spec/integration/authorization/cancan_spec.rb +21 -13
  65. data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -8
  66. data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +15 -4
  67. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +9 -12
  68. data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +2 -10
  69. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +6 -0
  70. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +241 -300
  71. data/spec/integration/config/list/rails_admin_config_list_spec.rb +3 -81
  72. data/spec/integration/config/show/rails_admin_config_show_spec.rb +2 -2
  73. data/spec/spec_helper.rb +1 -0
  74. data/spec/unit/active_record_extension_spec.rb +16 -0
  75. data/spec/unit/adapters/active_record_spec.rb +11 -9
  76. data/spec/unit/adapters/mongoid_spec.rb +4 -4
  77. data/spec/unit/config/actions/base_spec.rb +32 -0
  78. data/spec/unit/config/fields/base_spec.rb +56 -0
  79. data/spec/unit/config/fields/date_spec.rb +53 -0
  80. data/spec/unit/config/fields/datetime_spec.rb +55 -0
  81. data/spec/unit/config/fields/time_spec.rb +39 -0
  82. data/spec/unit/config/fields/timestamp_spec.rb +20 -0
  83. data/spec/unit/config_spec.rb +1 -1
  84. data/spec/unit/support/csv_converter_spec.rb +16 -0
  85. metadata +44 -35
  86. data/lib/rails_admin/config/fields/factories/serialized.rb +0 -17
  87. data/lib/tasks/prepare_ci_env.rake +0 -27
data/Gemfile CHANGED
@@ -32,47 +32,22 @@ group :active_record do
32
32
  end
33
33
 
34
34
  group :mongoid do
35
- case ENV['CI_ORM_VERSION']
36
- when 'head'
37
- gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
38
- gem 'mongoid-paperclip', :require => 'mongoid_paperclip', :git => 'git://github.com/mshibuya/mongoid-paperclip.git', :branch => 'fix-stop-patching-logger'
39
- # For now, carrierwave-mongoid's mongoid dependency is restricted to '~> 2.1'
40
- gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid', :git => 'git://github.com/tanordheim/carrierwave-mongoid.git', :branch => 'mongoid_3_0'
41
- else
42
- platforms :ruby, :mswin, :mingw do
43
- gem 'bson'
44
- gem 'bson_ext'
45
- end
46
- gem 'mongoid'
47
- gem 'mongoid-paperclip', :require => 'mongoid_paperclip'
48
- gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
49
- end
35
+ gem 'mongoid', '~> 3.0'
36
+ gem 'mongoid-paperclip', '~> 0.0.8', :require => 'mongoid_paperclip'
37
+ gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid', :git => 'git://github.com/jnicklas/carrierwave-mongoid.git', :branch => 'mongoid-3.0'
50
38
  end
51
39
 
52
40
  group :debug do
53
- platform :mri_18 do
54
- gem 'ruby-debug'
55
- gem 'linecache'
56
- end
57
-
58
41
  platform :mri_19 do
59
- gem 'ruby-debug19'
42
+ gem 'debugger'
60
43
  gem 'simplecov', :require => false
61
44
  end
62
-
63
- platform :jruby do
64
- gem 'ruby-debug'
65
- end
66
- end
67
-
68
- platforms :jruby, :mingw_18, :ruby_18 do
69
- gem 'fastercsv', '~> 1.5'
70
45
  end
71
46
 
72
47
  group :development, :test do
73
48
  gem 'cancan'
74
49
  gem 'devise'
75
- gem 'paperclip', '~> 2.7'
50
+ gem 'paperclip'
76
51
  end
77
52
 
78
53
  gemspec
data/README.md CHANGED
@@ -18,6 +18,20 @@ Hoeven][plukevdh], and [Rein Henrichs][reinh].
18
18
  [plukevdh]: https://github.com/plukevdh
19
19
  [reinh]: https://github.com/reinh
20
20
 
21
+ ## Announcements
22
+
23
+ * for those with `rake db:migrate` errors, update to master and check that you see the line: "[RailsAdmin] RailsAdmin initialization disabled by default." when you launch the task. If not (or if migrations still don't work), open a ticket with an application on Github that can reproduce the issue.
24
+
25
+ * `config.models do ... end` is deprecated (note the 's' to models, `config.model(MyModel) do .. end` is fine), for performance reasons (forces early loading of all application's models). Duplicate to each model instead, before next release. If you really need the old behavior:
26
+
27
+ ```ruby
28
+ config.models.each do |m|
29
+ config.model m do
30
+ # <<<< here goes your code
31
+ end
32
+ end
33
+ ```
34
+
21
35
  ## Features
22
36
 
23
37
  * Display database tables
@@ -43,6 +57,7 @@ Take RailsAdmin for a [test drive][demo] with sample data. ([Source code.][dummy
43
57
  [dummy_app]: https://github.com/bbenezech/dummy_app
44
58
 
45
59
  ## Installation
60
+
46
61
  In your `Gemfile`, add the following dependencies:
47
62
 
48
63
  gem 'fastercsv' # Only required on Ruby 1.8 and below
@@ -98,6 +113,7 @@ Optionally, you may wish to set up [Cancan](https://github.com/ryanb/cancan),
98
113
  More on that in the [Wiki](https://github.com/sferik/rails_admin/wiki)
99
114
 
100
115
  ## Usage
116
+
101
117
  Start the server:
102
118
 
103
119
  $ rails server
@@ -110,13 +126,15 @@ You should now be able to administer your site at
110
126
  All configuration documentation has moved to the wiki: https://github.com/sferik/rails_admin/wiki
111
127
 
112
128
  ## Screenshots
129
+
113
130
  ![Dashboard view](https://github.com/sferik/rails_admin/raw/master/screenshots/dashboard.png "dashboard view")
114
131
  ![Delete view](https://github.com/sferik/rails_admin/raw/master/screenshots/delete.png "delete view")
115
132
  ![List view](https://github.com/sferik/rails_admin/raw/master/screenshots/list.png "list view")
116
133
  ![Nested view](https://github.com/sferik/rails_admin/raw/master/screenshots/nested.png "nested view")
117
- ![Polymophic edit view](https://github.com/sferik/rails_admin/raw/master/screenshots/polymorphic.png "polymorphic view")
134
+ ![Polymorphic edit view](https://github.com/sferik/rails_admin/raw/master/screenshots/polymorphic.png "polymorphic view")
118
135
 
119
136
  ## Support
137
+
120
138
  If you have a question, please check this README, the wiki, and the [list of
121
139
  known issues][troubleshoot].
122
140
 
@@ -130,6 +148,7 @@ list][list].
130
148
  If you think you found a bug in RailsAdmin, you can [submit an issue][issues].
131
149
 
132
150
  ## Contributing
151
+
133
152
  In the spirit of [free software][free-sw], **everyone** is encouraged to help
134
153
  improve this project.
135
154
 
@@ -180,7 +199,6 @@ Ideally, a bug report should include a pull request with failing specs.
180
199
  ## Supported Ruby Versions
181
200
  This library aims to support and is [tested against][travis] the following Ruby implementations:
182
201
 
183
- * Ruby 1.8.7
184
202
  * Ruby 1.9.2
185
203
  * Ruby 1.9.3
186
204
  * [Rubinius][]
@@ -40,7 +40,7 @@
40
40
  }).toArray();
41
41
  }
42
42
  var filtering_select = $('<div class="input-append filtering-select" style="float:left"></div>')
43
- var input = this.input = $('<input type="search">')
43
+ var input = this.input = $('<input type="text">')
44
44
  .val(value)
45
45
  .addClass("ra-filtering-select-input")
46
46
  .attr('style', select.attr('style'))
@@ -83,7 +83,7 @@
83
83
  .keyup(function() {
84
84
  /* Clear select options and trigger change if selected item is deleted */
85
85
  if ($(this).val().length == 0) {
86
- select.empty();
86
+ select.html($('<option value="" selected="selected"></option>'));
87
87
  select.trigger("change");
88
88
  }
89
89
  })
@@ -7,7 +7,7 @@ $(document).ready ->
7
7
  tab_content.children().last()
8
8
 
9
9
  $('form').live 'nested:fieldAdded', (content) ->
10
- field = content.field.addClass('tab-pane')
10
+ field = content.field.addClass('tab-pane').attr('id', 'unique-id-' + (new Date().getTime()))
11
11
  new_tab = $('<li><a data-toggle="tab" href="#' + field.attr('id') + '">' + field.children('.object-infos').data('object-label') + '</a></li>')
12
12
  parent_group = field.closest('.control-group')
13
13
  controls = parent_group.children('.controls')
@@ -60,7 +60,7 @@
60
60
  },
61
61
  dataType: 'text'
62
62
  });
63
- },100);
63
+ },200);
64
64
 
65
65
  },
66
66
 
@@ -26,7 +26,10 @@ $(document).live 'rails_admin.dom_ready', ->
26
26
  # enumeration
27
27
 
28
28
  $('form [data-enumeration]').each ->
29
- $(this).filteringSelect $(this).data('options')
29
+ if $(this).is('[multiple]')
30
+ $(this).filteringMultiselect $(this).data('options')
31
+ else
32
+ $(this).filteringSelect $(this).data('options')
30
33
 
31
34
  # fileupload
32
35
 
@@ -35,6 +38,24 @@ $(document).live 'rails_admin.dom_ready', ->
35
38
  $(this).find(".delete input[type='checkbox']").live 'click', ->
36
39
  $(input).children('.toggle').toggle('slow')
37
40
 
41
+ # fileupload-preview
42
+
43
+ $('form [data-fileupload]').change ->
44
+ input = this
45
+ image_container = $("#" + input.id).parent().children(".preview")
46
+ unless image_container.length
47
+ image_container = $("#" + input.id).parent().prepend($('<img />').addClass('preview')).find('img.preview')
48
+ image_container.parent().find('img:not(.preview)').hide()
49
+ ext = $("#" + input.id).val().split('.').pop().toLowerCase()
50
+ if input.files and input.files[0] and $.inArray(ext, ['gif','png','jpg','jpeg','bmp']) != -1
51
+ reader = new FileReader()
52
+ reader.onload = (e) ->
53
+ image_container.attr "src", e.target.result
54
+ reader.readAsDataURL input.files[0]
55
+ image_container.show()
56
+ else
57
+ image_container.hide()
58
+
38
59
  # filtering-multiselect
39
60
 
40
61
  $('form [data-filteringmultiselect]').each ->
@@ -62,6 +83,7 @@ $(document).live 'rails_admin.dom_ready', ->
62
83
  toggler = field.find('> .controls > .btn-group > .toggler')
63
84
  # add each nested field to a tab-pane and reference it in the nav
64
85
  content.children('.fields:not(.tab-pane)').addClass('tab-pane').each ->
86
+ $(this).attr('id', 'unique-id-' + (new Date().getTime()) + Math.floor(Math.random()*100000)) # some elements are created on the same ms
65
87
  nav.append('<li><a data-toggle="tab" href="#' + this.id + '">' + $(this).children('.object-infos').data('object-label') + '</a></li>')
66
88
  # only if no tab is set to active
67
89
  if nav.find("> li.active").length == 0
@@ -88,7 +110,7 @@ $(document).live 'rails_admin.dom_ready', ->
88
110
  nav = field.find("> .controls > .nav")
89
111
  content = field.find("> .tab-content")
90
112
  toggler = field.find('> .controls > .toggler')
91
- content.children(".fields:not(.tab-pane)").addClass('tab-pane').each ->
113
+ content.children(".fields:not(.tab-pane)").addClass('tab-pane active').each ->
92
114
  nav.append('<li><a data-toggle="tab" href="#' + this.id + '">' + $(this).children('.object-infos').data('object-label') + '</a></li>')
93
115
  first_tab = nav.find("> li > a[data-toggle='tab']:first")
94
116
  first_tab.tab('show')
@@ -156,7 +178,7 @@ $(document).live 'rails_admin.dom_ready', ->
156
178
  CodeMirror.fromTextArea(textarea,{mode:options['options']['mode'],theme:options['options']['theme']})
157
179
  $(textarea).addClass('codemirrored')
158
180
 
159
- array = $('form [data-richtext=codemirror]').not('.codemirrored')
181
+ array = $('form [data-richtext=codemirror]').not('.codemirrored')
160
182
  if array.length
161
183
  @array = array
162
184
  if not window.CodeMirror
@@ -167,3 +189,21 @@ $(document).live 'rails_admin.dom_ready', ->
167
189
  else
168
190
  goCodeMirrors(@array)
169
191
 
192
+ # bootstrap_wysihtml5
193
+
194
+ goBootstrapWysihtml5s = (array) =>
195
+ array.each ->
196
+ $(@).addClass('bootstrap-wysihtml5ed')
197
+ $(@).closest('.controls').addClass('well')
198
+ $(@).wysihtml5()
199
+
200
+ array = $('form [data-richtext=bootstrap-wysihtml5]').not('.bootstrap-wysihtml5ed')
201
+ if array.length
202
+ @array = array
203
+ if not window.wysihtml5
204
+ options = $(array[0]).data('options')
205
+ $('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
206
+ $.getScript options['jspath'], (script, textStatus, jqXHR) =>
207
+ goBootstrapWysihtml5s(@array)
208
+ else
209
+ goBootstrapWysihtml5s(@array)
@@ -62,3 +62,5 @@ $(document).live 'rails_admin.dom_ready', ->
62
62
 
63
63
  $('.form-horizontal legend').has('i.icon-chevron-right').each ->
64
64
  $(this).siblings('.control-group').hide()
65
+
66
+ $(".table").tooltip selector: "th[rel=tooltip]"
@@ -1,3 +1,5 @@
1
+ @charset "UTF-8";
2
+
1
3
  <%
2
4
  theme = ENV['RAILS_ADMIN_THEME'] || :default
3
5
  %>
@@ -25,6 +27,7 @@
25
27
  @import "rails_admin/jquery.ui.timepicker";
26
28
  @import "rails_admin/ra.calendar-additions";
27
29
  @import "rails_admin/ra.filtering-multiselect";
30
+ @import "rails_admin/ra.widgets";
28
31
  @import "rails_admin/jquery.colorpicker";
29
32
 
30
33
 
@@ -0,0 +1,8 @@
1
+ iframe.wysihtml5-sandbox{
2
+ height: 250px !important;
3
+ width: 75% !important;
4
+ }
5
+ .controls img.preview{
6
+ max-height: 100px;
7
+ max-width: 100px;
8
+ }
@@ -29,7 +29,7 @@ module RailsAdmin
29
29
  self.send(params[:bulk_action]) if params[:bulk_action].in?(RailsAdmin::Config::Actions.all(:controller => self, :abstract_model => @abstract_model).select(&:bulkable?).map(&:route_fragment))
30
30
  end
31
31
 
32
- def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all]))
32
+ def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all] || params[:bulk_ids]))
33
33
  scope = model_config.abstract_model.scoped
34
34
  if auth_scope = @authorization_adapter && @authorization_adapter.query(auth_scope_key, model_config.abstract_model)
35
35
  scope = scope.merge(auth_scope)
@@ -40,7 +40,7 @@ module RailsAdmin
40
40
  end
41
41
 
42
42
  private
43
-
43
+
44
44
  def get_layout
45
45
  "rails_admin/#{request.headers['X-PJAX'] ? 'pjax' : 'application'}"
46
46
  end
@@ -113,7 +113,7 @@ module RailsAdmin
113
113
  end
114
114
 
115
115
  def check_for_cancel
116
- if params[:_continue]
116
+ if params[:_continue] || (params[:bulk_action] && !params[:bulk_ids])
117
117
  redirect_to(back_or_index, :flash => { :info => t("admin.flash.noaction") })
118
118
  end
119
119
  end
@@ -10,8 +10,8 @@ module RailsAdmin
10
10
  end
11
11
 
12
12
  def current_action?(action, abstract_model = @abstract_model, object = @object)
13
- @action.custom_key == action.custom_key &&
14
- abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
13
+ @action.custom_key == action.custom_key &&
14
+ abstract_model.try(:to_param) == @abstract_model.try(:to_param) &&
15
15
  (@object.try(:persisted?) ? @object.id == object.try(:id) : !object.try(:persisted?))
16
16
  end
17
17
 
@@ -43,7 +43,7 @@ module RailsAdmin
43
43
  end
44
44
 
45
45
  def main_navigation
46
- nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
46
+ nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
47
47
  nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|
48
48
 
49
49
  li_stack = nodes.select{|n| n.parent.nil? || !n.parent.to_s.in?(nodes_stack.map{|c| c.abstract_model.model_name }) }.map do |node|
@@ -63,6 +63,18 @@ module RailsAdmin
63
63
  end.join.html_safe
64
64
  end
65
65
 
66
+ def static_navigation
67
+ li_stack = RailsAdmin::Config.navigation_static_links.map do |title, url|
68
+ content_tag(:li, link_to(title.to_s, url, :target => '_blank')).html_safe
69
+ end.join.html_safe
70
+
71
+ if li_stack.present?
72
+ li_stack = %{<li class='nav-header'>#{RailsAdmin::Config.navigation_static_label || t('admin.misc.navigation_static_label')}</li>}.html_safe + li_stack
73
+ end
74
+
75
+ li_stack
76
+ end
77
+
66
78
  def navigation nodes_stack, nodes, level
67
79
  nodes.map do |node|
68
80
  %{
@@ -78,7 +90,6 @@ module RailsAdmin
78
90
  begin
79
91
  (parent_actions ||= []) << action
80
92
  end while action.breadcrumb_parent && (action = action(*action.breadcrumb_parent))
81
- parent_actions << action(:dashboard) if parent_actions.last.key != :dashboard # in case chain is interrupted
82
93
 
83
94
  content_tag(:ul, :class => "breadcrumb") do
84
95
  parent_actions.map do |a|
@@ -1,31 +1,31 @@
1
- ActionView::Base.field_error_proc = Proc.new { |html_tag, instance| html_tag }
2
-
3
1
  module RailsAdmin
4
2
  class FormBuilder < ::ActionView::Helpers::FormBuilder
5
3
  include ::NestedForm::BuilderMixin
6
4
 
7
5
  def generate(options = {})
8
- options.reverse_merge!({
9
- :action => @template.controller.params[:action],
10
- :model_config => @template.instance_variable_get(:@model_config),
11
- :nested_in => false
12
- })
6
+ without_field_error_proc_added_div do
7
+ options.reverse_merge!({
8
+ :action => @template.controller.params[:action],
9
+ :model_config => @template.instance_variable_get(:@model_config),
10
+ :nested_in => false
11
+ })
13
12
 
14
- if options[:nested_in]
15
- action = :nested
16
- elsif @template.request.format == 'text/javascript'
17
- action = :modal
18
- else
19
- action = options[:action]
20
- end
21
-
22
- groups = options[:model_config].send(action).with(:form => self, :object => @object, :view => @template).visible_groups
13
+ if options[:nested_in]
14
+ action = :nested
15
+ elsif @template.request.format == 'text/javascript'
16
+ action = :modal
17
+ else
18
+ action = options[:action]
19
+ end
20
+
21
+ groups = options[:model_config].send(action).with(:form => self, :object => @object, :view => @template).visible_groups
23
22
 
24
- object_infos +
25
- groups.map do |fieldset|
26
- fieldset_for fieldset, options[:nested_in]
27
- end.join.html_safe +
28
- (options[:nested_in] ? '' : @template.render(:partial => 'submit_buttons'))
23
+ object_infos +
24
+ groups.map do |fieldset|
25
+ fieldset_for fieldset, options[:nested_in]
26
+ end.join.html_safe +
27
+ (options[:nested_in] ? '' : @template.render(:partial => 'rails_admin/main/submit_buttons'))
28
+ end
29
29
  end
30
30
 
31
31
  def fieldset_for fieldset, nested_in
@@ -43,14 +43,15 @@ module RailsAdmin
43
43
  def field_wrapper_for field, nested_in
44
44
  if field.label
45
45
  # do not show nested field if the target is the origin
46
- unless field.inverse_of.presence && field.inverse_of == nested_in
46
+ unless field.inverse_of.presence && field.inverse_of == nested_in &&
47
+ @template.instance_variable_get(:@model_config).abstract_model == field.associated_model_config.abstract_model
47
48
  @template.content_tag(:div, :class => "control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", :id => "#{dom_id(field)}_field") do
48
49
  label(field.method_name, field.label, :class => 'control-label') +
49
50
  (field.nested_form ? field_for(field) : input_for(field))
50
51
  end
51
52
  end
52
53
  else
53
- (field.nested_form ? field_for(field) : input_for(field))
54
+ (field.nested_form ? field_for(field) : input_for(field))
54
55
  end
55
56
  end
56
57
 
@@ -85,18 +86,6 @@ module RailsAdmin
85
86
  %{<span style="display:none" class="object-infos" data-model-label="#{model_label}" data-object-label="#{object_label}"></span>}.html_safe
86
87
  end
87
88
 
88
- def javascript_for(field, options = {}, &block)
89
- %{<script type="text/javascript">
90
- jQuery(function($) {
91
- if(!$("#{jquery_namespace(field)}").parents(".fields_blueprint").length) {
92
- if(#{options[:modal] == false ? '!$("#modal").length' : 'true'}) {
93
- #{@template.capture(&block)}
94
- }
95
- }
96
- });
97
- </script>}.html_safe
98
- end
99
-
100
89
  def jquery_namespace field
101
90
  %{#{(@template.controller.params[:modal] ? '#modal ' : '')}##{dom_id(field)}_field}
102
91
  end
@@ -113,5 +102,16 @@ module RailsAdmin
113
102
  def dom_name field
114
103
  (@dom_name ||= {})[field.name] ||= %{#{@object_name}#{options[:index] && "[#{options[:index]}]"}[#{field.method_name}]#{field.is_a?(Config::Fields::Association) && field.multiple? ? '[]' : ''}}
115
104
  end
105
+
106
+ protected
107
+ def without_field_error_proc_added_div
108
+ default_field_error_proc = ::ActionView::Base.field_error_proc
109
+ begin
110
+ ::ActionView::Base.field_error_proc = Proc.new { |html_tag, instance| html_tag }
111
+ yield
112
+ ensure
113
+ ::ActionView::Base.field_error_proc = default_field_error_proc
114
+ end
115
+ end
116
116
  end
117
117
  end