Module: Base::Project::App::Helpers::LocalizableHelper

Defined in:
lib/base/project/app/helpers/localizable_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_localization(location) ⇒ Object



8
9
10
# File 'lib/base/project/app/helpers/localizable_helper.rb', line 8

def add_localization(location)
  add_localizations([location]) if location
end

#add_localizations(locations) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/base/project/app/helpers/localizable_helper.rb', line 12

def add_localizations(locations)
  return '' if locations.blank?

  js_locations = []
  first_location = locations.first

  been_img = image_url('map/been.png')
  current_img = image_url('map/employee.png')

  locations.each do |location|
    coordinates = prepare_coordinates(location)
    next if coordinates.blank?

    if location != first_location
      image = been_img
      current = true
    else
      image = current_img
      current = false
    end

    location_id = "loc-#{location.id}"

    js_locations << "window.map.addCoordinate({
      coordinates: #{coordinates},
      icon: '#{image}',
      locationId: '#{location_id}',
      visited: #{current},
      period: true,
      properties: { title: '#{location.name}', icon: '#{image}' }
    });"
  end

  js_locations << "window.map.getMap().setCenter(#{prepare_coordinates(first_location)});"
  js_locations << 'window.map.getMap().setZoom(15);'

  result = js_locations.join("\n")
  result.html_safe
end

#prepare_coordinates(location) ⇒ Object



3
4
5
6
# File 'lib/base/project/app/helpers/localizable_helper.rb', line 3

def prepare_coordinates(location)
  coordinate_array = location.coordinates
  coordinate_array.present? ? escape_javascript(coordinate_array.to_json).to_s : ''
end