Class: Forma::ImageField
- Inherits:
-
SimpleField
- Object
- Field
- SimpleField
- Forma::ImageField
- Defined in:
- lib/forma/field.rb
Overview
Image upload field.
Instance Attribute Summary
Attributes inherited from Field
#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #turbolink, #url, #value, #width
Instance Method Summary collapse
- #edit_element(val) ⇒ Object
-
#initialize(h = {}) ⇒ ImageField
constructor
A new instance of ImageField.
- #view_element(val) ⇒ Object
Methods inherited from SimpleField
Methods inherited from Field
#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html
Methods included from Html
Methods included from Utils
extract_value, number_format, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ ImageField
Returns a new instance of ImageField.
384 385 386 387 388 389 390 |
# File 'lib/forma/field.rb', line 384 def initialize(h = {}) h = h.symbolize_keys @popover = h[:popover] @height = h[:height] || 200 @width = h[:width] || 200 super(h) end |
Instance Method Details
#edit_element(val) ⇒ Object
407 408 409 |
# File 'lib/forma/field.rb', line 407 def edit_element(val) el('input', attrs: { name: parameter_name, type: 'file' }) end |
#view_element(val) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/forma/field.rb', line 392 def view_element(val) popover_data = {} image_url = val.respond_to?(:url) ? val.url : val.to_s if @popover popover_data['data-original-title'] = eval_with_model(@popover[:title]) url = eval_with_model(@popover[:url]) popover_data['data-content'] = %Q{<div style="height: #{@height}px; width: #{@width}px;"><img src="#{url}"></img></div>} popover_data['data-html'] = 'true' popover_data['data-placement'] = @popover[:placement] el('img', attrs: { src: image_url, class: 'ff-popover' }.merge(popover_data)) else el('img', attrs: { src: image_url }) end end |