Skip to content

Commit

Permalink
Adds a parent_readonly configuration option to has_many associations to
Browse files Browse the repository at this point in the history
hide "Add another" buttons
  • Loading branch information
pehlert committed Nov 11, 2012
1 parent 92f7d80 commit be988f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -41,7 +41,7 @@


- selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv - selected_ids = (hdv = field.html_default_value).nil? ? selected_ids : hdv
= 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}) = 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})
- if authorized? :new, config.abstract_model - if authorized?(:new, config.abstract_model) && !field.parent_readonly
- path_hash = { :model_name => config.abstract_model.to_param, :modal => true } - path_hash = { :model_name => config.abstract_model.to_param, :modal => true }
- path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of - path_hash.merge!({ :associations => { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
= 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' = 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'
5 changes: 5 additions & 0 deletions lib/rails_admin/config/fields/types/has_many_association.rb
Expand Up @@ -17,6 +17,11 @@ class HasManyAssociation < RailsAdmin::Config::Fields::Association
false false
end end


# read-only parent objects
register_instance_option :parent_readonly do
self.associated_model_config.excluded?
end

def method_name def method_name
nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids
end end
Expand Down

0 comments on commit be988f7

Please sign in to comment.