Class: Forma::MapField

Inherits:
Field
  • Object
show all
Defined in:
lib/forma/field.rb

Overview

Map field.

Instance Attribute Summary

Attributes inherited from Field

#actions, #after, #autofocus, #before, #child_model_name, #hint, #i18n, #icon, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #url

Instance Method Summary collapse

Methods inherited from Field

#action, #id, #initialize, #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

This class inherits a constructor from Forma::Field

Instance Method Details

#edit_element(val) ⇒ Object



204
205
206
207
208
209
210
211
212
# File 'lib/forma/field.rb', line 204

def edit_element(val)
  el('div', attrs: { style: { width: "#{self.width}px", height: "#{self.height}px", position: 'relative' } }, children: [
    el('div', attrs: { id: self.id, class: 'ff-map' }),
    # google_import,
    map_display(val, true),
    el('input', attrs: { name: latitude_name, id: "#{self.id}_latitude", value: val[0], type: 'hidden' }),
    el('input', attrs: { name: longitude_name, id: "#{self.id}_longitude", value: val[1], type: 'hidden' }),
  ])
end

#heightObject



194
# File 'lib/forma/field.rb', line 194

def height; @height || 500 end

#valueObject



183
184
185
186
187
188
189
190
191
# File 'lib/forma/field.rb', line 183

def value
  val = super
  if val then val
  else
    lat  = extract_value(self.model, "#{self.name}_latitude")  || Forma.config.map.default_latitude
    long = extract_value(self.model, "#{self.name}_longitude") || Forma.config.map.default_longitude
    [ lat, long ]
  end
end

#view_element(val) ⇒ Object



196
197
198
199
200
201
202
# File 'lib/forma/field.rb', line 196

def view_element(val)
  el('div', attrs: { style: { width: "#{self.width}px", height: "#{self.height}px", position: 'relative' } }, children: [
    el('div', attrs: { id: self.id, class: 'ff-map' }),
    # google_import,
    map_display(val, false)
  ])
end

#widthObject



193
# File 'lib/forma/field.rb', line 193

def width; @width || 500 end