aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-07-07 18:19:50 +0200
committerLuc Donnet2017-07-07 18:19:50 +0200
commit24977a51e49a3d88cf36d1fd71e2ddc51c4ec6e5 (patch)
tree87512253a6a7badc376998622f1e57776c2e54cf
parent42f5fbc1c93a79310458fc3c299192fb44556101 (diff)
downloadchouette-core-24977a51e49a3d88cf36d1fd71e2ddc51c4ec6e5.tar.bz2
Fix routing_constraint_zone validation for create refs #3962 @3
-rw-r--r--app/assets/javascripts/routing_constraint_zones.coffee3
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb10
-rw-r--r--app/models/chouette/routing_constraint_zone.rb2
-rw-r--r--app/views/journey_patterns_collections/show.html.slim5
-rw-r--r--app/views/routing_constraint_zones/_stop_points.html.slim2
-rw-r--r--app/views/routing_constraint_zones/edit.html.slim2
-rw-r--r--app/views/routing_constraint_zones/new.html.slim2
-rw-r--r--app/views/routing_constraint_zones/new.js.erb2
8 files changed, 19 insertions, 9 deletions
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee
index 2fd83fa28..c01c9ca2f 100644
--- a/app/assets/javascripts/routing_constraint_zones.coffee
+++ b/app/assets/javascripts/routing_constraint_zones.coffee
@@ -2,11 +2,12 @@ $ ->
update_stop_points = () ->
url = $('#routing_constraint_zone_route_id').attr("data-url")
+ routing_constraint_zone_json = $('#routing_constraint_zone_route_id').attr("data-object")
route_id = $('#routing_constraint_zone_route_id').val()
$.ajax
url: url
dataType: 'script'
- data: { route_id: route_id }
+ data: { route_id: route_id, routing_constraint_zone_json: routing_constraint_zone_json }
error: (jqXHR, textStatus, errorThrown) ->
console.log("ERROR")
success: (data, textStatus, jqXHR) ->
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index 1eb2ddf28..c526e6348 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -22,14 +22,20 @@ class RoutingConstraintZonesController < ChouetteController
def new
new! do |format|
format.html
- @route = @line.routes.find params[:route_id] if params[:route_id]
- format.js
+ format.js {
+ # Get selected route in the form view
+ @route = @line.routes.find params[:route_id] if params[:route_id]
+ # Get the routing_constraint_zone, the main use is when validation failed
+ routing_constraint_zone = @line.routing_constraint_zones.new(JSON(params[:routing_constraint_zone_json])) if params[:routing_constraint_zone_json]
+ @routing_constraint_zone = routing_constraint_zone || build_resource
+ }
end
end
protected
alias_method :routing_constraint_zone, :resource
+ alias_method :line, :parent
def collection
@q = current_referential.routing_constraint_zones.search(params[:q])
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb
index 6a8847e4d..77f51c466 100644
--- a/app/models/chouette/routing_constraint_zone.rb
+++ b/app/models/chouette/routing_constraint_zone.rb
@@ -2,7 +2,7 @@ class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord
belongs_to :route
has_array_of :stop_points, class_name: 'Chouette::StopPoint'
- validates_presence_of :name, :stop_point_ids, :route_id
+ validates_presence_of :name, :stop_points, :route
validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') }
validate :stop_points_belong_to_route, :not_all_stop_points_selected
diff --git a/app/views/journey_patterns_collections/show.html.slim b/app/views/journey_patterns_collections/show.html.slim
index b5607090f..eb6dfb650 100644
--- a/app/views/journey_patterns_collections/show.html.slim
+++ b/app/views/journey_patterns_collections/show.html.slim
@@ -3,7 +3,10 @@
"Missions de #{@route.try(:stop_points).first.try(:stop_area).name} vers #{@route.try(:stop_points).last.try(:stop_area).name}",
'Lorem ipsum dolor sit amet',
''
-
+- @journey_patterns.each do |jp|
+ - jp.errors.each do |error_message|
+ = error_message
+
/ PageContent
.page_content
.container-fluid
diff --git a/app/views/routing_constraint_zones/_stop_points.html.slim b/app/views/routing_constraint_zones/_stop_points.html.slim
index 10c1d4900..4e85ba8b2 100644
--- a/app/views/routing_constraint_zones/_stop_points.html.slim
+++ b/app/views/routing_constraint_zones/_stop_points.html.slim
@@ -9,5 +9,5 @@
= "#{stop_point.stop_area.city_name} (#{stop_point.stop_area.zip_code})"
div
span.has_radio
- = check_box_tag( "routing_constraint_zone[stop_point_ids][]", "#{stop_point.id}", @routing_constraint_zone.stop_point_ids && @routing_constraint_zone.stop_point_ids.include?(stop_point.id) )
+ = check_box_tag( "routing_constraint_zone[stop_point_ids][]", "#{stop_point.id}", routing_constraint_zone.stop_point_ids && routing_constraint_zone.stop_point_ids.include?(stop_point.id) )
span.radio-label
diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim
index 4fe2786a3..7ecba1918 100644
--- a/app/views/routing_constraint_zones/edit.html.slim
+++ b/app/views/routing_constraint_zones/edit.html.slim
@@ -34,6 +34,6 @@
div
.nested-fields
- = render( partial: 'routing_constraint_zones/stop_points', object: @routing_constraint_zone.route.stop_points)
+ = render( partial: 'routing_constraint_zones/stop_points', locals: { routing_constraint_zone: @routing_constraint_zone, stop_points: @routing_constraint_zone.route.stop_points } )
= form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'itl_form'
diff --git a/app/views/routing_constraint_zones/new.html.slim b/app/views/routing_constraint_zones/new.html.slim
index ab7143a76..4e792f8af 100644
--- a/app/views/routing_constraint_zones/new.html.slim
+++ b/app/views/routing_constraint_zones/new.html.slim
@@ -12,7 +12,7 @@
.row
.col-lg-12
= form.input :name
- = form.input :route_id, collection: @line.routes, include_blank: false, input_html: {data: {url: new_referential_line_routing_constraint_zone_path(@referential, @line) }}
+ = form.input :route_id, collection: @line.routes, include_blank: false, input_html: {data: {url: new_referential_line_routing_constraint_zone_path(@referential, @line), object: @routing_constraint_zone.to_json }}
.separator
diff --git a/app/views/routing_constraint_zones/new.js.erb b/app/views/routing_constraint_zones/new.js.erb
index 406845a4d..418e7958b 100644
--- a/app/views/routing_constraint_zones/new.js.erb
+++ b/app/views/routing_constraint_zones/new.js.erb
@@ -1 +1 @@
-$("#stop_points").html("<%= escape_javascript(render partial: 'routing_constraint_zones/stop_points', object: @route.stop_points) %>");
+$("#stop_points").html("<%= escape_javascript(render partial: 'routing_constraint_zones/stop_points', locals: { routing_constraint_zone: @routing_constraint_zone, stop_points: @route.stop_points }) %>");