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