diff options
| author | Xinhui | 2017-12-26 13:44:34 +0100 |
|---|---|---|
| committer | Xinhui | 2017-12-26 13:44:34 +0100 |
| commit | 1e9b030411b11c1027695196b878b69d8301ddc8 (patch) | |
| tree | c6b6d8a8bb6b77a3c707477fcc45ad78e2c6a4c0 /app | |
| parent | 9fe0ca13d7caba486561f52557c1fa3d2f9f0a52 (diff) | |
| download | chouette-core-1e9b030411b11c1027695196b878b69d8301ddc8.tar.bz2 | |
Select2 stop_area form parent_id field
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/javascripts/select2.coffee | 17 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 4 | ||||
| -rw-r--r-- | app/views/autocomplete_stop_areas/index.rabl | 3 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 3 |
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 |
