aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorLuc Donnet2017-07-03 15:13:08 +0200
committerLuc Donnet2017-07-03 15:13:08 +0200
commit34775f5157902a30d1bbbb18991a1872b59fde3b (patch)
treecbd14a9e0e721f9ec70d682cad624b8107d0ab32 /app/assets/javascripts
parent1adc021ba4d797152a6f31cfe17161ef20877fb7 (diff)
downloadchouette-core-34775f5157902a30d1bbbb18991a1872b59fde3b.tar.bz2
Fix routing constraint zones edit and new Refs #3953
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/routing_constraint_zones.coffee80
1 files changed, 12 insertions, 68 deletions
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee
index 8721dfb38..2fd83fa28 100644
--- a/app/assets/javascripts/routing_constraint_zones.coffee
+++ b/app/assets/javascripts/routing_constraint_zones.coffee
@@ -1,73 +1,17 @@
-@ITL_stoppoints = ->
- routeID = $('#routing_constraint_zone_route_id').val()
-
- if (routeID)
- origin = window.location.origin
- path = window.location.pathname.split('/', 5).join('/')
- reqURL = origin + path + '/routes/' + routeID + '/stop_points.json'
+$ ->
+ update_stop_points = () ->
+ url = $('#routing_constraint_zone_route_id').attr("data-url")
+ route_id = $('#routing_constraint_zone_route_id').val()
$.ajax
- url: reqURL
- dataType: 'json'
+ url: url
+ dataType: 'script'
+ data: { route_id: route_id }
error: (jqXHR, textStatus, errorThrown) ->
- console.log(errorThrown)
- success: (collection, textStatus, jqXHR) ->
- html = ''
- stopAreaBaseURL = origin + window.location.pathname.split('/', 3).join('/') + '/stop_areas/'
-
- collection.forEach (item, index) ->
- html += "<div class='nested-fields'><div class='wrapper'>
- <div><a href='" + stopAreaBaseURL + item.stop_area_id + "' class='navlink' title='Voir l&#39;arrêt'><span>" + item.name + "</span></a></div>
- <div><span>" + item.city_name + " (" + item.zip_code + ")</span></div>
- <div>
- <span class='has_radio'>
- <input type='checkbox' name='routing_constraint_zone[stop_point_ids][" + index + "]' value='" + item.id + "'>
- <span class='radio-label'></span>
- </span>
- </div>
- </div></div>"
-
- $('#ITL_stoppoints').find('.nested-fields').remove()
- $('#ITL_stoppoints').find('.nested-head').after(html)
-
- # VALIDATION
- selection = []
-
- totalItems = collection.length
-
- $('#ITL_stoppoints').on 'click', "input[type='checkbox']", (e) ->
- v = $(e.target).val()
+ console.log("ERROR")
+ success: (data, textStatus, jqXHR) ->
+ console.log("SUCCESS")
- if ( $.inArray(v, selection) != -1 )
- selection.splice(selection.indexOf(v), 1)
- else
- selection.push(v)
-
- alertMsg1 = "<div class='alert alert-danger' style='margin-bottom:15px;'>
- <p class='small'>Un ITL doit comporter au moins deux arrêts</p>
- </div>"
- alertMsg2 = "<div class='alert alert-danger' style='margin-bottom:15px;'>
- <p class='small'>Un ITL ne peut recouvrir tous les arrêts d'un itinéraire</p>
- </div>"
-
- $(document).on 'click', "input[type='submit']", (e)->
- inputName = $('#routing_constraint_zone_name').val()
-
- $('.alert-danger').remove()
-
- if ( selection.length < 2 && inputName != "" )
- e.preventDefault()
- $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove()
- $('#ITL_stoppoints').prepend(alertMsg1)
-
- if ( selection.length == totalItems && inputName != "" )
- e.preventDefault()
- $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove()
- $('#ITL_stoppoints').prepend(alertMsg2)
-
-$ ->
- ITL_stoppoints()
+ $("#itl_form #routing_constraint_zone_route_id").on 'change', -> update_stop_points()
- $('#routing_constraint_zone_route_id').on 'change', ->
- $('.alert-danger').remove()
- ITL_stoppoints()
+ update_stop_points()