Permalink
Browse files

Adds a parent_readonly configuration option to has_many associations to

hide "Add another" buttons
  • Loading branch information...
1 parent 92f7d80 commit be988f7e1d490906ca3cdcc91719ec53f1be7773 @pehlert committed Nov 11, 2012
@@ -41,7 +41,7 @@
- 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})
-- 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.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'
@@ -17,6 +17,11 @@ class HasManyAssociation < RailsAdmin::Config::Fields::Association
false
end
+ # read-only parent objects
+ register_instance_option :parent_readonly do
+ self.associated_model_config.excluded?
+ end
+
def method_name
nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids
end

0 comments on commit be988f7

Please sign in to comment.