Module: FormHelper
- Defined in:
- lib/forge/app/helpers/form_helper.rb
Instance Method Summary collapse
- #add_child_link(name, association) ⇒ Object
-
#content_row(title, options = {}) ⇒ Object
form row helper for content blocks.
-
#file_select_widget(f, method, options = {}) ⇒ Object
asset library helper for adding an image to a model.
-
#forge_form_for(*args, &block) ⇒ Object
form-header form row helper.
-
#form_row(label = nil, options = {}) ⇒ Object
form row helper for pop-up window forms.
- #language_switcher(table) ⇒ Object
- #new_child_fields_template(form_builder, association, options = {}) ⇒ Object
-
#publish_box(f, object) ⇒ Object
form row helper for boolean published block.
- #remove_child_link(name, f) ⇒ Object
-
#side_row(title, options = {}) ⇒ Object
form row helper for narrow side column rows.
- #title_row(options = {}) ⇒ Object
Instance Method Details
#add_child_link(name, association) ⇒ Object
81 82 83 |
# File 'lib/forge/app/helpers/form_helper.rb', line 81 def add_child_link(name, association) link_to(name, "#", :class => "add_child", :"data-association" => association) end |
#content_row(title, options = {}) ⇒ Object
form row helper for content blocks
45 46 47 48 49 |
# File 'lib/forge/app/helpers/form_helper.rb', line 45 def content_row(title, = {}) title = content_tag(:h3, title) explanation = [:explanation].blank? ? "" : content_tag(:div, [:explanation], :class => "explanation") return title.html_safe + explanation.html_safe + "<br />".html_safe + yield end |
#file_select_widget(f, method, options = {}) ⇒ Object
asset library helper for adding an image to a model
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/forge/app/helpers/form_helper.rb', line 62 def (f, method, = {}) unique_id = Time.now.to_i field = "#{f.object.class.to_s.downcase}_#{method}" thumbnail_url = f.object.send("#{method}_asset_url".to_sym).blank? ? f.object.send("#{method}_icon_path".to_sym) : f.object.send("#{method}_asset_url".to_sym) content = "" # Build the links links = [link_to("Upload From Computer", '#', :class => "upload-file"), link_to("Choose From Library", '#', :class => "select-asset")] links << remove_child_link("Remove", f) if [:allow_destroy] links << content_tag(:label, check_box_tag("remove_asset") + "Remove this asset") if [:allow_remove] # Build the rest of the widget content << image_tag(thumbnail_url, :class => "form-thumbnail") unless thumbnail_url.blank? # If the form failed, show the thumbnail of the previously selected asset content << f.hidden_field("#{method}_asset_id".to_sym, :class => "file-widget-asset-id") # Eg. avatar_asset_id content << f.hidden_field("#{method}_asset_url".to_sym, :class => "file-widget-asset-url") # Eg. avatar_asset_url content << content_tag(:small, content_tag(:div, "", :class => "spacer") + links.join('<br />').html_safe) return content_tag :div, content.html_safe, :class => "extendable-inset" end |
#forge_form_for(*args, &block) ⇒ Object
form-header form row helper
3 4 5 6 7 |
# File 'lib/forge/app/helpers/form_helper.rb', line 3 def forge_form_for(*args, &block) = args. .merge(:builder => ::ForgeFormBuilder) form_for(*(args + []), &block) end |
#form_row(label = nil, options = {}) ⇒ Object
form row helper for pop-up window forms
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/forge/app/helpers/form_helper.rb', line 26 def form_row(label = nil, = {}) explanation = [:explanation].blank? ? nil : "<div class='explanation'>#{[:explanation]}</div>" required = [:required].blank? ? nil : " *" style = [:style].blank? ? nil : [:style] id = [:id].blank? ? nil : [:id] file_link = nil unless [:file].nil? || ([:file].url && [:file].url.blank?) || ([:file].is_a?(ActiveRecord) && [:file].new_record?) #check for a_fu or paperclip [:file].url = [:file].public_filename if [:file].url.nil? file_link = '<br /><small><a href="' + [:file].url + '" target="_">View Current</a></small>' end label_td = content_tag(:td, "#{label}#{required}#{file_link}".html_safe, :class => "label") control_td = content_tag(:td, yield + "#{explanation}", :class => "control") return content_tag(:tr, label_td.html_safe + control_td.html_safe, :id => id, :style => style).html_safe end |
#language_switcher(table) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/forge/app/helpers/form_helper.rb', line 101 def language_switcher(table) if Forge.config.languages if I18nLookup.fields[:tables][table] select_tag "current_language", ([["English", "en"]] + Forge.config.languages.map {|k, v| [k.to_s.titleize, v]}) end end end |
#new_child_fields_template(form_builder, association, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/forge/app/helpers/form_helper.rb', line 89 def new_child_fields_template(form_builder, association, = {}) [:object] ||= form_builder.object.class.reflect_on_association(association).klass.new [:partial] ||= association.to_s.singularize [:form_builder_local] ||= :f content_tag(:div, :id => "#{association}_fields_template", :style => "display: none") do form_builder.fields_for(association, [:object], :child_index => "new_#{association}") do |f| render(:partial => [:partial], :locals => {[:form_builder_local] => f}) end end end |
#publish_box(f, object) ⇒ Object
form row helper for boolean published block
52 53 54 55 56 57 58 59 |
# File 'lib/forge/app/helpers/form_helper.rb', line 52 def publish_box(f, object) if can?(:publish, object) return content_tag(:h3, "Publish") + content_tag(:div, "Is your #{object.class.to_s.downcase} ready to appear on your website?", :class => "explanation") + ("Yes", f.(:published, true), "Not Yet", f.(:published, false)) + "<hr />".html_safe end end |
#remove_child_link(name, f) ⇒ Object
85 86 87 |
# File 'lib/forge/app/helpers/form_helper.rb', line 85 def remove_child_link(name, f) f.hidden_field(:_destroy) + link_to(name, "javascript:void(0)", :class => "remove_child") end |
#side_row(title, options = {}) ⇒ Object
form row helper for narrow side column rows
17 18 19 20 21 22 23 |
# File 'lib/forge/app/helpers/form_helper.rb', line 17 def side_row(title, = {}) title = content_tag(:h3, title) explanation = [:explanation].blank? ? "" : content_tag(:div, [:explanation], :class => "explanation") content = title.html_safe + explanation.html_safe + yield content += "<hr />".html_safe unless [:last] content end |
#title_row(options = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/forge/app/helpers/form_helper.rb', line 9 def title_row( = {}) title = content_tag(:h3, [:title] ? [:title] : "Title") explanation = [:explanation] ? content_tag(:div, [:explanation], :class => "explanation") : "" row_label = content_tag(:div, title.html_safe + explanation.html_safe, :class => "label") return row_label.html_safe + yield + content_tag(:div, "", :class => "spacer") end |