Class: Forma::ArrayField

Inherits:
SimpleField show all
Defined in:
lib/forma/field.rb

Overview

Array 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

Methods inherited from SimpleField

#errors, #has_errors?, #value

Methods inherited from Field

#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html

Methods included from Html

attr, el

Methods included from Utils

extract_value, number_format, #simple_value, singular_name

Constructor Details

#initialize(h = {}) ⇒ ArrayField

Returns a new instance of ArrayField.



478
479
480
481
482
483
# File 'lib/forma/field.rb', line 478

def initialize(h={})
  h = h.symbolize_keys
  @item_actions = h[:item_actions] || []
  @item_url = h[:item_url]
  super(h)
end

Instance Method Details

#edit_element(val) ⇒ Object



494
495
496
# File 'lib/forma/field.rb', line 494

def edit_element(val)
  el('div', text: 'NO IMPLEMENTATION')
end

#item_action(url, h = {}) ⇒ Object



498
499
500
501
# File 'lib/forma/field.rb', line 498

def item_action(url, h={})
  h[:url] = url
  @item_actions << Action.new(h)
end

#view_element(val) ⇒ Object



485
486
487
488
489
490
491
492
# File 'lib/forma/field.rb', line 485

def view_element(val)
  el('div', attrs: { class: ['ff-array-field'] }, children: val.map { |x| 
    el('div', attrs: { class: 'ff-array-part' }, children: [
      if @item_url then el('a', attrs: { href: eval_with_model(@item_url, model: x) }, text: x.to_s) else el('span', text: x.to_s) end,
      (el('span', attrs: { class: 'ff-actions' }, children: @item_actions.map { |a| a.to_html(x) } ) if @item_actions.any?)
    ])
  })
end