Class: Cms::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Cms::FormBuilder
- Defined in:
- app/helpers/cms/form_builder.rb
Overview
Adds additional form fields to the Rails FormBuilder which can be used to create CMS forms.
Instance Method Summary collapse
-
#cms_attachment_manager ⇒ Object
Renders a multiple file uploader for attachments.
-
#cms_check_box(method, options = {}) ⇒ Object
Renders a label and checkbox suitable for allow editors to update a boolean field.
- #cms_drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
-
#cms_error_messages ⇒ Object
Basic replacement for the error_messages provided by Rails 2, which were deprecated/removed in Rails 3.
-
#cms_file_field(method, options = {}) ⇒ Object
Returns a file upload input tag for a given block, along with label and instructions.
-
#cms_instructions(instructions) ⇒ Object
Renders instructions for a given field below the field itself.
-
#cms_label(field, label_value) ⇒ Object
Returns a label for a given field.
- #cms_tag_list(options = {}) ⇒ Object
-
#cms_template_editor(method, options = {}) ⇒ Object
Renders a template editor that allows developers to edit the view used to render a specific block.
-
#cms_text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor with the ‘type’ selector.
- #date_picker(method, options = {}) ⇒ Object
-
#drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
Renders a CMS styled JavaScript/CSS styled select box, by itself with no label or other markup besides the js.
- #tag_list(options = {}) ⇒ Object
-
#text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor without the ‘type’ selector.
Instance Method Details
#cms_attachment_manager ⇒ Object
Renders a multiple file uploader for attachments. Allows users to add as many attachments to this model as needed.
83 84 85 86 87 88 89 90 |
# File 'app/helpers/cms/form_builder.rb', line 83 def defs = Cms::Attachment.definitions_for(object.class.name, :multiple) names = defs.keys.sort return if names.empty? names.unshift "Select a type to upload a file" if names.size > 1 render_cms_form_partial :attachment_manager, :asset_definitions => defs, :asset_types => names end |
#cms_check_box(method, options = {}) ⇒ Object
Renders a label and checkbox suitable for allow editors to update a boolean field.
Params:
* method - The name of the field this check_box will update.
* options - Hash of values including:
- :label
- :instructions
- :default_value
- Any other standard FormBuilder.check_box options that will be passed directly to the check_box method.
154 155 156 157 158 159 |
# File 'app/helpers/cms/form_builder.rb', line 154 def cms_check_box(method, ={}) add_tabindex!() set_default_value!(method, ) = .extract_only!(:label, :instructions, :default_value) render_cms_form_partial "check_box", :method => method, :options => , :cms_options => end |
#cms_drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/cms/form_builder.rb', line 94 def cms_drop_down(method, choices, ={}, ={}) add_tabindex!() set_default_value!(method, ) = .extract_only!(:label, :instructions, :default_value) render_cms_form_partial :drop_down, :object_name => @object_name, :method => method, :choices => choices, :options => , :cms_options => , :html_options => end |
#cms_error_messages ⇒ Object
Basic replacement for the error_messages provided by Rails 2, which were deprecated/removed in Rails 3.
191 192 193 194 195 196 197 198 199 200 |
# File 'app/helpers/cms/form_builder.rb', line 191 def return unless object.respond_to?(:errors) && object.errors.any? errors_list = "" errors_list << @template.content_tag(:h2, "#{object.errors.size} error prohibited this #{object_name.humanize} from being saved.".html_safe) errors_list << @template.content_tag(:p, "There were problems with the following fields:") errors_list << @template.content_tag(:ul, object.errors..map { || @template.content_tag(:li, ).html_safe }.join("\n").html_safe).html_safe @template.content_tag(:div, errors_list.html_safe, :class => "errorExplanation", :id => "errorExplanation") end |
#cms_file_field(method, options = {}) ⇒ Object
Returns a file upload input tag for a given block, along with label and instructions.
73 74 75 76 77 78 79 80 |
# File 'app/helpers/cms/form_builder.rb', line 73 def cms_file_field(method, ={}) @object. if @object.respond_to?(:ensure_attachment_exists) unless [:label] [:label] = method.to_s.humanize end render_form_field("file_field", method, ) end |
#cms_instructions(instructions) ⇒ Object
Renders instructions for a given field below the field itself. Instructions can be used to provide helpful guidance to content editors including formatting help or just explaining what a field is for.
If instructions are blank/nil, then nothing will be shown.
141 142 143 |
# File 'app/helpers/cms/form_builder.rb', line 141 def cms_instructions(instructions) render_cms_form_partial :instructions, :instructions => instructions end |
#cms_label(field, label_value) ⇒ Object
Returns a label for a given field
57 58 59 60 61 62 63 |
# File 'app/helpers/cms/form_builder.rb', line 57 def cms_label(field, label_value) if label_value label field, label_value else label field end end |
#cms_tag_list(options = {}) ⇒ Object
104 105 106 107 108 109 110 |
# File 'app/helpers/cms/form_builder.rb', line 104 def cms_tag_list(={}) add_tabindex!() set_default_value!(:tag_list, ) = .extract_only!(:label, :instructions, :default_value) render_cms_form_partial :tag_list, :options => , :cms_options => end |
#cms_template_editor(method, options = {}) ⇒ Object
Renders a template editor that allows developers to edit the view used to render a specific block. Render both a ‘Handler’ select box (erb, builder, etc) and a text_area for editing. Will not display the editor if the underlying object is marked as ‘render_inline(false)’. This allows developers to edit the render.html.erb directly to update how the model displays.
For example, Portlets will often specify a :template to allow runtime update of their view.
Options:
:default_handler - Which handler will be the default when creating new instances. (Defaults to erb)
:instructions - Instructions that will be displayed below the text area. (Blank by default)
:label - The name for the label (Defaults to humanized version of field name)
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/helpers/cms/form_builder.rb', line 174 def cms_template_editor(method, ={}) if object.class.render_inline # Set some defaults [:default_value] = @object.class.default_template set_default_value!(method, ) [:default_handler] = "erb" unless [:default_handler] = .extract_only!(:label, :instructions) = .extract_only!(:default_handler) add_tabindex!() render_cms_form_partial :template_editor, :method => method, :dropdown_options => , :options => , :cms_options => end end |
#cms_text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor with the ‘type’ selector.
124 125 126 127 128 129 130 131 132 133 |
# File 'app/helpers/cms/form_builder.rb', line 124 def cms_text_editor(method, = {}) add_tabindex!() set_default_value!(method, ) = .extract_only!(:label, :instructions, :default_value) render_cms_form_partial :text_editor, :id => ([:id] || "#{@object_name}_#{method}"), :editor_enabled => (["editorEnabled"].blank? ? true : (["editorEnabled"] == 'true' || ["editorEnabled"] == ['true'])), :object_name => @object_name, :method => method, :options => , :cms_options => end |
#date_picker(method, options = {}) ⇒ Object
28 29 30 |
# File 'app/helpers/cms/form_builder.rb', line 28 def date_picker(method, ={}) text_field(method, {:size => 10, :class => "date_picker", :value => Cms::DatePicker.format_for_ui(@object.send(method))}.merge()) end |
#drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
Renders a CMS styled JavaScript/CSS styled select box, by itself with no label or other markup besides the js.
Options:
* All standard select tag options plus:
* :default_value - The default item to have selected (defaults to the value of the underlying model)
* :width - The width for the select (defaults to 455px).
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/cms/form_builder.rb', line 14 def drop_down(method, choices, = {}, = {}) select_class = "#{@object_name}_#{method}" h_opts = add_tabindex!(@default_options.merge()) h_opts[:class] = select_class opts = () set_default_value!(method, ) = .extract_only!(:default_value, :width) render_cms_form_partial :fancy_drop_down, :object_name => @object_name, :method => method, :choices => choices, :options => opts, :cms_options => , :html_options => h_opts end |
#tag_list(options = {}) ⇒ Object
32 33 34 35 |
# File 'app/helpers/cms/form_builder.rb', line 32 def tag_list(={}) field_name = .delete(:name) || :tag_list text_field(field_name, {:size => 50, :class => "tag-list"}.merge()) end |
#text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor without the ‘type’ selector.
115 116 117 118 119 120 121 |
# File 'app/helpers/cms/form_builder.rb', line 115 def text_editor(method, = {}) @template.send( "text_editor", @object_name, method, ()) end |