diff options
| author | Vlatka Pavisic | 2017-01-06 17:42:46 +0100 | 
|---|---|---|
| committer | Vlatka Pavisic | 2017-01-06 17:42:59 +0100 | 
| commit | 51534c59d3ddebf72a186cfc120d0481fab95d78 (patch) | |
| tree | 24ed8f0c7d5e8a8bfdb2d86d0f441002c17226f9 /app/controllers/time_tables_controller.rb | |
| parent | b6cd50e722136033c0e579ebfadd855d5fe7de7d (diff) | |
| download | chouette-core-51534c59d3ddebf72a186cfc120d0481fab95d78.tar.bz2 | |
Refs #2347 : TimeTable with Calendar
Diffstat (limited to 'app/controllers/time_tables_controller.rb')
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 30 | 
1 files changed, 27 insertions, 3 deletions
| diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 5ebd3c5c3..10e1e76dc 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -9,7 +9,6 @@ class TimeTablesController < ChouetteController    belongs_to :referential    def show -      @year = params[:year] ? params[:year].to_i : Date.today.cwyear      @time_table_combination = TimeTableCombination.new      show! do @@ -24,6 +23,25 @@ class TimeTablesController < ChouetteController      end    end +  def create +    tt_params = time_table_params +    if tt_params[:calendar_id] +      %i(monday tuesday wednesday thursday friday saturday sunday).map { |d| tt_params[d] = true } +      calendar = current_organisation.calendars.find_by_id(tt_params[:calendar_id]) +      tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes) +    end +    @time_table = Chouette::TimeTable.new(tt_params) +    if calendar +      calendar.dates.each_with_index do |date, i| +        @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i) +      end +      calendar.date_ranges.each_with_index do |date_range, i| +        @time_table.periods << Chouette::TimeTablePeriod.new(period_start: date_range.begin, period_end: date_range.end, position: i) +      end +    end +    create! +  end +    def edit      edit! do        build_breadcrumb :edit @@ -31,6 +49,12 @@ class TimeTablesController < ChouetteController      end    end +  def update +    @time_table = Chouette::TimeTable.find_by_id(params[:id]) +    @time_table.calendar_id = nil +    update! +  end +    def index      request.format.kml? ? @per_page = nil : @per_page = 12 @@ -89,8 +113,8 @@ class TimeTablesController < ChouetteController    end    private -   +    def time_table_params -    params.require(:time_table).permit( :objectid, :object_version, :creation_time, :creator_id, :version, :comment, :int_day_types, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, :tag_list, :tag_search ) +    params.require(:time_table).permit( :objectid, :object_version, :creation_time, :creator_id, :calendar_id, :version, :comment, :int_day_types, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, :tag_list, :tag_search )    end  end | 
