diff options
| author | Michel Etienne | 2014-08-14 15:48:33 +0200 |
|---|---|---|
| committer | Michel Etienne | 2014-08-14 15:48:33 +0200 |
| commit | 11ffb51486eae01f6d9f571155d7afaec8826130 (patch) | |
| tree | 4ab94fc03249553aed8bb9e3b026c7d7fc7dd37a | |
| parent | 8157af57a17b75eb4e710de940b8fe15244bf561 (diff) | |
| download | chouette-core-11ffb51486eae01f6d9f571155d7afaec8826130.tar.bz2 | |
manage timetable combination modal form with ajax
| -rw-r--r-- | app/assets/javascripts/time_tables.js.coffee | 23 | ||||
| -rw-r--r-- | app/assets/stylesheets/main/time_tables.css.scss | 7 | ||||
| -rw-r--r-- | app/controllers/time_table_combinations_controller.rb | 16 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 1 | ||||
| -rw-r--r-- | app/models/time_table_combination.rb | 26 | ||||
| -rw-r--r-- | app/views/time_table_combinations/_combine.html.erb | 14 | ||||
| -rw-r--r-- | app/views/time_table_combinations/_combine_form.html.erb | 49 | ||||
| -rw-r--r-- | app/views/time_table_combinations/create.js.erb | 11 | ||||
| -rw-r--r-- | app/views/time_tables/_combine.html.erb | 37 | ||||
| -rw-r--r-- | app/views/time_tables/_show_time_table.html.erb | 127 | ||||
| -rw-r--r-- | app/views/time_tables/show.html.erb | 129 | ||||
| -rw-r--r-- | config/locales/time_table_combinations.yml | 3 | ||||
| -rw-r--r-- | config/locales/time_tables.yml | 10 |
13 files changed, 274 insertions, 179 deletions
diff --git a/app/assets/javascripts/time_tables.js.coffee b/app/assets/javascripts/time_tables.js.coffee index 71b9ca14f..75889bd3f 100644 --- a/app/assets/javascripts/time_tables.js.coffee +++ b/app/assets/javascripts/time_tables.js.coffee @@ -5,7 +5,28 @@ jQuery -> $('.time_tables .calendars.content').toggle('slow') $('a.calendars .switcher').toggle() - $('.time_tables a.calendars').click(switch_calendars) + $('.time_tables').on('click','a.calendars',switch_calendars) + + switch_dates = (event) -> + event.preventDefault() + $('.time_tables .dates.content').toggle('slow') + $('a.dates .switcher').toggle() + + $('.time_tables').on('click','a.dates',switch_dates) + + switch_excluded_dates = (event) -> + event.preventDefault() + $('.time_tables .excluded_dates.content').toggle('slow') + $('a.excluded_dates .switcher').toggle() + + $('.time_tables').on('click','a.excluded_dates',switch_excluded_dates) + + switch_periods = (event) -> + event.preventDefault() + $('.time_tables .periods.content').toggle('slow') + $('a.periods .switcher').toggle() + + $('.time_tables').on('click','a.periods',switch_periods) # add trigger when creating new date or period entries to activate datepicker tt_datepickerI18n = (index, element) -> diff --git a/app/assets/stylesheets/main/time_tables.css.scss b/app/assets/stylesheets/main/time_tables.css.scss index 4f8729076..0989b5745 100644 --- a/app/assets/stylesheets/main/time_tables.css.scss +++ b/app/assets/stylesheets/main/time_tables.css.scss @@ -38,8 +38,15 @@ } } + #workspace.time_tables.show { + .modal-body{overflow-y: visible;} + + .typeahead.dropdown-menu { + z-index: 100001; + } + .day_type { border-style:solid; border-width:1px; diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb index 2af3fe630..eb41dc2e1 100644 --- a/app/controllers/time_table_combinations_controller.rb +++ b/app/controllers/time_table_combinations_controller.rb @@ -1,24 +1,26 @@ class TimeTableCombinationsController < ChouetteController - respond_to :html, :only => [:create] + respond_to :js, :only => [:create] belongs_to :referential do belongs_to :time_table, :parent_class => Chouette::TimeTable end def create - combination = TimeTableCombination.new( params[:time_table_combination].merge( :source_id => parent.id)) - if combination.invalid? - flash[:error] = combination.errors.full_messages.join("<br/>") - else + @time_table_combination = TimeTableCombination.new( params[:time_table_combination].merge( :source_id => parent.id)) + @year = params[:year] ? params[:year].to_i : Date.today.cwyear + if @time_table_combination.valid? begin - combination.combine + @time_table_combination.combine flash[:notice] = t('time_table_combinations.success') rescue flash[:error] = t('time_table_combinations.failure') end + parent.reload end - redirect_to referential_time_table_path(@referential, @time_table) end + protected + + alias_method :time_table_combination, :resource end diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index ea08bb487..14cc7aa10 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -9,6 +9,7 @@ class TimeTablesController < ChouetteController def show @year = params[:year] ? params[:year].to_i : Date.today.cwyear + @time_table_combination = TimeTableCombination.new show! end diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb index d42a0aa49..26fb38fbe 100644 --- a/app/models/time_table_combination.rb +++ b/app/models/time_table_combination.rb @@ -3,10 +3,29 @@ class TimeTableCombination include ActiveModel::Conversion extend ActiveModel::Naming - attr_accessor :source_id, :combined_id, :operation + attr_accessor :source_id, :combined_id, :combined_name, :operation, :status - validates_presence_of :source_id, :combined_id, :operation + validates_presence_of :source_id, :combined_id, :operation, :combined_name validates_inclusion_of :operation, :in => %w( union intersection disjunction) + + def clean + self.source_id = nil + self.combined_id = nil + self.combined_name = nil + self.operation = nil + self.errors.clear + self.status = false + end + + def valid?(context = nil) + self.combined_name = nil if self.combined_id.blank? + super context + end + + def invalid?(context = nil) + self.combined_name = nil if self.combined_id.blank? + super context + end def self.operations %w( union intersection disjunction) @@ -16,6 +35,7 @@ class TimeTableCombination attributes.each do |name, value| send("#{name}=", value) end + self.status = false end def persisted? @@ -23,6 +43,7 @@ class TimeTableCombination end def combine + self.status = false source = Chouette::TimeTable.find( source_id) combined = Chouette::TimeTable.find( combined_id) if operation == "union" @@ -35,6 +56,7 @@ class TimeTableCombination raise "unknown operation" end source.save + self.status = true end end diff --git a/app/views/time_table_combinations/_combine.html.erb b/app/views/time_table_combinations/_combine.html.erb new file mode 100644 index 000000000..3257cf812 --- /dev/null +++ b/app/views/time_table_combinations/_combine.html.erb @@ -0,0 +1,14 @@ +<div id="combine_form" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> + <h4 class="modal-title" id="myModalLabel"><%= t('time_tables.show.combine_form') %></h4> + </div> + <% @time_table_combination.clean %> + <%= render "time_table_combinations/combine_form" %> + + </div> + </div> + +</div> diff --git a/app/views/time_table_combinations/_combine_form.html.erb b/app/views/time_table_combinations/_combine_form.html.erb new file mode 100644 index 000000000..f0dca6386 --- /dev/null +++ b/app/views/time_table_combinations/_combine_form.html.erb @@ -0,0 +1,49 @@ +<%= semantic_form_for [@referential, @time_table, @time_table_combination], :remote => true do |form| %> + <div class="modal-body"> + <%= render "shared/flash_messages" %> + <%= form.inputs do %> + <%= form.input :operation, :as => :radio, :collection => Hash[TimeTableCombination.operations.map {|b| [t( b, :scope => "time_table_combinations.operations"),b]}] %> + <%= form.input :combined_name, :class => "typeahead form-control input-lg" %> + <%= form.input :combined_id, :as => :hidden %> + <% end %> + </div> + <div class="modal-footer"> + <%= form.actions do %> + <%= form.action :submit, :as => :button , :label => t('time_tables.show.combine')%> + <% end %> + </div> + +<script> + $(function() { + var timeTableSuggestion = new Bloodhound({ + datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), + queryTokenizer: Bloodhound.tokenizers.whitespace, + limit: 12, + remote: { + url: '<%= comment_filter_referential_time_tables_path(@referential, :format => :json) %>', + }, + }); + + timeTableSuggestion.initialize(); + + $('#time_table_combination_combined_name').typeahead( + { + hint: true, + highlight: true, + minLength: 1 + }, + { + name: 'comment', + displayKey: 'name', + source: timeTableSuggestion.ttAdapter() + } + ); + + $('#time_table_combination_combined_name').on('typeahead:selected', function($e, datum) + { + $('input[name="time_table_combination[combined_id]"]').val(datum.id); + }) + + }); +</script> +<% end %> diff --git a/app/views/time_table_combinations/create.js.erb b/app/views/time_table_combinations/create.js.erb new file mode 100644 index 000000000..06655deea --- /dev/null +++ b/app/views/time_table_combinations/create.js.erb @@ -0,0 +1,11 @@ + +var combine_form_partial = '<%= j render "time_table_combinations/combine_form" %> '; + +$('#new_time_table_combination').replaceWith(combine_form_partial); + +<% if @time_table_combination.status %> + +var time_table_partial = '<%= j render "time_tables/show_time_table" %> '; +$('#time_table_show').replaceWith(time_table_partial); + +<% end %> diff --git a/app/views/time_tables/_combine.html.erb b/app/views/time_tables/_combine.html.erb deleted file mode 100644 index 8e375a10b..000000000 --- a/app/views/time_tables/_combine.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<div id="combine_form" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> -<div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> - <h4 class="modal-title" id="myModalLabel"><%= t('time_tables.show.combine_form') %></h4> - </div> - <%= semantic_form_for [@referential, @time_table, TimeTableCombination.new] do |form| %> - <div class="modal-body"> - <%= form.inputs do %> - <%= form.input :operation, :as => :radio, :collection => Hash[TimeTableCombination.operations.map {|b| [t( b, :scope => "time_table_combinations.operations"),b]}] %> - <%= form.input :combined_id, :as => :text %> - <% end %> - </div> - <div class="modal-footer"> - <%= form.actions do %> - <%= form.action :submit, :as => :button , :label => t('time_tables.show.combine')%> - <% end %> - </div> - <% end %> - </div> - </div> -</div> - -<script> - $(function() { - $( "#time_table_combination_combined_id" ).tokenInput('<%= comment_filter_referential_time_tables_path(@referential, :format => :json) %>', { - crossDomain: false, - prePopulate: $('#time_table_combination_combined_id').data('pre'), - tokenLimit: 1, - minChars: 1, - hintText: '<%= t('search_hint') %>', - noResultsText: '<%= t('no_result_text') %>', - searchingText: '<%= t('searching_term') %>' - }); - }); -</script> diff --git a/app/views/time_tables/_show_time_table.html.erb b/app/views/time_tables/_show_time_table.html.erb new file mode 100644 index 000000000..71fe973c9 --- /dev/null +++ b/app/views/time_tables/_show_time_table.html.erb @@ -0,0 +1,127 @@ +<div class="time_table_show" id="time_table_show"> + + <div class="resume"> + <div class="validity <%= time_table_state_code(@time_table) %>"></div> + <label> + <% if @time_table.bounding_dates.empty? %> + <%= t(".resume_empty") %> + <% else %> + <%= t(".resume", :start_date => l(@time_table.bounding_dates.min), + :end_date => l(@time_table.bounding_dates.max)) %> + <% end %> + </label> + </div> + <div class="summary"> + <p> + <label><%= @time_table.human_attribute_name("version") %>: </label> + <%= @time_table.version %> + </p> + <p> + <label><%= @time_table.human_attribute_name("tag_list") %>: </label> + <%= @time_table.tag_list %> + </p> + <p> + <label><%= @time_table.human_attribute_name("day_types") %>: </label> + <% if @time_table.int_day_types & 508 == 0 %> + <label><%= @time_table.human_attribute_name("none") %></label> + <% else %> + <% if @time_table.monday %> + <span class='day_type'> <%= @time_table.human_attribute_name("monday") %> </span> + <% end %> + + <% if @time_table.tuesday %> + <span class='day_type'> <%= @time_table.human_attribute_name("tuesday") %> </span> + <% end %> + + <% if @time_table.wednesday %> + <span class='day_type'> <%= @time_table.human_attribute_name("wednesday") %> </span> + <% end %> + + <% if @time_table.thursday %> + <span class='day_type'> <%= @time_table.human_attribute_name("thursday") %> </span> + <% end %> + + <% if @time_table.friday %> + <span class='day_type'> <%= @time_table.human_attribute_name("friday") %> </span> + <% end %> + + <% if @time_table.saturday %> + <span class='day_type'> <%= @time_table.human_attribute_name("saturday") %> </span> + <% end %> + + <% if @time_table.sunday %> + <span class='day_type'> <%= @time_table.human_attribute_name("sunday") %> </span> + <% end %> + <% end %> + </p> + + <h3 class="time_table_calendars"> + <a class="calendars"><%= @time_table.human_attribute_name("calendars") %> + <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> + <%= image_tag("icons/minus.png" , :class => "switcher" ) %> + </a> + + </h3> + <div class="calendars content"> + <div class="year_choice"> + <span class="previous"> <%= link_to("<", referential_time_table_path(@referential, @time_table, :year => (@year - 1)) ) %> </span> + <span class="year"> <%= "#{@year}" %> </span> + <span class="next"> <%= link_to(">", referential_time_table_path(@referential, @time_table, :year => (@year + 1)) ) %> </span> + </div> + <div class="calendar_helper"> + <%= cal = "" + (1..12).each do |month| + cal << calendar(:year => @year, :month => month, :first_day_of_week => 1) do |d| + if @time_table.excluded_date?(d) + [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "excluded_date"}] + elsif @time_table.include_in_overlap_dates?(d) + [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "overlap_date"}] + elsif @time_table.include_in_dates?(d) + [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "selected_date"}] + elsif @time_table.include_in_periods?(d) + [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "selected_period"}] + end + end + end + cal.html_safe + %> + </div> + </div> + + + </div> + <h3 class="time_table_periods"> + <a class="periods"><%= @time_table.human_attribute_name("periods") %> + <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> + <%= image_tag("icons/minus.png" , :class => "switcher" ) %> + </a> + + </h3> + <div class="periods content"> + <%= render "time_tables/periods" %> + </div> + + <h3 class="time_table_dates"> + <a class="dates"><%= @time_table.human_attribute_name("dates") %> + <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> + <%= image_tag("icons/minus.png" , :class => "switcher" ) %> + </a> + </h3> + + <div class="dates content"> + <%= render "time_tables/dates" %> + </div> + + <h3 class="time_table_dates"> + <a class="excluded_dates"><%= @time_table.human_attribute_name("excluded_dates") %> + <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> + <%= image_tag("icons/minus.png" , :class => "switcher" ) %> + </a> + </h3> + + <div class="excluded_dates content"> + <%= render "time_tables/excluded_dates" %> + </div> + +</div> + diff --git a/app/views/time_tables/show.html.erb b/app/views/time_tables/show.html.erb index 3a8e75124..b5c5c9dfe 100644 --- a/app/views/time_tables/show.html.erb +++ b/app/views/time_tables/show.html.erb @@ -5,134 +5,9 @@ <%= title_tag t('time_tables.show.title', :time_table => @time_table.comment )%> -<%= render "combine" %> +<%= render "time_table_combinations/combine" %> -<div class="time_table_show"> - - <div class="resume"> - <div class="validity <%= time_table_state_code(@time_table) %>"></div> - <label> - <% if @time_table.bounding_dates.empty? %> - <%= t(".resume_empty") %> - <% else %> - <%= t(".resume", :start_date => l(@time_table.bounding_dates.min), - :end_date => l(@time_table.bounding_dates.max)) %> - <% end %> - </label> - </div> - <div class="summary"> - <p> - <label><%= @time_table.human_attribute_name("version") %>: </label> - <%= @time_table.version %> - </p> - <p> - <label><%= @time_table.human_attribute_name("tag_list") %>: </label> - <%= @time_table.tag_list %> - </p> - <p> - <label><%= @time_table.human_attribute_name("day_types") %>: </label> - <% if @time_table.int_day_types & 508 == 0 %> - <label><%= @time_table.human_attribute_name("none") %></label> - <% else %> - <% if @time_table.monday %> - <span class='day_type'> <%= @time_table.human_attribute_name("monday") %> </span> - <% end %> - - <% if @time_table.tuesday %> - <span class='day_type'> <%= @time_table.human_attribute_name("tuesday") %> </span> - <% end %> - - <% if @time_table.wednesday %> - <span class='day_type'> <%= @time_table.human_attribute_name("wednesday") %> </span> - <% end %> - - <% if @time_table.thursday %> - <span class='day_type'> <%= @time_table.human_attribute_name("thursday") %> </span> - <% end %> - - <% if @time_table.friday %> - <span class='day_type'> <%= @time_table.human_attribute_name("friday") %> </span> - <% end %> - - <% if @time_table.saturday %> - <span class='day_type'> <%= @time_table.human_attribute_name("saturday") %> </span> - <% end %> - - <% if @time_table.sunday %> - <span class='day_type'> <%= @time_table.human_attribute_name("sunday") %> </span> - <% end %> - <% end %> - </p> - - <h3 class="time_table_calendars"> - <a class="calendars"><%= @time_table.human_attribute_name("calendars") %> - <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> - <%= image_tag("icons/minus.png" , :class => "switcher" ) %> - </a> - - </h3> - <div class="calendars content"> - <div class="year_choice"> - <span class="previous"> <%= link_to("<", referential_time_table_path(@referential, @time_table, :year => (@year - 1)) ) %> </span> - <span class="year"> <%= "#{@year}" %> </span> - <span class="next"> <%= link_to(">", referential_time_table_path(@referential, @time_table, :year => (@year + 1)) ) %> </span> - </div> - <div class="calendar_helper"> - <%= cal = "" - (1..12).each do |month| - cal << calendar(:year => @year, :month => month, :first_day_of_week => 1) do |d| - if @time_table.excluded_date?(d) - [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "excluded_date"}] - elsif @time_table.include_in_overlap_dates?(d) - [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "overlap_date"}] - elsif @time_table.include_in_dates?(d) - [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "selected_date"}] - elsif @time_table.include_in_periods?(d) - [link_to(d.mday, edit_referential_time_table_path(@referential, @time_table) ), {:class => "selected_period"}] - end - end - end - cal.html_safe - %> - </div> - </div> - - - </div> - <h3 class="time_table_periods"> - <a class="periods"><%= @time_table.human_attribute_name("periods") %> - <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> - <%= image_tag("icons/minus.png" , :class => "switcher" ) %> - </a> - - </h3> - <div class="periods content"> - <%= render "periods" %> - </div> - - <h3 class="time_table_dates"> - <a class="dates"><%= @time_table.human_attribute_name("dates") %> - <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> - <%= image_tag("icons/minus.png" , :class => "switcher" ) %> - </a> - </h3> - - <div class="dates content"> - <%= render "dates" %> - </div> - - <h3 class="time_table_dates"> - <a class="excluded_dates"><%= @time_table.human_attribute_name("excluded_dates") %> - <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> - <%= image_tag("icons/minus.png" , :class => "switcher" ) %> - </a> - </h3> - - <div class="excluded_dates content"> - <%= render "excluded_dates" %> - </div> - -</div> +<%= render "show_time_table" %> <% content_for :sidebar do %> <ul class="actions"> diff --git a/config/locales/time_table_combinations.yml b/config/locales/time_table_combinations.yml index b224a7e12..ff15f33e2 100644 --- a/config/locales/time_table_combinations.yml +++ b/config/locales/time_table_combinations.yml @@ -22,6 +22,7 @@ fr: activemodel: attributes: time_table_combination: - combined_id: "Calendrier à combiner" + combined_name: "Calendrier à combiner" + combined_id: "Id Calendrier" operation: "opération" diff --git a/config/locales/time_tables.yml b/config/locales/time_tables.yml index cb8b834fc..5742b7e30 100644 --- a/config/locales/time_tables.yml +++ b/config/locales/time_tables.yml @@ -23,8 +23,6 @@ en: edit: title: "Update timetable %{time_table}" show: - resume: "From %{start_date} to %{end_date}" - resume_empty: "Empty timetable" title: "Timetable %{time_table}" dates: "Application dates" periods: "Application periods" @@ -34,6 +32,9 @@ en: add_date: "Add a date" combine_form: "Combinations" combine: "Apply" + show_time_table: + resume: "From %{start_date} to %{end_date}" + resume_empty: "Empty timetable" index: title: "Timetables" comment: "Search by name" @@ -108,8 +109,6 @@ fr: edit: title: "Modifier le calendrier %{time_table}" show: - resume: "Validité comprise du %{start_date} au %{end_date}" - resume_empty: "Calendrier vide" title: Calendrier %{time_table} dates: "Dates d'application" periods: "Périodes d'application" @@ -119,6 +118,9 @@ fr: add_date: "Ajouter une date" combine_form: "Combinaison de calendriers" combine: "Appliquer" + show_time_table: + resume: "Validité comprise du %{start_date} au %{end_date}" + resume_empty: "Calendrier vide" index: comment: "Recherche par nom" tag_search: "Tags : vacances,jour fériés" |
