Permalink
Browse files

added the instructions method to the group

  • Loading branch information...
1 parent 0060ad2 commit 3ced23b4d9caae7a0ebeb1a54fd3195b81e43148 @AlainPilon AlainPilon committed Jun 24, 2011
View
@@ -744,6 +744,24 @@ Field groups can be renamed:
This would render "Team information" instead of "Basic info" as the groups label.
+**Field groupings - instructions**
+
+Field groups can have a set of instructions which is displayed under the label:
+
+ RailsAdmin.config do |config|
+ config.model Team do
+ edit do
+ group :default do
+ label "Team information"
+ instructions "Please fill all informations related to your team..."
+ end
+ end
+ end
+ end
+
+This content is mostly useful when the admin doign the data entry is not familiar with the system or as a way to display inline documentation.
+
+
**Field groupings - syntax**
As in the list view, the edit views' configuration blocks can directly
@@ -1,8 +1,9 @@
<% if (fields = fieldset.fields.map{ |f| f.with(:form => form, :object => object, :view => self) }.select(&:visible)).length > 0 %>
- <fieldset class="group">
+ <fieldset>
<legend><%= fieldset.label %></legend>
+ <%= content_tag :div, fieldset.instructions, :class => "instructions" if fieldset.instructions %>
<% fields.each do |field| %>
<%= field.render -%>
<% end %>
</fieldset>
- <% end %>
+ <% end %>
@@ -9,7 +9,8 @@ class Group < RailsAdmin::Config::Base
include RailsAdmin::Config::Hideable
attr_reader :name
-
+ attr_accessor :instructions
+
def initialize(parent, name)
super(parent)
@name = name.to_s.tr(' ', '_').downcase.to_sym
@@ -52,6 +53,12 @@ def visible_fields
register_instance_option(:label) do
name.to_s.humanize
end
+
+ register_instance_option(:instructions) do
+ nil
+ end
+
+
end
end
end
@@ -57,7 +57,57 @@
response.should have_tag("legend", :content => "Renamed group")
end
-
+
+ describe "instructions" do
+
+ it "should show instructions section if present" do
+ RailsAdmin.config Team do
+ edit do
+ group :default do
+ instructions "instructions paragraph to display"
+ end
+ end
+ end
+ get rails_admin_new_path(:model_name => "team")
+
+ response.should have_tag('.instructions', :content => "instructions paragraph to display")
+ end
+
+ it "should not show instructions if not present" do
+ RailsAdmin.config Team do
+ edit do
+ group :default do
+ label 'no_instructions'
+ end
+ end
+ end
+ get rails_admin_new_path(:model_name => "team")
+
+ response.should_not have_tag('.instructions')
+ end
+
+ it "should be able to display multiple instructions if there are multiple sections" do
+ RailsAdmin.config Team do
+ edit do
+ group :default do
+ field :name
+ instructions 'instructions for default'
+ end
+ group :other_section do
+ label "Other Section"
+ field :division_id
+ instructions 'instructions for other section'
+ end
+ end
+ end
+ get rails_admin_new_path(:model_name => "team")
+ response.should have_tag(".instructions", :content => 'instructions for default')
+ response.should have_tag(".instructions", :content => 'instructions for other section')
+ response.should have_tag(".instructions", :count => 2)
+ end
+
+ end
+
it "should have accessor for its fields" do
RailsAdmin.config Team do
edit do

0 comments on commit 3ced23b

Please sign in to comment.