aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-07-03 15:13:08 +0200
committerLuc Donnet2017-07-03 15:13:08 +0200
commit34775f5157902a30d1bbbb18991a1872b59fde3b (patch)
treecbd14a9e0e721f9ec70d682cad624b8107d0ab32
parent1adc021ba4d797152a6f31cfe17161ef20877fb7 (diff)
downloadchouette-core-34775f5157902a30d1bbbb18991a1872b59fde3b.tar.bz2
Fix routing constraint zones edit and new Refs #3953
-rw-r--r--app/assets/javascripts/routing_constraint_zones.coffee80
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb41
-rw-r--r--app/models/chouette/vehicle_journey.rb7
-rw-r--r--app/views/calendars/show.html.slim2
-rw-r--r--app/views/routing_constraint_zones/_form.html.slim25
-rw-r--r--app/views/routing_constraint_zones/_stop_points.html.slim10
-rw-r--r--app/views/routing_constraint_zones/edit.html.slim25
-rw-r--r--app/views/routing_constraint_zones/new.html.slim24
-rw-r--r--app/views/routing_constraint_zones/new.js.erb1
-rw-r--r--app/views/routing_constraint_zones/show.html.slim2
10 files changed, 95 insertions, 122 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()
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index 6fb5348f0..1eb2ddf28 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -4,14 +4,33 @@ class RoutingConstraintZonesController < ChouetteController
defaults resource_class: Chouette::RoutingConstraintZone
respond_to :html, :xml, :json
- before_action :check_stoppoint_param, only: [:create, :update]
+ # before_action :check_stoppoint_param, only: [:create, :update]
belongs_to :referential do
belongs_to :line, parent_class: Chouette::Line
end
+ def show
+ show! do |format|
+ @routing_constraint_zone = @routing_constraint_zone.decorate(context: {
+ referential: current_referential,
+ line: parent.id
+ })
+ end
+ end
+
+ def new
+ new! do |format|
+ format.html
+ @route = @line.routes.find params[:route_id] if params[:route_id]
+ format.js
+ end
+ end
+
protected
+ alias_method :routing_constraint_zone, :resource
+
def collection
@q = current_referential.routing_constraint_zones.search(params[:q])
@@ -25,26 +44,6 @@ class RoutingConstraintZonesController < ChouetteController
end
end
- def resource
- @routing_constraint_zone ||= begin
- routing_constraint_zone = current_referential.routing_constraint_zones.find(params[:id])
- routing_constraint_zone = routing_constraint_zone.decorate(context: {
- referential: current_referential,
- line: parent.id
- })
- end
- end
-
- def build_resource
- @routing_constraint_zone ||= begin
- routing_constraint_zone = current_referential.routing_constraint_zones.new
- routing_constraint_zone = routing_constraint_zone.decorate(context: {
- referential: current_referential,
- line: parent.id
- })
- end
- end
-
private
def sort_column
(Chouette::RoutingConstraintZone.column_names).include?(params[:sort]) ? params[:sort] : 'name'
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 3a5851310..71c339780 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -23,15 +23,14 @@ module Chouette
validates_presence_of :route
validates_presence_of :journey_pattern
+ validates :vehicle_journey_at_stops, :vjas_departure_time_must_be_before_next_stop_arrival_time,
+ vehicle_journey_at_stops_are_in_increasing_time_order: true
+ validates_presence_of :number
has_many :vehicle_journey_at_stops, -> { includes(:stop_point).order("stop_points.position") }, :dependent => :destroy
has_and_belongs_to_many :time_tables, :class_name => 'Chouette::TimeTable', :foreign_key => "vehicle_journey_id", :association_foreign_key => "time_table_id"
has_many :stop_points, -> { order("stop_points.position") }, :through => :vehicle_journey_at_stops
- validates :vehicle_journey_at_stops, :vjas_departure_time_must_be_before_next_stop_arrival_time,
- vehicle_journey_at_stops_are_in_increasing_time_order: true
- validates_presence_of :number
-
before_validation :set_default_values,
:calculate_vehicle_journey_at_stop_day_offset
diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim
index d7849005b..26248cea8 100644
--- a/app/views/calendars/show.html.slim
+++ b/app/views/calendars/show.html.slim
@@ -25,4 +25,4 @@
Calendar.human_attribute_name(:shared) => t("#{@calendar.shared}"),
'Organisation' => @calendar.organisation.name,
Calendar.human_attribute_name(:dates) => @calendar.dates.collect{|d| l(d, format: :short)}.join(', ').html_safe,
- Calendar.human_attribute_name(:date_ranges) => @calendar.date_ranges.collect{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end - (d.exclude_end? ? 1.day : 0), format: :short))}.join('<br>').html_safe }
+ Calendar.human_attribute_name(:date_ranges) => @calendar.date_ranges.collect{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end, format: :short))}.join('<br>').html_safe }
diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim
deleted file mode 100644
index 5e5f44269..000000000
--- a/app/views/routing_constraint_zones/_form.html.slim
+++ /dev/null
@@ -1,25 +0,0 @@
-= simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
-
- .row
- .col-lg-12
- = form.input :name
- = form.input :route_id, collection: @line.routes, include_blank: false
-
- .separator
-
- #ITL_stoppoints
- .subform
- .nested-head
- .wrapper
- div
- .form-group
- label.control-label Arrêt
- div
- .form-group
- label.control-label Commune
- div
-
- = hidden_field_tag 'stop_point_ids', @routing_constraint_zone.stop_point_ids.to_s, id: 'stop_point_ids'
-
-
- = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'itl_form'
diff --git a/app/views/routing_constraint_zones/_stop_points.html.slim b/app/views/routing_constraint_zones/_stop_points.html.slim
new file mode 100644
index 000000000..e6ea62ee2
--- /dev/null
+++ b/app/views/routing_constraint_zones/_stop_points.html.slim
@@ -0,0 +1,10 @@
+- stop_points.each do |stop_point|
+ .wrapper
+ div
+ = link_to stop_point.stop_area.name, referential_stop_area_path(@referential, stop_point.stop_area.id)
+ div
+ = "#{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) )
+ span.radio-label
diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim
index 589083927..a99f8e8d3 100644
--- a/app/views/routing_constraint_zones/edit.html.slim
+++ b/app/views/routing_constraint_zones/edit.html.slim
@@ -9,4 +9,27 @@
.container-fluid
.row
.col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
- == render 'form'
+ = simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
+
+ .row
+ .col-lg-12
+ = form.input :name
+ = form.association :route, collection: @line.routes, disabled: true
+
+ .separator
+
+ #ITL_stoppoints
+ .subform
+ .nested-head
+ .wrapper
+ div
+ .form-group
+ label.control-label Arrêt
+ div
+ .form-group
+ label.control-label Commune
+ div
+ .nested-fields
+ = render( partial: 'routing_constraint_zones/stop_points', object: @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 f6ae62825..119f01e12 100644
--- a/app/views/routing_constraint_zones/new.html.slim
+++ b/app/views/routing_constraint_zones/new.html.slim
@@ -7,4 +7,26 @@
.container-fluid
.row
.col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
- == render 'form'
+ = simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
+
+ .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) }}
+
+ .separator
+
+ #ITL_stoppoints
+ .subform
+ .nested-head
+ .wrapper
+ div
+ .form-group
+ label.control-label Arrêt
+ div
+ .form-group
+ label.control-label Commune
+ div
+ .nested-fields#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.js.erb b/app/views/routing_constraint_zones/new.js.erb
new file mode 100644
index 000000000..406845a4d
--- /dev/null
+++ b/app/views/routing_constraint_zones/new.js.erb
@@ -0,0 +1 @@
+$("#stop_points").html("<%= escape_javascript(render partial: 'routing_constraint_zones/stop_points', object: @route.stop_points) %>");
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
index 1dad4f561..3decc086f 100644
--- a/app/views/routing_constraint_zones/show.html.slim
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -28,7 +28,7 @@
.col-lg-12
= table_builder @routing_constraint_zone.route.stop_points,
{ "Arrêts de l'itinéraire" => 'name',
- "Arrêts inclus dans l'ITL" => Proc.new{ |rsp| (@routing_constraint_zone.stop_points.collect{|c| c.name}.include? rsp.name) ? 'Oui' : 'Non' } },
+ "Arrêts inclus dans l'ITL" => Proc.new{ |rsp| (@routing_constraint_zone.stop_point_ids.include? rsp.id) ? 'Oui' : 'Non' } },
[],
[],
'table has-stoppoints'