Class: Sunrise::Views::FormBuilder
- Inherits:
-
SimpleForm::FormBuilder
- Object
- SimpleForm::FormBuilder
- Sunrise::Views::FormBuilder
- Includes:
- ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::TagHelper
- Defined in:
- lib/sunrise/views/form_builder.rb
Instance Method Summary collapse
- #attach_file_field(attribute_name, options = {}, &block) ⇒ Object
- #button(type, *args, &block) ⇒ Object
- #globalize(options = {}, &block) ⇒ Object
- #input(attribute_name, options = {}, &block) ⇒ Object
Instance Method Details
#attach_file_field(attribute_name, options = {}, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/sunrise/views/form_builder.rb', line 47 def attach_file_field(attribute_name, = {}, &block) value = .delete(:value) if .key?(:value) value ||= object.fileupload_asset(attribute_name) element_guid = object.fileupload_guid element_id = dom_id(object, [attribute_name, element_guid].join('_')) = (.delete(:script) || {}).stringify_keys params = { :method => attribute_name, :assetable_id => object.new_record? ? nil : object.id, :assetable_type => object.class.name, :guid => element_guid }.merge(.delete(:params) || {}) ['action'] ||= '/sunrise/fileupload?' + Rack::Utils.build_query(params) ['allowedExtensions'] ||= ['jpg', 'jpeg', 'png', 'gif'] ['multiple'] ||= object.fileupload_multiple?(attribute_name) ['element'] ||= element_id label ||= if object && object.class.respond_to?(:human_attribute_name) object.class.human_attribute_name(attribute_name) end locals = { :element_id => element_id, :file_title => ([:file_title] || "JPEG, GIF, PNG or TIFF"), :file_max_size => ([:file_max_size] || 10), :label => (label || attribute_name.to_s.humanize), :object => object, :attribute_name => attribute_name, :assets => [value].flatten.delete_if { |v| v.nil? || v.new_record? }, :script_options => .inspect.gsub('=>', ':'), :multiple => ['multiple'], :asset_klass => params[:klass] } template.render(:partial => "manage/fileupload/container", :locals => locals) end |
#button(type, *args, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sunrise/views/form_builder.rb', line 28 def (type, *args, &block) = args. html = [:input_html] || {} url = [:url] || [:manage, object_plural] value = object.new_record? ? 'create' : 'update' title = html[:title] || I18n.t(value, :scope => :manage) html = { :value => value, :type => type, :class => "gr cupid-green", :name => "commit" }.merge(html) content_tag(:div, :class => "buts controls") do concat content_tag(:button, title, html) concat link_to(I18n.t('manage.cancel'), url, :class => "erase") end end |
#globalize(options = {}, &block) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/sunrise/views/form_builder.rb', line 21 def globalize(={}, &block) locales = [:locales] || Sunrise.available_locales html = [] html.join.html_safe end |
#input(attribute_name, options = {}, &block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/sunrise/views/form_builder.rb', line 12 def input(attribute_name, = {}, &block) [:input_html] ||= {} [:input_html] = { :class => 'text' }.merge([:input_html]) attribute_name = "#{attribute_name}_#{[:locale]}" unless [:locale].blank? super(attribute_name, , &block) end |