From 83ef73e839e2b9efd71fe74ab993cdf1ffa66903 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 18 Sep 2014 08:39:57 +0200 Subject: Fix data-pre render for stop areas and add time_table with token input Refs #0028814 --- app/inputs/search_stop_area_input.rb | 2 +- app/inputs/search_time_table_input.rb | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/inputs/search_time_table_input.rb (limited to 'app/inputs') diff --git a/app/inputs/search_stop_area_input.rb b/app/inputs/search_stop_area_input.rb index 8003a513a..44f9cf82a 100644 --- a/app/inputs/search_stop_area_input.rb +++ b/app/inputs/search_stop_area_input.rb @@ -13,7 +13,7 @@ class SearchStopAreaInput < Formtastic::Inputs::SearchInput noResultsText: '#{options[:no_result_text]}', searchingText: '#{options[:searching_text]}', resultsFormatter: function(item){ return '
  • ' + item.name + '
    ' + item.area_type + '
    ' + item.zip_code + ' ' + item.city_name + '
  • ' }, - tokenFormatter: function(item) { return '
  • ' + item.name + '

  • ' } + tokenFormatter: function(item){ return '
  • ' + item.name + '
    ' + item.area_type + '
    ' + item.zip_code + ' ' + item.city_name + '
  • ' }, }); });").html_safe) end diff --git a/app/inputs/search_time_table_input.rb b/app/inputs/search_time_table_input.rb new file mode 100644 index 000000000..49f266d7a --- /dev/null +++ b/app/inputs/search_time_table_input.rb @@ -0,0 +1,40 @@ +class SearchTimeTableInput < Formtastic::Inputs::SearchInput + + def search + if options[:json] + tokenLimit = options[:tokenLimit].present? ? options[:tokenLimit] : "null" + template.content_tag( :script, + ("$(document).ready(function() { + $('##{dom_id}').tokenInput('#{options[:json]}', { + crossDomain: false, + tokenLimit: #{tokenLimit}, + minChars: 2, + preventDuplicates: true, + hintText: '#{options[:hint_text]}', + noResultsText: '#{options[:no_result_text]}', + searchingText: '#{options[:searching_text]}', + resultsFormatter: function(item){ return '
  • ' + item.comment + '
    ' + item.time_table_bounding + '
    ' + item.composition_info + '
  • ' }, + tokenFormatter: function(item){ return '
  • ' + item.comment + '
    ' + item.time_table_bounding + '
    ' + item.composition_info + '
  • ' }, + }); + });").html_safe) + end + end + + def to_html + input_wrapping do + label_html << + builder.search_field(method, input_html_options) << + search + end + end + + def input_html_options + super.merge({ + :required => nil, + :autofocus => nil, + :class => 'token-input', + 'data-model-name' => object.class.model_name.human + }) + end + +end -- cgit v1.2.3