diff options
| author | Michel Etienne | 2014-08-21 13:01:04 +0200 | 
|---|---|---|
| committer | Michel Etienne | 2014-08-21 13:01:04 +0200 | 
| commit | 00be8c517ea3cc1c5736f673f73962ab3c203d47 (patch) | |
| tree | 1dd340308ad531f4af770348db3cb9c893477752 | |
| parent | 4e787048ecdda31c129dcada8385e74124795b82 (diff) | |
| download | chouette-core-00be8c517ea3cc1c5736f673f73962ab3c203d47.tar.bz2 | |
inprove timetable combinations
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/controllers/time_table_combinations_controller.rb | 9 | ||||
| -rw-r--r-- | app/models/time_table_combination.rb | 8 | ||||
| -rw-r--r-- | app/views/time_table_combinations/_combine.html.erb | 2 | ||||
| -rw-r--r-- | app/views/time_table_combinations/create_failure.js.erb | 5 | ||||
| -rw-r--r-- | app/views/time_table_combinations/create_success.js.erb (renamed from app/views/time_table_combinations/create.js.erb) | 3 | 
6 files changed, 14 insertions, 15 deletions
| diff --git a/Gemfile.lock b/Gemfile.lock index 66e76c29c..03309d76a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@  GIT    remote: https://github.com/afimb/ninoxe.git -  revision: 5bb26096ba96661c684c76c05dac05deda877937 +  revision: abee1ec401e4f8f44528620225e2db2c06e1c97f    branch: sismo    specs:      ninoxe (1.1.0) diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb index eb41dc2e1..baaf90fec 100644 --- a/app/controllers/time_table_combinations_controller.rb +++ b/app/controllers/time_table_combinations_controller.rb @@ -7,15 +7,18 @@ class TimeTableCombinationsController < ChouetteController    def create      @time_table_combination = TimeTableCombination.new( params[:time_table_combination].merge( :source_id => parent.id)) +    #@time_table = parent      @year = params[:year] ? params[:year].to_i : Date.today.cwyear      if @time_table_combination.valid?        begin -        @time_table_combination.combine +        @time_table = @time_table_combination.combine          flash[:notice] = t('time_table_combinations.success') -      rescue +        render "create_success" +      rescue Exception=> e +        Rails.logger.error "Error: #{e}"          flash[:error] = t('time_table_combinations.failure') +        render "create_failure"        end -      parent.reload      end    end diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb index 26fb38fbe..85ab20bb7 100644 --- a/app/models/time_table_combination.rb +++ b/app/models/time_table_combination.rb @@ -3,7 +3,7 @@ class TimeTableCombination    include ActiveModel::Conversion      extend ActiveModel::Naming -  attr_accessor :source_id, :combined_id, :combined_name, :operation, :status +  attr_accessor :source_id, :combined_id, :combined_name, :operation    validates_presence_of :source_id, :combined_id, :operation, :combined_name    validates_inclusion_of :operation, :in =>  %w( union intersection disjunction) @@ -14,7 +14,6 @@ class TimeTableCombination      self.combined_name = nil      self.operation = nil      self.errors.clear -    self.status = false    end      def valid?(context = nil)  @@ -35,7 +34,6 @@ class TimeTableCombination      attributes.each do |name, value|          send("#{name}=", value)        end   -    self.status = false    end      def persisted?   @@ -43,7 +41,6 @@ class TimeTableCombination    end     def combine -    self.status = false      source = Chouette::TimeTable.find( source_id)      combined = Chouette::TimeTable.find( combined_id)      if operation == "union" @@ -55,8 +52,7 @@ class TimeTableCombination      else         raise "unknown operation"      end -    source.save -    self.status = true +    source    end  end diff --git a/app/views/time_table_combinations/_combine.html.erb b/app/views/time_table_combinations/_combine.html.erb index 3257cf812..85fc5ab26 100644 --- a/app/views/time_table_combinations/_combine.html.erb +++ b/app/views/time_table_combinations/_combine.html.erb @@ -5,9 +5,7 @@          <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> diff --git a/app/views/time_table_combinations/create_failure.js.erb b/app/views/time_table_combinations/create_failure.js.erb new file mode 100644 index 000000000..65cc241c5 --- /dev/null +++ b/app/views/time_table_combinations/create_failure.js.erb @@ -0,0 +1,5 @@ + +var combine_form_partial = '<%= j render "time_table_combinations/combine_form" %> '; + +$('#new_time_table_combination').replaceWith(combine_form_partial); + diff --git a/app/views/time_table_combinations/create.js.erb b/app/views/time_table_combinations/create_success.js.erb index 06655deea..79ab543d9 100644 --- a/app/views/time_table_combinations/create.js.erb +++ b/app/views/time_table_combinations/create_success.js.erb @@ -3,9 +3,6 @@ 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 %> | 
