diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/stylesheets/main/time_tables.sass | 5 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 30 | ||||
| -rw-r--r-- | app/models/calendar.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 2 | ||||
| -rw-r--r-- | app/views/time_tables/_form.html.slim | 14 | ||||
| -rw-r--r-- | app/views/time_tables/_show_time_table.html.slim | 9 |
6 files changed, 50 insertions, 11 deletions
diff --git a/app/assets/stylesheets/main/time_tables.sass b/app/assets/stylesheets/main/time_tables.sass index b24a02c27..de2ae8253 100644 --- a/app/assets/stylesheets/main/time_tables.sass +++ b/app/assets/stylesheets/main/time_tables.sass @@ -61,6 +61,9 @@ .actions float: right + #associated_calendars + padding-top: 15px + #workspace.time_tables.edit, #workspace.time_tables.new, #workspace.time_tables.create, @@ -129,4 +132,4 @@ background: url(image-path('icons/remove.png')) no-repeat 0% 50% .actions - margin-top: 20px
\ No newline at end of file + margin-top: 20px 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 diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 54237e9cc..641f97302 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -1,5 +1,6 @@ class Calendar < ActiveRecord::Base belongs_to :organisation + has_many :time_tables validates_presence_of :name, :short_name, :organisation validates_uniqueness_of :short_name diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index abe6186a7..7afdc4529 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -17,6 +17,8 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord has_many :dates, -> {order(:date)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTableDate", :dependent => :destroy has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy + belongs_to :calendar + after_save :save_shortcuts def self.object_id_key diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index 7194ce363..8652f7cb5 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -5,9 +5,11 @@ = form.input :tag_search, as: :tags, :input_html => { :id => "tag_search",:placeholder => t("formtastic.placeholders.time_table.tag_search") } = form.input :tag_list, as: :hidden, :input_html => { :id => "tag_list" } = form.input :objectid, :required => !@time_table.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.objectid")} - + - if @time_table.new_record? + = form.input :calendar, as: :select, collection: current_organisation.calendars + h3.time_table_periods = @time_table.human_attribute_name("periods") - + #periods_content = form.inputs class: 'day_type' do label.day_type_label = @time_table.human_attribute_name("day_types") @@ -24,7 +26,7 @@ == render "period_fields", :f => p = link_to_add_association t("time_tables.actions.add_period"), form, :periods , :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "div#periods" - + h3.time_table_dates = @time_table.human_attribute_name("dates") #dates_content @@ -53,9 +55,9 @@ javascript: $("#tag_search").tagsManager({ prefilled: items, output: '#tag_list', - tagsContainer: '#tagsContainer' + tagsContainer: '#tagsContainer' }); - + var time_tables_tag_list = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), queryTokenizer: Bloodhound.tokenizers.whitespace, @@ -68,4 +70,4 @@ javascript: name: 'time_tables_tag_list', displayKey: 'name', source: time_tables_tag_list.ttAdapter() - });
\ No newline at end of file + }); diff --git a/app/views/time_tables/_show_time_table.html.slim b/app/views/time_tables/_show_time_table.html.slim index ccdc4187f..419d13c96 100644 --- a/app/views/time_tables/_show_time_table.html.slim +++ b/app/views/time_tables/_show_time_table.html.slim @@ -24,6 +24,13 @@ #my-tab-content.tab-content #time_tables.tab-pane.active + #associated_calendar + => "#{t('calendars.standard_calendar')} : " + - if @time_table.calendar + = link_to @time_table.calendar.name, @time_table.calendar + - else + = '--' + .well.legend span.title = t(".legend") span.label.excluded_date X @@ -84,4 +91,4 @@ - if @time_table.dates.where("in_out = false").present? h3.time_table_dates = @time_table.human_attribute_name("excluded_dates") .excluded_dates.content - == render "time_tables/excluded_dates"
\ No newline at end of file + == render "time_tables/excluded_dates" |
