diff options
| author | Bruno Perles | 2015-12-03 10:57:02 +0100 | 
|---|---|---|
| committer | Bruno Perles | 2015-12-16 10:02:40 +0100 | 
| commit | 18d7e19b30671f5d73ad57a9bcd2b4aca62611ba (patch) | |
| tree | bb5fed0d52f56dcf9a803785a69bb1b4fcb54863 | |
| parent | 013f4fa8fe9bb08f3ed1d15f905ca2a8437d6aa7 (diff) | |
| download | chouette-core-18d7e19b30671f5d73ad57a9bcd2b4aca62611ba.tar.bz2 | |
Add OL Style on selected section
| -rw-r--r-- | app/assets/javascripts/route_section.js.coffee | 59 | ||||
| -rw-r--r-- | app/maps/application_map.rb | 3 | ||||
| -rw-r--r-- | app/views/route_sections_selectors/edit.html.erb | 2 | 
3 files changed, 48 insertions, 16 deletions
diff --git a/app/assets/javascripts/route_section.js.coffee b/app/assets/javascripts/route_section.js.coffee index f2e494c0c..74f095772 100644 --- a/app/assets/javascripts/route_section.js.coffee +++ b/app/assets/javascripts/route_section.js.coffee @@ -4,6 +4,7 @@ class @RouteSectionMap      routeSectionOption = $("option[value=#{route_section_id}]")      routeSectionOption.parent().val route_section_id +    RouteSectionMap.changeStyle(routeSectionOption.parent())      $('#map-selection').show()      $('#empty-map-selection').hide() @@ -16,7 +17,49 @@ class @RouteSectionMap      $('#map-selection').hide()      $('#empty-map-selection').show() +  @editRoute = (el) -> +    new_route_section_id = $(el).val() +    edit_link = $(el).closest("tr").find("a.edit-route-section") + +    # Save edit link to play with it +    unless edit_link.data("href-pattern")? +      edit_link.data "href-pattern", edit_link.attr('href').replace(new RegExp("/route_sections/([0-9]+)/edit"), "/route_sections/:id/edit") + +    if !!new_route_section_id +      edit_link.removeClass "disabled" +      edit_link.attr 'href', edit_link.data("href-pattern").replace(/:id/, new_route_section_id) +    else +      edit_link.addClass "disabled" +      edit_link.attr 'href', '#' + +  @featureStyle = (id, erase) -> +    if id +      features = route_section_geometry.getFeaturesByAttribute('id', id.toString()) +      if features.length > 0 +        feature = features[0] +        style = null +        if !erase +          style = +            strokeWidth: 3 +            strokeColor: 'green' +        feature.style = style +        feature.layer.redraw() + +  @changeStyle = (el) -> +    id = $(el).val() +    options = $(el).find('option').map(-> +      $(this).val() +    ) +    $.each options, (key, value) -> +      RouteSectionMap.featureStyle value, true +      return +    RouteSectionMap.featureStyle id, false +  jQuery -> +  $route_sections_selector = $('[name^="route_sections_selector[sections_attributes]"]') +  $.each $route_sections_selector, (index, el) -> +    RouteSectionMap.changeStyle el +    if $("#map.route_section").length > 0 and user_geometry?      projWGS84 = new OpenLayers.Projection("EPSG:4326")      proj900913 = new OpenLayers.Projection("EPSG:900913") @@ -33,20 +76,8 @@ jQuery ->      })    $('#new_route_sections_selector select').on 'change', -> -    new_route_section_id = $(this).val() - -    edit_link = $(this).closest("tr").find("a.edit-route-section") - -    # Save edit link to play with it -    unless edit_link.data("href-pattern")? -      edit_link.data "href-pattern", edit_link.attr('href').replace(new RegExp("/route_sections/([0-9]+)/edit"), "/route_sections/:id/edit") - -    if !!new_route_section_id -      edit_link.removeClass "disabled" -      edit_link.attr 'href', edit_link.data("href-pattern").replace(/:id/, new_route_section_id) -    else -      edit_link.addClass "disabled" -      edit_link.attr 'href', '#' +    RouteSectionMap.changeStyle this +    RouteSectionMap.editRoute this    $('form.route_section').find('button[type="submit"]').on 'click', (e) ->      e.preventDefault(); diff --git a/app/maps/application_map.rb b/app/maps/application_map.rb index 6de0ff8c2..25b1fc10a 100644 --- a/app/maps/application_map.rb +++ b/app/maps/application_map.rb @@ -73,7 +73,8 @@ class ApplicationMap    def to_html(options = {})      if not respond_to?(:ready?) or ready? -      "<div id=\"#{id}\" class=\"#{default_class}\"><button data-ce-id=\"#{id}\" data-ce-action=\"map-fullscreen\" class=\"ce-MapExpandBlock\"><i class=\"fa fa-expand\"></i></button></div> #{map.to_html(options)}".html_safe +      expand = options[:no_fullscreen] ? '' : "<button data-ce-id=\"#{id}\" data-ce-action=\"map-fullscreen\" class=\"ce-MapExpandBlock\"><i class=\"fa fa-expand\"></i></button>" +      "<div id=\"#{id}\" class=\"#{default_class}\">#{expand}</div>#{map.to_html(options)}".html_safe      end    end diff --git a/app/views/route_sections_selectors/edit.html.erb b/app/views/route_sections_selectors/edit.html.erb index 0cd58d9c1..a60b8b95b 100644 --- a/app/views/route_sections_selectors/edit.html.erb +++ b/app/views/route_sections_selectors/edit.html.erb @@ -1,7 +1,7 @@  <%= title_tag t('.title', journey_pattern: journey_name(@journey_pattern)) %>  <div class = "large-map"> -  <%= @map.to_html %> +  <%= @map.to_html(no_fullscreen: true) %>  </div>  <%= semantic_form_for resource, url: referential_line_route_journey_pattern_route_sections_selector_path(@referential, @line, @route, @journey_pattern), method: :put do |form| %>  | 
