]> projects.mako.cc - selectricity-live/blob - vendor/plugins/login_engine/app/helpers/user_helper.rb
2dad7d8b5e22bcc44fd6aedaef3f07bb3e14968b
[selectricity-live] / vendor / plugins / login_engine / app / helpers / user_helper.rb
1 module UserHelper
2
3   # Abstraction to make views a little cleaner
4   def form_input(helper_method, prompt, field_name=nil, options = {}, form_name = nil)
5     form_name = "user" if form_name.nil?
6     case helper_method.to_s
7     when 'hidden_field'
8       self.hidden_field(form_name, field_name, options)
9     when /^.*button$/
10       #prompt = l(:"#{@controller.controller_name}_#{field_name}_button")
11       <<-EOL
12       <tr><td class="button" colspan="2">
13         #{self.send(helper_method, form_name, prompt, options)}
14       </td></tr>
15       EOL
16     else
17       field = (
18         case helper_method
19         when :select
20           self.send(helper_method, form_name, field_name, options.delete('values'), options)
21         when :password_field
22           options[:value] = ""
23           self.send(helper_method, form_name, field_name, options)
24         else
25           self.send(helper_method, form_name, field_name, options)
26         end)
27 #      lname = "#{form_name}_#{field_name}_form"
28 #      prompt = l(:"#{lname}")
29       if LoginEngine.config(:two_column_input)
30 <<-EOL
31         <tr class="two_columns">
32           <td class="prompt"><label>#{prompt}:</label></td>
33           <td class="value">#{field}</td>
34         </tr>
35         EOL
36       else
37 <<-EOL
38         <tr><td class="prompt"><label>#{prompt}:</label></td></tr>
39         <tr><td class="value">#{field}</td></tr>
40         EOL
41       end
42     end
43   end
44
45 #  def button_helper(name, options = {})
46 #    label = l(:"#{@controller.controller_name}_#{name}_button")
47 #    "#{self.send(:submit_tag, label, options)}"
48 #  end
49
50 #  def link_helper(name, options = {})
51 #    raise ArgumentError if name.nil?
52 #    label = l(:"#{@controller.controller_name}_#{name}_link")
53 #    "#{self.send(:link_to, label, options)}"
54 #  end
55
56   def title_helper
57     "#{@controller.controller_class_name} #{@controller.action_name}"
58   end
59
60 #  def message_helper(name)
61 #    l(:"#{@controller.controller_name}_#{name}_message")
62 #  end
63
64   def start_form_tag_helper(options = {})
65     url = url_for(:action => "#{@controller.action_name}")
66     "#{self.send(:start_form_tag, url, options)}"
67   end
68
69   def attributes(hash)
70     hash.keys.inject("") { |attrs, key| attrs + %{#{key}="#{h(hash[key])}" } }
71   end
72
73   def read_only_field(form_name, field_name, html_options)
74     "<span #{attributes(html_options)}>#{instance_variable_get('@' + form_name)[field_name]}</span>"
75   end
76
77   def submit_button(form_name, prompt, html_options)
78     %{<input name="submit" type="submit" value="#{prompt}" />}
79   end
80
81   def changeable(user, field)
82     if user.new_record? or LoginEngine.config(:changeable_fields).include?(field)
83       :text_field
84     else
85       :read_only_field
86     end
87   end
88 end

Benjamin Mako Hill || Want to submit a patch?