aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/time_tables_controller.rb
blob: b860d2948ed24e57f571d4c5492ad46f379ca5da (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
class TimeTablesController < ChouetteController
  defaults :resource_class => Chouette::TimeTable
  respond_to :html
  respond_to :xml
  respond_to :json

  belongs_to :referential

  def comment_filter
    respond_to do |format|  
      format.json { render :json => filtered_time_tables_maps}  
    end  
    
  end

  protected

  def filtered_time_tables_maps
    filtered_time_tables.collect do |time_table|
      { :id => time_table.id.to_s, :name => time_table.comment }
    end
  end
  def filtered_time_tables
    referential.time_tables.select{ |t| t.comment =~ /#{params[:q]}/i  }
  end

  def collection    
    @q = referential.time_tables.search(params[:q])
    @time_tables ||= @q.result(:distinct => true).order(:comment).paginate(:page => params[:page], :per_page => 10)
  end

  def resource_url(time_table = nil)
    referential_time_table_path(referential, time_table || resource)
  end

  def collection_url
    referential_time_tables_path(referential)
  end
end