diff options
| author | Xinhui | 2017-05-19 16:47:48 +0200 |
|---|---|---|
| committer | Xinhui | 2017-05-19 16:51:37 +0200 |
| commit | 96f12acb6a122c8549e00f04c953e51f5212a6cf (patch) | |
| tree | e54fe64ec467c2c5930db4aafe6917a14cbcbf4e | |
| parent | 4c1a2a33fde5b29f3b4c4024281ad80277a967d5 (diff) | |
| download | chouette-core-96f12acb6a122c8549e00f04c953e51f5212a6cf.tar.bz2 | |
Templating select2 time_table_combination + refactoring
Refs #3406
| -rw-r--r-- | app/assets/javascripts/select2.coffee | 4 | ||||
| -rw-r--r-- | app/assets/javascripts/time_table_combinations.coffee | 8 | ||||
| -rw-r--r-- | app/controllers/autocomplete_calendars_controller.rb | 7 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 1 | ||||
| -rw-r--r-- | app/models/time_table_combination.rb | 2 | ||||
| -rw-r--r-- | app/views/autocomplete_calendars/autocomplete.rabl | 5 | ||||
| -rw-r--r-- | app/views/time_table_combinations/_form.html.slim | 7 | ||||
| -rw-r--r-- | config/routes.rb | 4 | ||||
| -rw-r--r-- | spec/controllers/autocomplete_calendars_controller_spec.rb | 5 |
9 files changed, 33 insertions, 10 deletions
diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee index 510e6fe9b..6771a7d05 100644 --- a/app/assets/javascripts/select2.coffee +++ b/app/assets/javascripts/select2.coffee @@ -29,12 +29,12 @@ bind_select2_ajax = (el, cfg = {}) -> select2_time_table = (item) -> return item.text if item.loading wrap = $('<div>', "class":'select2-result clearfix') - wrap.html(["<h5>Time table : #{item.comment}</h5>"].join("\n")) + wrap.html(["<h5>#{item.comment}</h5>"].join("\n")) select2_calendar = (item) -> return item.text if item.loading wrap = $('<div>', "class":'select2-result clearfix') - wrap.html(["<h5>Calendar : #{item.name}</h5>"].join("\n")) + wrap.html(["<h5>#{item.name}</h5>"].join("\n")) @select_2 = -> diff --git a/app/assets/javascripts/time_table_combinations.coffee b/app/assets/javascripts/time_table_combinations.coffee new file mode 100644 index 000000000..8fd9dadb1 --- /dev/null +++ b/app/assets/javascripts/time_table_combinations.coffee @@ -0,0 +1,8 @@ +$(document).on("change", '#time_table_combination_combined_type', (e) -> + el = $("#time_table_combination_#{$(this).val()}_id") + other = $(".tt_combination_target:not(##{el.attr('id')})") + + if el.length + el.prop('disabled', false).parents('.form-group').removeClass('hidden').show() + other.prop('disabled', true).parents('.form-group').hide() +) diff --git a/app/controllers/autocomplete_calendars_controller.rb b/app/controllers/autocomplete_calendars_controller.rb new file mode 100644 index 000000000..dbdd1a9fc --- /dev/null +++ b/app/controllers/autocomplete_calendars_controller.rb @@ -0,0 +1,7 @@ +class AutocompleteCalendarsController < ApplicationController + respond_to :json, :only => [:autocomplete] + + def autocomplete + @calendars = Calendar.search(params[:q]).result.paginate(page: params[:page]) + end +end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 0ddfa14bf..7cbc4fe8b 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -499,7 +499,6 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord add_included_day d end end - self.convert_continuous_dates_to_periods end # if remained excluded dates are valid in other tt , remove it from result self.dates.each do |date| diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb index d7e16665c..ec3c74641 100644 --- a/app/models/time_table_combination.rb +++ b/app/models/time_table_combination.rb @@ -16,7 +16,7 @@ class TimeTableCombination def clean self.source_id = nil self.time_table_id = nil - self.calendar = nil + self.calendar_id = nil self.combined_type = nil self.operation = nil self.errors.clear diff --git a/app/views/autocomplete_calendars/autocomplete.rabl b/app/views/autocomplete_calendars/autocomplete.rabl new file mode 100644 index 000000000..199195f31 --- /dev/null +++ b/app/views/autocomplete_calendars/autocomplete.rabl @@ -0,0 +1,5 @@ +collection @calendars, :object_root => false +attribute :id, :name, :short_name, :shared +node :text do |cal| + cal.name +end diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim index 8f4924bd3..ef6a1b56b 100644 --- a/app/views/time_table_combinations/_form.html.slim +++ b/app/views/time_table_combinations/_form.html.slim @@ -1,15 +1,12 @@ - h1 = @time_table.comment - = simple_form_for [@referential, @time_table, @combination], html: {class: 'form-horizontal'}, wrapper: :horizontal_form do |form| .row .col-lg-12 = form.input :combined_type, as: :select, collection: ['time_table', 'calendar'] - = form.input :operation, as: :select, collection: TimeTableCombination.operations - = form.input :time_table_id, as: :select, input_html: { data: { select2_ajax: 'true', term: 'comment_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json), formater: 'select2_time_table'}} + = form.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', data: { select2_ajax: 'true', term: 'comment_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json), formater: 'select2_time_table'}}, disabled: @combination.combined_type != 'time_table', wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} - = form.input :calendar_id, as: :select, input_html: { data: { select2_ajax: 'true', term: 'name_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json), formater: 'select2_calendar'}} + = form.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', data: { select2_ajax: 'true', term: 'name_cont', url: autocomplete_calendars_path, formater: 'select2_calendar'}}, disabled: @combination.combined_type != 'calendar', wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''} = form.button :submit, t('actions.submit') diff --git a/config/routes.rb b/config/routes.rb index 06f64c4dd..4342052f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,7 +72,9 @@ ChouetteIhm::Application.routes.draw do resources :networks end - resources :calendars + resources :calendars do + get :autocomplete, on: :collection, controller: 'autocomplete_calendars' + end resources :referentials do resources :api_keys diff --git a/spec/controllers/autocomplete_calendars_controller_spec.rb b/spec/controllers/autocomplete_calendars_controller_spec.rb new file mode 100644 index 000000000..3ff75fadf --- /dev/null +++ b/spec/controllers/autocomplete_calendars_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe AutocompleteCalendarsController, type: :controller do + +end |
