Merge request #83, resolve conflict
[gitorious:mainline.git] / lib / gitorious_form_builder.rb
1 class GitoriousFormBuilder < ActionView::Helpers::FormBuilder
2   
3   # Creates a set of radio buttons for the current_user and a select tag
4   # for any groups he's a member of
5   def current_user_or_group(field, label_title, hint = nil, options = {})
6     result = [label(field, label_title), ""]
7     result << "<div>"
8     result << "Me: " + radio_button("#{field}_type", "User", {:checked => true})
9     result << select_group_membership(field)
10     if options[:hint]
11       result << content_tag(:p, options[:hint], :class => "hint")
12     end
13     result << "</div>"
14     result.join("\n")
15   end
16   
17   private
18
19   def select_group_membership(field)
20     admin_groups = @template.current_user.groups.select {|g| g.admin? @template.current_user }
21     result = ""
22     unless admin_groups.empty?
23       result << "Group: " + radio_button("#{field}_type", "Group")
24       result << select("#{field}_id", admin_groups.map{|g| [g.name, g.id] }, 
25                         {}, :id => "#{object_name}_#{field}_id_group_select")
26     end
27     result    
28   end
29 end