module ScaffoldLogic module FormHelper SELECT_PROMPT_OPTION = '' # Returns a check mark. # # Usage: # # <%= checkmark -%> def checkmark %{
}.html_safe end def countdown_field(field_id,update_id,max,options = {}) function = "$('#{update_id}').innerHTML = (#{max} - $F('#{field_id}').length);" count_field_tag(field_id,function,options) end def count_field(field_id,update_id,options = {}) function = "$('#{update_id}').innerHTML = $F('#{field_id}').length;" count_field_tag(field_id,function,options) end def count_field_tag(field_id,function,options = {}) %{ }.html_safe end # Returns a simulated text-field for read-only versions of a form. # # Usage: # # <%= faux_field 'Name', @user.name -%> def faux_field(label, content, options={:field_id => nil, :help => nil}) if options[:help] options[:field_id] ||= "field_#{Time.zone.now.to_i}#{rand(10000)}" %{#{tag_for_label_with_inline_help label, options[:field_id], options[:help]}
#{content}
}.html_safe else %{
#{content}
}.html_safe end end # Returns a legend tag that renders correctly in all browsers. # # Usage: # # <%= legend_tag "Report Criteria" -%> # # With help text: # # <%= legend_tag "Report Criteria", :help => "Some descriptive copy here." -%> # Backlinks (<%= # @google_results.size -%>) # <%- end -%> # # Recommended CSS to support display of help icon and text: # # .help_icon { # display: block; # float: left; # margin-top: -16px; # margin-left: 290px; # border-left: 1px solid #444444; # padding: 3px 6px; # cursor: pointer; # } # # div.popup_help { # color: #666666; # width: 98%; # background: #ffffff; # padding: 1em; # border: 1px solid #999999; # margin: 1em 0em; # } def legend_tag(text, options={}) options[:id] ||= "#{text.downcase.gsub(' ', '-')}-legend" if options[:help] _html = %{
#{text}?
\r} _html << %{\r} else _html = %{
#{text}
\r} end _html.gsub!(/ id=""/,'') _html.gsub!(/ class=""/,'') _html.html_safe end # Create a set of tags for displaying a field label with inline help. # Field label text is appended with a ? icon, which responds to a click # by showing or hiding the provided help text. # # Sample usage: # # <%= tag_for_label_with_inline_help 'Relative Frequency', 'rel_frequency', 'Relative frequency of search traffic for this keyword across multiple search engines, as measured by WordTracker.' %> # # Yields: # # # def tag_for_label_with_inline_help( label_text, field_id, help_text ) _html = "" _html << %{} _html << %{} _html end # Create a set of tags for displaying a field label followed by instructions. # The instructions are displayed on a new line following the field label. # # Usage: # # <%= tag_for_label_with_instructions 'Status', 'is_active', 'Only active widgets will be visible to the public.' %> # # Yields: # # def tag_for_label_with_instructions( label_text, field_id, instructions ) _html = "" _html << %{} _html end # Returns a string of HTML option tags for the given array of option values. Specify the selected value for stickiness. # # Usage: # # <%= select_tag :user, tags_for_option_values(User.all.map{ |c| [c.name, c.id] }, params[:user]) -%> def tags_for_option_values( a, selected = nil, prompt_option = SELECT_PROMPT_OPTION ) "#{prompt_option}#{a.map{ |_e| _flag = _e[1].to_s == selected ? 'selected="1"' : ''; _e.is_a?(Array) ? "" : "" }}".html_safe end end end