diff options
| -rw-r--r-- | app/assets/javascripts/select2.coffee | 8 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 22 | ||||
| -rw-r--r-- | app/inputs/tags_input.rb | 31 | ||||
| -rw-r--r-- | app/views/time_tables/_form.html.slim | 5 |
4 files changed, 46 insertions, 20 deletions
diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee index edd4c476d..e20ef8d32 100644 --- a/app/assets/javascripts/select2.coffee +++ b/app/assets/javascripts/select2.coffee @@ -7,5 +7,13 @@ placeholder: target.data('select2ed-placeholder') allowClear: true + $('select.form-control.tags').each -> + target = $(this) + target.select2 + theme: 'bootstrap' + language: 'fr' + allowClear: true + tags: true + $(document).on 'ready page:load', select_2 diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index bdde5d3ab..50c925eac 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -117,6 +117,26 @@ class TimeTablesController < ChouetteController private def time_table_params - params.require(:time_table).permit( :objectid, :object_version, :creator_id, :calendar_id, :version, :comment, :int_day_types, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, :tag_list, :tag_search ) + params.require(:time_table).permit( + :objectid, + :object_version, + :creator_id, + :calendar_id, + :version, :comment, + :int_day_types, + :monday, + :tuesday, + :wednesday, + :thursday, + :friday, + :saturday, + :sunday, + :start_date, + :end_date, + { :dates_attributes => [:date, :in_out, :id, :_destroy] }, + { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, + {tag_list: []}, + :tag_search + ) end end diff --git a/app/inputs/tags_input.rb b/app/inputs/tags_input.rb index 4fbf0465f..1dc6129ee 100644 --- a/app/inputs/tags_input.rb +++ b/app/inputs/tags_input.rb @@ -1,19 +1,16 @@ -class TagsInput < Formtastic::Inputs::StringInput - - def to_html - input_wrapping do - label_html << - '<span id="tagsContainer"></span>'.html_safe << - builder.text_field(method, input_html_options) - end +class TagsInput < SimpleForm::Inputs::CollectionInput + enable :placeholder + + def input(wrapper_options = {}) + @collection ||= @builder.object.send(attribute_name) + label_method, value_method = detect_collection_methods + + merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) + merged_input_options.reverse_merge!(multiple: true) + + @builder.collection_select( + attribute_name, collection, value_method, label_method, + input_options, merged_input_options + ) end - - def input_html_options - super.merge({ - :required => nil, - :autofocus => nil, - :class => 'tm-input', - }) - end - end diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index 94af1bd01..a02d65188 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -4,8 +4,9 @@ .col-lg-12 = form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")} = form.input :version - = form.input :tag_search, as: :select, :input_html => { :id => "tag_search",:placeholder => t("formtastic.placeholders.time_table.tag_search") } - = form.input :tag_list, as: :hidden, :input_html => { :id => "tag_list" } + + = form.input :tag_list, as: :tags + = form.input :objectid, :required => !@time_table.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.objectid")} - if @time_table.new_record? = form.input :calendar, as: :select, collection: current_organisation.calendars |
