diff options
| author | Marc Florisson | 2014-04-30 00:12:32 +0200 |
|---|---|---|
| committer | Marc Florisson | 2014-04-30 00:12:32 +0200 |
| commit | c088a3b8d8c355191d4eed33e55be599124c5e0d (patch) | |
| tree | e562acb366a5d88a9a9179ed35932d00813298c0 | |
| parent | 9663dcb4d35e75a4046a14014e504ea9fa92abba (diff) | |
| download | chouette-core-c088a3b8d8c355191d4eed33e55be599124c5e0d.tar.bz2 | |
fix new stop point insertion at any place on route
| -rw-r--r-- | app/views/routes/_form.html.erb | 38 | ||||
| -rw-r--r-- | app/views/routes/_stop_point_fields.html.erb | 2 |
2 files changed, 29 insertions, 11 deletions
diff --git a/app/views/routes/_form.html.erb b/app/views/routes/_form.html.erb index 12556faa9..091f68278 100644 --- a/app/views/routes/_form.html.erb +++ b/app/views/routes/_form.html.erb @@ -39,8 +39,15 @@ var read_stop_point_ids = function(){ }); } var write_stop_point_ids = function(){ - $('#stop_points input[type="hidden"][class="stop_point_id"]').each(function(index) { - $(this).attr("value", stop_point_ids[index]) + $('#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()); + } }); } @@ -54,12 +61,21 @@ var write_stop_point_ids = function(){ opacity: 0.4, scroll: true, start: function( event, ui ) { - stop_point_ids = $('#stop_points input[type="hidden"][class="stop_point_id"]').map(function() { - return $(this).val(); - }); }, + 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( stop_point_ids ); + }, update: function( event, ui ) { - $('#stop_points input[type="hidden"][class="stop_point_id"]').each(function(index) { - $(this).attr("value", stop_point_ids[index]) + $('#stop_points input[type="hidden"][class~="stop_point_id"]').each( function( index,element) { + if ( $(element).hasClass("added_stop_point") ){ + $(this).attr("value", ""); + } else { + $(this).attr("value", stop_point_ids.shift()); + } }); order_position(); } @@ -72,7 +88,6 @@ $('#stop_points').bind("cocoon:after-insert", function(event, insertedItem) { var cocoonId = insertedItem.find("input.new_stop_point").attr("id").match( /route_stop_points_attributes_(\d+)_stop_area_id/)[1]; insertedItem.find('input').each( function(index,e){ var old = $(e).attr("name"); - console.log(old); if (old!=undefined) { $(e).attr("name", old.replace( cocoonId, new_stop_count - 1)); } @@ -83,8 +98,11 @@ $('#stop_points').bind("cocoon:after-insert", function(event, insertedItem) { }); $('#stop_points').on("cocoon:before-remove", function() { - stop_point_ids = $('#stop_points input[type="hidden"][class="stop_point_id"]').map(function() { - return $(this).val(); + 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()); }); //var stop_point_ids = read_stop_point_ids(); console.log( "before-remove"); diff --git a/app/views/routes/_stop_point_fields.html.erb b/app/views/routes/_stop_point_fields.html.erb index 26219a2e7..e36ee460c 100644 --- a/app/views/routes/_stop_point_fields.html.erb +++ b/app/views/routes/_stop_point_fields.html.erb @@ -3,7 +3,7 @@ <%= link_to_remove_association "<i class='fa fa-trash-o'></i>".html_safe, f %> <span class="handle" alt="<%= t('stop_points.index.move') %>" title="<%= t('stop_points.index.move') %>" ><i class='fa fa-arrows'></i></span> <% if f.object.stop_area.nil? %> - <%= f.input :id, :as => :hidden, :input_html => { :class => "stop_point_id", :value => "" } %> + <%= f.input :id, :as => :hidden, :input_html => { :class => "stop_point_id added_stop_point", :value => "" } %> <%= f.input :position, :as => :hidden, :input_html => { :class => "position" } %> <%= f.input :stop_area_id, :label => false, :wrapper_html => { :class => (f.object.valid? ? "" : "error") }, :input_html => { :class => "new_stop_point stop_area_id", :"data-pre" => [].to_json } %> <script> |
