class Forma::MapField
Map field.
Public Instance Methods
edit_element(val)
click to toggle source
# File lib/forma/field.rb, line 209 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
height()
click to toggle source
# File lib/forma/field.rb, line 199 def height; @height || 500 end
value()
click to toggle source
Calls superclass method
# File lib/forma/field.rb, line 188 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)
click to toggle source
# File lib/forma/field.rb, line 201 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
width()
click to toggle source
# File lib/forma/field.rb, line 198 def width; @width || 500 end
Private Instance Methods
latitude_name()
click to toggle source
# File lib/forma/field.rb, line 231 def latitude_name "#{name_as_chain[0]}[#{name_as_chain[1]}_latitude]" end
longitude_name()
click to toggle source
# File lib/forma/field.rb, line 235 def longitude_name "#{name_as_chain[0]}[#{name_as_chain[1]}_longitude]" end
map_display(val, edit)
click to toggle source
# File lib/forma/field.rb, line 221 def map_display(val, edit) longLat = "{ latitude: #{val[0]}, longitude: #{val[1]} }" zoom_level = Forma.config.map.zoom_level el( 'script', attrs: { type: 'text/javascript' }, html: %Q{ forma.registerGoogleMap('#{self.id}', #{zoom_level}, #{longLat}, [ #{longLat} ], #{edit}); } ) end