From 33e796dc89b36f7c57adb9d462c0cc35a15be623 Mon Sep 17 00:00:00 2001
From: Vlatka Pavisic
Date: Tue, 18 Apr 2017 18:17:17 +0200
Subject: Refs #3132 #3135 #3136 ITL StopArea validations
---
app/assets/javascripts/routing_constraint_zones.coffee | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
(limited to 'app/assets/javascripts')
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee
index 7460a64a7..458189b36 100644
--- a/app/assets/javascripts/routing_constraint_zones.coffee
+++ b/app/assets/javascripts/routing_constraint_zones.coffee
@@ -4,18 +4,24 @@ fill_stop_points_options = ->
referential_id = document.location.pathname.match(/\d+/g)[0]
line_id = document.location.pathname.match(/\d+/g)[1]
route_id = $('#routing_constraint_zone_route_id').val()
+ if errors_on_form()
+ stop_point_ids = eval($('#stop_point_ids').val())
$.ajax
url: "/referentials/#{referential_id}/lines/#{line_id}/routes/#{route_id}/stop_points"
dataType: 'json'
success: (data, textStatus, jqXHR) ->
for stop_point in data
- stop_point_select.append ""
+ selected = $.inArray(stop_point.id, stop_point_ids) != -1
+ stop_point_select.append ""
error: (jqXHR, textStatus, errorThrown) ->
console.log textStatus
console.log errorThrown
+errors_on_form = ->
+ document.location.pathname.endsWith('routing_constraint_zones') && $('#new_routing_constraint_zone').length
+
$(document).on 'turbolinks:load', ->
- if document.location.pathname.endsWith('new')
+ if document.location.pathname.endsWith('new') || errors_on_form()
fill_stop_points_options()
$('#routing_constraint_zone_route_id').change(fill_stop_points_options)
--
cgit v1.2.3