aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichel Etienne2014-05-06 10:23:45 +0200
committerMichel Etienne2014-05-06 10:23:45 +0200
commitfcf18b2051facb515313f7756315b3b9904867fc (patch)
tree2acbcda771f6153585fb006191bd7251966316af
parentc9d2cf5d2bb8264a393ebc3f62110d14d085b180 (diff)
parentc088a3b8d8c355191d4eed33e55be599124c5e0d (diff)
downloadchouette-core-fcf18b2051facb515313f7756315b3b9904867fc.tar.bz2
Merge branch 'fix_stop_point_on_route'
-rw-r--r--app/assets/stylesheets/routes.css.scss22
-rw-r--r--app/views/routes/_form.html.erb107
-rw-r--r--app/views/routes/_stop_point_fields.html.erb29
-rw-r--r--app/views/stop_points/new.html.erb5
4 files changed, 160 insertions, 3 deletions
diff --git a/app/assets/stylesheets/routes.css.scss b/app/assets/stylesheets/routes.css.scss
index 918f7c4fb..77d84ee87 100644
--- a/app/assets/stylesheets/routes.css.scss
+++ b/app/assets/stylesheets/routes.css.scss
@@ -46,6 +46,28 @@
#route_color{ width: 100px;
color: white;
font-weight: bold;}
+
+ #stop_points .nested-fields {
+ ol {
+ margin-left: 25%;
+ i.fa { margin-right: 10px;}
+
+ li {
+ display: inline;
+
+ .token-input-list {
+ overflow: visible;
+ .token-input-token {
+ p { margin: 0px 0px !important; }
+ }
+ }
+ }
+ }
+ }
+
+ #stop_points .links {
+ margin: 10px 0 15px 25%;
+ }
}
#workspace.routes.show
diff --git a/app/views/routes/_form.html.erb b/app/views/routes/_form.html.erb
index ddabcc528..091f68278 100644
--- a/app/views/routes/_form.html.erb
+++ b/app/views/routes/_form.html.erb
@@ -1,14 +1,22 @@
<%= semantic_form_for [@referential, @line, @route] do |form| %>
- <%= form.inputs do %>
+ <%= form.inputs do %>
<%= form.input :name %>
<%= form.input :published_name %>
<%= form.input :number %>
- <%= form.input :comment %>
+ <%= form.input :comment %>
<%= form.input :opposite_route, :as => :select, :collection => @line.routes.select { |r| r.id != @route.id } %>
<%= form.input :direction_code, :as => :select, :collection => Chouette::Route.directions, :include_blank => false, :member_label => Proc.new { |mode| t("directions.label.#{mode}") } %>
<%= form.input :wayback_code, :as => :select, :collection => Chouette::Route.waybacks, :include_blank => false, :member_label => Proc.new { |mode| t("waybacks.label.#{mode}") } %>
- <%= form.input :objectid, :required => !@route.new_record?, :input_html => { :disabled => !@route.new_record? } %>
+ <%= form.input :objectid, :required => !@route.new_record?, :input_html => { :disabled => !@route.new_record? } %>
<% end %>
+ <div id="stop_points">
+ <%= form.semantic_fields_for :stop_points, :include_id => false, :label => "TOTO" do |p| %>
+ <%= render "stop_point_fields", :f => p, :test1 => "oiuoiu" %>
+ <% end %>
+ <div class="links">
+ <%= link_to_add_association t("routes.actions.add_stop_point"), form, :stop_points, :class => 'add_stop_point' %>
+ </div>
+ </div>
<%= form.actions do %>
<%= form.action :submit, :as => :button %>
@@ -16,3 +24,96 @@
<% end %>
<% end %>
+<script>
+var stop_point_ids = [];
+var order_position;
+
+order_position = function() {
+ $('#stop_points input[type="hidden"][id$="position"]').each(function(index) {
+ $(this).val(index);
+ });
+};
+var read_stop_point_ids = function(){
+ $('#stop_points input[type="hidden"][class="stop_point_id"]').map(function() {
+ return $(this).val();
+ });
+}
+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());
+ }
+ });
+}
+
+
+ $('#stop_points').sortable({
+ axis: 'y',
+ dropOnEmpty: false,
+ handle: '.handle',
+ cursor: 'crosshair',
+ items: '.stop_point',
+ opacity: 0.4,
+ scroll: true,
+ start: function( event, ui ) {
+ 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,element) {
+ if ( $(element).hasClass("added_stop_point") ){
+ $(this).attr("value", "");
+ } else {
+ $(this).attr("value", stop_point_ids.shift());
+ }
+ });
+ order_position();
+ }
+ });
+
+$('#stop_points').bind("cocoon:after-insert", function(event, insertedItem) {
+ //$( ".stop_point" ).last().val( );
+
+ var new_stop_count = $('div.nested-fields.stop_point').size();
+ 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");
+ if (old!=undefined) {
+ $(e).attr("name", old.replace( cocoonId, new_stop_count - 1));
+ }
+ });
+
+ console.log( "cocoonId="+cocoonId+", new_stop_count="+new_stop_count);
+ order_position();
+});
+
+$('#stop_points').on("cocoon:before-remove", 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());
+ });
+ //var stop_point_ids = read_stop_point_ids();
+ console.log( "before-remove");
+ console.log( stop_point_ids);
+});
+
+$('#stop_points').on("cocoon:after-remove", function() {
+ write_stop_point_ids();
+ order_position();
+});
+
+
+</script>
+
diff --git a/app/views/routes/_stop_point_fields.html.erb b/app/views/routes/_stop_point_fields.html.erb
new file mode 100644
index 000000000..e36ee460c
--- /dev/null
+++ b/app/views/routes/_stop_point_fields.html.erb
@@ -0,0 +1,29 @@
+<div class="nested-fields stop_point">
+ <%= f.inputs do %>
+ <%= 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 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>
+ $(function() {
+ $( ".new_stop_point" ).last().tokenInput('<%= referential_stop_point_areas_path(@referential, :format => :json) %>',
+ { crossDomain: false,
+ prePopulate: $('#stop_area_id').data('pre'),
+ tokenLimit: 1,
+ minChars: 3,
+ hintText: '<%= t('search_hint') %>',
+ noResultsText: '<%= t('no_result_text') %>',
+ searchingText: '<%= t('searching_term') %>' }
+ );
+ });
+ </script>
+ <% else %>
+ <%= f.input :id, :as => :hidden, :input_html => { :class => "stop_point_id" } %>
+ <%= f.input :position, :as => :hidden, :input_html => { :class => "position" } %>
+ <%= f.input :stop_area_id, :as => :hidden, :input_html => { :class => "stop_area_id"} %>
+ <%= f.object.stop_area.name %>
+ <% end %>
+ <% end %>
+ </div>
diff --git a/app/views/stop_points/new.html.erb b/app/views/stop_points/new.html.erb
index 14eba5bcc..ee2495ee0 100644
--- a/app/views/stop_points/new.html.erb
+++ b/app/views/stop_points/new.html.erb
@@ -1,5 +1,10 @@
<%= title_tag t('.title', :route => @route.name) %>
+<ul>
+ <% @route.stop_areas.last(3).each do |stop_area| %>
+ <li><%= stop_area.parent.name %></li>
+ <% end %>
+</ul>
<%= semantic_form_for [@referential, @line, @route, @stop_point] do |form| %>
<div>
<%= form.inputs do %>