Module: Ropenlayer::FormBuilder

Defined in:
lib/ropenlayer/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#map_localization(options = {}, map_div_options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ropenlayer/form_builder.rb', line 4

def map_localization(options = {}, map_div_options = {})
  self.object.ensure_mapper_model
  self.object.ensure_localizable_model
  
  return_tag = ''

  
  dom_id_map   = "ropenlayer_#{ @template.params[:action] }_#{ @template.params[:controller] }"
  klass_config = self.object.class.ropenlayer_mapper_config.merge({:map_js_options => { :eventListeners => "{ 'moveend': #{ dom_id_map }EventHandler, 'zoomend': #{ dom_id_map }EventHandler }"}})
  map          = self.object.build_ropenlayer_map(dom_id_map, klass_config)

  map_div_options.merge!(:id => dom_id_map)
  
  
  [ :longitude , :latitude, :zoom ].each do |data|
    id_hidden_value                     = "#{ self.object.class.name.underscore }_#{ klass_config[data] }"
    map.form_localizations_fields[data] = id_hidden_value
    return_tag << hidden_field(klass_config[data], :id => id_hidden_value)
  end
    
  return_tag << localization_helper(map)
  return_tag << "#{ @template.("div", '', map_div_options) } #{ @template.javascript_tag map.to_js }" 
  @template.raw  return_tag 
end

#map_nodes_editor(mapper_relation, options = {}, map_div_options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ropenlayer/form_builder.rb', line 30

def map_nodes_editor(mapper_relation, options = {}, map_div_options = {})
  self.object.ensure_nodeable_model
  mapper = self.object.send(mapper_relation)
  mapper.ensure_mapper_model
  
  mapper_config   = mapper.class.ropenlayer_mapper_config
  nodeable_config = self.object.class.ropenlayer_node_config
  
  mapper_config.merge!(options)
  mapper_config.merge!(:edit_map => true)
  
  dom_id_map   = "ropenlayer_#{ mapper.class }_#{ @template.params[:action] }_#{ @template.params[:controller] }"
  map         = mapper.build_ropenlayer_map(dom_id_map, mapper_config)
  
  map_div_options.merge!(:id => dom_id_map)
  
  
  return_tag = '' 
  
  self.object.node ||= self.object.build_node # FIXME has_many relation!
  
  self.fields_for :node do |node_form|
    return_tag << node_form.hidden_field(:geometry_string)
  end
  
  return_tag << @template.javascript_tag("#{ map.js_helper.create_new_feature_callback(map, self) }") unless map.options[:add_feature_callback] != map.class::DEFAULT_ADD_FEATURE_CALLBACK
  return_tag << "#{ @template.("div", '', map_div_options) }#{ @template.javascript_tag map.to_js }" 
  
  @template.raw  return_tag
end