diff options
| -rw-r--r-- | app/controllers/stop_area_children_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/stop_area_parents_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/stop_point_areas_controller.rb | 20 | ||||
| -rw-r--r-- | app/views/routes/_form.html.erb | 96 |
4 files changed, 65 insertions, 55 deletions
diff --git a/app/controllers/stop_area_children_controller.rb b/app/controllers/stop_area_children_controller.rb index 773f6e1b8..d60fcb1a6 100644 --- a/app/controllers/stop_area_children_controller.rb +++ b/app/controllers/stop_area_children_controller.rb @@ -11,7 +11,7 @@ class StopAreaChildrenController < ChouetteController protected def children_maps - children.map { |c| c.attributes} + children.map {|area| area.attributes.merge( :area_type => t("area_types.label.#{area.area_type.underscore}"))} end def children diff --git a/app/controllers/stop_area_parents_controller.rb b/app/controllers/stop_area_parents_controller.rb index 06b462075..c32e5df17 100644 --- a/app/controllers/stop_area_parents_controller.rb +++ b/app/controllers/stop_area_parents_controller.rb @@ -9,7 +9,7 @@ class StopAreaParentsController < ChouetteController end def parents_maps - parents.map { |p| p.attributes} + parents.map {|area| area.attributes.merge( :area_type => t("area_types.label.#{area.area_type.underscore}"))} end def parents diff --git a/app/controllers/stop_point_areas_controller.rb b/app/controllers/stop_point_areas_controller.rb index 9544d0fe6..1ece8641e 100644 --- a/app/controllers/stop_point_areas_controller.rb +++ b/app/controllers/stop_point_areas_controller.rb @@ -3,25 +3,17 @@ class StopPointAreasController < ChouetteController respond_to :json, :only => :index def index - respond_to do |format| - format.json { render :json => areas_maps } - end + respond_to do |format| + format.json { render :json => areas_maps } + end end def areas_maps - areas.collect do |area| - { :id => area.id.to_s, - :name => area.name, - :country_code => area.country_code, - :zip_code => area.zip_code || "", - :city_name => area.city_name || "", - :area_type => t("area_types.label.#{area.area_type.underscore}") - } - end + areas.map {|area| area.attributes.merge( :area_type => t("area_types.label.#{area.area_type.underscore}"))} end - def areas - Chouette::StopPoint.area_candidates.select{ |p| p.name =~ /#{params[:q]}/i } + def areas + Chouette::StopPoint.area_candidates.select{ |p| p.name =~ /#{params[:q]}/i } end end diff --git a/app/views/routes/_form.html.erb b/app/views/routes/_form.html.erb index 658fda0ae..270c49911 100644 --- a/app/views/routes/_form.html.erb +++ b/app/views/routes/_form.html.erb @@ -26,55 +26,73 @@ <% end %> <% end %> <script> -var stop_point_ids = []; -var order_position = function() { - $('#stop_points input[type="hidden"][id$="position"]').each(function(index) { - $(this).val(index); - }); -}; +$(document).ready( function() { + var stop_point_ids = []; -var write_stop_point_ids = function(){ - $('#stop_points input[type="hidden"][class~="stop_point_id"]').each(function(index,element) { + var order_position = function() { + $('#stop_points input[type="hidden"][id$="position"]').each(function(index) { + $(this).val(index); + }); + }; + var write_stop_point_ids = function(){ + $('#stop_points input[type="hidden"][class~="stop_point_id"]').each(function(index,element) { - // soit le parent a la classe added_stop_point - if ( $(element).hasClass("added_stop_point") ){ - $(this).attr("value", ""); - } else { - $(this).attr("value", stop_point_ids.shift()); - } - }); -} -var empty_stop_point_ids = function() { - while(stop_point_ids.length > 0) { - stop_point_ids.pop(); + // soit le parent a la classe added_stop_point + if ( $(element).hasClass("added_stop_point") ){ + $(this).attr("value", ""); + } else { + $(this).attr("value", stop_point_ids.shift()); + } + }); } - $('#stop_points input[type="hidden"][class="stop_point_id"]').map(function() { - stop_point_ids.push( $(this).val()); - }); - // console.log( "before-remove"); - // console.log( stop_point_ids); -}; -var stop_area_selection_token_input = function( element ) { - element.tokenInput('<%= referential_stop_point_areas_path(@referential, :format => :json) %>', - { crossDomain: false, - prePopulate: $(element).data('pre'), - tokenLimit: 1, - minChars: 3, - hintText: '<%= t('search_hint') %>', - noResultsText: '<%= t('no_result_text') %>', - searchingText: '<%= t('searching_term') %>', - resultsFormatter: function(item){ return '<li><div class=\"name\">' + item.name + '</div><div class=\"info\">' + item.area_type + '</div><div class=\"info\">' + item.zip_code + ' ' + item.city_name + '</div></li>' }, - tokenFormatter: function(item) { return '<li><p>' + item.name + '</p></li>' } - }); -}; -$(document).ready( function() { + var empty_stop_point_ids = function() { + while(stop_point_ids.length > 0) { + stop_point_ids.pop(); + } + $('#stop_points input[type="hidden"][class="stop_point_id"]').map(function() { + stop_point_ids.push( $(this).val()); + }); + // console.log( "before-remove"); + // console.log( stop_point_ids); + }; + var stop_area_selection_token_input = function( element ) { + var item_name = function( item){ + var result = item.name; + if ( item.registration_number !=null && item.registration_number.length > 0) { + result += ' (' + item.registration_number + ')'; + } + return result; + }; + var item_format = function( item ){ + var info = ''; + if ( item.zip_code != null ) { + info += item.zip_code + ' '; + } + if ( item.city_name != null ) { + info += item.city_name; + } + return '<li><div class=\"name\">' + item_name( item) + '</div><div class=\"info\">' + item.area_type + '</div><div class=\"info\">' + info + '</div></li>' + }; + element.tokenInput('<%= referential_stop_point_areas_path(@referential, :format => :json) %>', + { crossDomain: false, + tokenLimit: 1, + minChars: 3, + hintText: '<%= t('search_hint') %>', + noResultsText: '<%= t('no_result_text') %>', + searchingText: '<%= t('searching_term') %>', + resultsFormatter: item_format , + tokenFormatter: item_format + }); + }; + $( ".new_stop_point" ).each( function(index, element){ stop_area_selection_token_input( $(element)) }); + $('#stop_points').sortable({ axis: 'y', dropOnEmpty: false, |
