aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/select2.coffee17
-rw-r--r--app/models/chouette/stop_area.rb4
-rw-r--r--app/views/autocomplete_stop_areas/index.rabl3
-rw-r--r--app/views/stop_areas/_form.html.slim3
4 files changed, 18 insertions, 9 deletions
diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee
index 2e3884d7f..8e3c3cbdd 100644
--- a/app/assets/javascripts/select2.coffee
+++ b/app/assets/javascripts/select2.coffee
@@ -9,24 +9,27 @@ bind_select2 = (el, cfg = {}) ->
target.select2 $.extend({}, default_cfg, cfg)
bind_select2_ajax = (el, cfg = {}) ->
- target = $(el)
+ _this = $(el)
cfg =
ajax:
data: (params) ->
- q:
- "#{target.data('term')}": params.term
- url: target.data('url'),
+ if _this.data('term')
+ { q: "#{_this.data('term')}": params.term }
+ else
+ { q: params.term }
+ url: _this.data('url'),
dataType: 'json',
delay: 125,
processResults: (data, params) -> results: data
- minimumInputLength: 1
- placeholder: target.data('select2ed-placeholder')
templateResult: (item) ->
item.text
templateSelection: (item) ->
item.text
escapeMarkup: (markup) ->
markup
+ initSelection : (item, callback) ->
+ if _this.data('saved')
+ callback(_this.data('saved'))
bind_select2(el, cfg)
@@ -40,7 +43,5 @@ bind_select2_ajax = (el, cfg = {}) ->
$('select.form-control.tags').each ->
bind_select2(this, {tags: true})
-
-
$ ->
select_2()
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index 2f8d7c096..1dfdac724 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -74,6 +74,10 @@ module Chouette
end
end
+ def full_name
+ "#{name} #{zip_code} #{city_name} - #{user_objectid}"
+ end
+
def user_objectid
if objectid =~ /^.*:([0-9A-Za-z_-]+):STIF$/
$1
diff --git a/app/views/autocomplete_stop_areas/index.rabl b/app/views/autocomplete_stop_areas/index.rabl
index 5a9f76a47..d20051ad5 100644
--- a/app/views/autocomplete_stop_areas/index.rabl
+++ b/app/views/autocomplete_stop_areas/index.rabl
@@ -14,7 +14,8 @@ node do |stop_area|
:longitude => stop_area.longitude,
:latitude => stop_area.latitude,
:area_type => stop_area.area_type,
- :comment => stop_area.comment
+ :comment => stop_area.comment,
+ :text => stop_area.full_name
}
end
diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim
index e44680499..078df5daf 100644
--- a/app/views/stop_areas/_form.html.slim
+++ b/app/views/stop_areas/_form.html.slim
@@ -6,6 +6,9 @@
/= @map.to_html
= f.input :id, as: :hidden
= f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")}
+
+ = f.input :parent_id, as: :select, input_html: { data: { select2_ajax: 'true', url: referential_autocomplete_stop_areas_path(@stop_area_referential), saved: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}}
+
= f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options, :include_blank => false
.location_info