4
5
6
7
8
9
10
11
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/controllers/c80_map/map_ajax_controller.rb', line 4
def save_map_data
result = {
areas: [],
buildings: [],
updated_locations_json: nil
}
if params[:buildings].present?
params[:buildings].each_key do |key|
new_building_options = params[:buildings][key]
b = Building.new({ coords: new_building_options[:coords].join(',') })
if b.valid?
b.save
result[:buildings] << { id: b.id, old_temp_id: new_building_options["id"] }
else
result[:buildings] << { id: new_building_options.id, status: 'error' }
end
end
end
if params[:areas].present?
params[:areas].each_key do |key|
new_area_options = params[:areas][key]
a = Area.new({
coords: new_area_options[:coords].join(','),
building_id: new_area_options[:parent_building_id]
})
if a.valid?
a.save
result[:areas] << { id: a.id, old_temp_id: new_area_options["id"] }
else
result[:areas] << { id: new_area_options.id, status: 'error' }
end
end
end
result[:updated_locations_json] = MapJson.fetch_json
puts "<MapAjaxController.save_map_data> result = #{result.to_json}"
respond_to do |format|
format.json { render json: result }
end
end
|