aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/connection_links_controller.rb
blob: a7f9758e890eb0f94ba744f677437f60deb09ddf (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
class ConnectionLinksController < ChouetteController
  include ReferentialSupport
  defaults :resource_class => Chouette::ConnectionLink

  belongs_to :referential do
    belongs_to :departure, :parent_class => Chouette::StopArea, :optional => true
    belongs_to :arrival, :parent_class => Chouette::StopArea, :optional => true
  end

  respond_to :html, :xml, :json
  respond_to :kml, :only => :show
  respond_to :js, :only => :index

  include PolicyChecker

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

  def show
    show!
  end

  def select_areas
    @connection_link = connection_link
    @departure = connection_link.departure
    @arrival = connection_link.arrival
  end

  protected

  alias_method :connection_link, :resource

  def collection
    @q = referential.connection_links.search(params[:q])
    @connection_links ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page])
  end

  def resource_url(connection_link = nil)
    referential_connection_link_path(referential, connection_link || resource)
  end

  def collection_url
    referential_connection_links_path(referential)
  end

  private

  def connection_link_params
    params.require(:connection_link).permit( :connection_link_type,:departure_id, :arrival_id, :objectid, :object_version, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs )
  end

end