aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/access_points_controller.rb
blob: 112a13a864791e2e41a0f8e1e8a897fa1164b5be (plain)
1
2
3
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
68
69
70
class AccessPointsController < ChouetteController
  include ReferentialSupport
  defaults :resource_class => Chouette::AccessPoint

  belongs_to :referential do
    belongs_to :stop_area, :parent_class => Chouette::StopArea, :optional => true, :polymorphic => true
  end

  respond_to :html, :kml, :xml, :json
  include PolicyChecker

  def index
    request.format.kml? ? @per_page = nil : @per_page = 12

    index! do |format|
      format.html {
        if collection.out_of_bounds?
          redirect_to params.merge(:page => 1)
        end
      }
    end
  end

  def show
    map.editable = false
    @generic_access_links = @access_point.generic_access_link_matrix
    @detail_access_links = @access_point.detail_access_link_matrix
    show! do |format|
      unless access_point.position or params[:default]
        format.kml {
          render :nothing => true, :status => :not_found
        }

      end
    end
  end


  def edit
    access_point.position ||= access_point.default_position
    map.editable = true
    edit!
  end


  protected

  alias_method :access_point, :resource

  def map
    @map = AccessPointMap.new(access_point).with_helpers(self)
  end

  def collection
    @q = parent.access_points.search(params[:q])
    @access_points ||=
      begin
        access_points = @q.result(:distinct => true).order(:name)
        access_points = access_points.paginate(:page => params[:page]) if @per_page.present?
        access_points
      end
  end

  private

  def access_point_params
    params.require(:access_point).permit( :objectid, :object_version, :name, :comment, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :openning_time, :closing_time, :access_type, :access_point_type, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :stop_area_id, :coordinates )
  end

end