From 0b6371b7248a2a731683d20f8b8bc12eb5f35bad Mon Sep 17 00:00:00 2001 From: jpl Date: Fri, 16 Jun 2017 11:37:20 +0200 Subject: Refs #3789: changing select input by select2 one --- app/assets/javascripts/select2.coffee | 1 + app/views/calendars/_form.html.slim | 4 ++-- app/views/routes/_form.html.slim | 4 ++-- app/views/time_table_combinations/_form.html.slim | 12 ++++++------ app/views/time_tables/_form.html.slim | 2 +- config/initializers/simple_form_bootstrap.rb | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee index 5adaabda5..d54ddb811 100644 --- a/app/assets/javascripts/select2.coffee +++ b/app/assets/javascripts/select2.coffee @@ -20,6 +20,7 @@ bind_select2_ajax = (el, cfg = {}) -> delay: 125, processResults: (data, params) -> results: data minimumInputLength: 3 + placeholder: target.data('select2ed-placeholder') templateResult: (item) -> item.text templateSelection: (item) -> diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim index 9aed9f7d8..3c152c61d 100644 --- a/app/views/calendars/_form.html.slim +++ b/app/views/calendars/_form.html.slim @@ -6,8 +6,8 @@ - if policy(@calendar).share? .form-group.has_switch - = f.label :shared, class: 'col-sm-4 control-label' - = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8'} + = f.label :shared, class: 'col-sm-4 col-xs-5 control-label' + = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8 col-xs-7'} .separator diff --git a/app/views/routes/_form.html.slim b/app/views/routes/_form.html.slim index ad389c482..bee86f91e 100644 --- a/app/views/routes/_form.html.slim +++ b/app/views/routes/_form.html.slim @@ -6,8 +6,8 @@ = f.input :published_name .form-group.has_switch - = f.label :wayback, class: 'col-sm-4 control-label' - = f.input :wayback, as: :boolean, checked_value: :straight_forward, unchecked_value: :backward, label: content_tag(:span, @route.wayback_text, class: 'switch-label', data: {checkedValue: t('enumerize.route.direction.straight_forward'), uncheckedValue: t('enumerize.route.direction.backward')}), wrapper_html: { class: 'col-sm-8'} + = f.label :wayback, class: 'col-sm-4 col-xs-5 control-label' + = f.input :wayback, as: :boolean, checked_value: :straight_forward, unchecked_value: :backward, label: content_tag(:span, @route.wayback_text, class: 'switch-label', data: {checkedValue: t('enumerize.route.direction.straight_forward'), uncheckedValue: t('enumerize.route.direction.backward')}), wrapper_html: { class: 'col-sm-8 col-xs-7'} = f.input :opposite_route_id, collection: @forward, disabled: @route.wayback.straight_forward?, wrapper_html: {class: input_opposite_route_id_css(@route, 'straight_forward')} diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim index d8bebf0c4..b4f818828 100644 --- a/app/views/time_table_combinations/_form.html.slim +++ b/app/views/time_table_combinations/_form.html.slim @@ -2,21 +2,21 @@ .row .col-lg-12 .form-group.has_switch - = f.label :combined_type, class: 'col-sm-4 control-label required' do + = f.label :combined_type, class: 'col-sm-4 col-xs-5 control-label required' do = 'Type de calendriers ' abbr title='Champ requis' * - = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8' } + = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' } - = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', term: 'comment_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} + = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} - = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''} + = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''} .separator .row .col-lg-12 - = f.label :operation, class: 'col-sm-4 control-label' - = f.input :operation, as: :radio_buttons, label: false, collection: TimeTableCombination.operations, label_method: lambda{|o| t("time_table_combinations.operations.#{o}")}, wrapper_html: { class: 'col-sm-8' } + = f.label :operation, class: 'col-sm-4 col-xs-5 control-label' + = f.input :operation, as: :radio_buttons, label: false, collection: TimeTableCombination.operations, label_method: lambda{|o| t("time_table_combinations.operations.#{o}")}, wrapper_html: { class: 'col-sm-8 col-xs-7' } = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'tt_combination_form' diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index d4e1d838e..d06fdf444 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -5,7 +5,7 @@ = form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")} - if @time_table.new_record? && !@time_table.created_from - = form.input :calendar_id, as: :select, collection: current_organisation.calendars + = form.input :calendar_id, as: :select, input_html: { class: 'tt_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}} - if @time_table.created_from = form.input :created_from, disabled: true, input_html: { value: @time_table.created_from.comment } diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index 67dfe1ceb..d90ea6398 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -58,9 +58,9 @@ SimpleForm.setup do |config| b.optional :pattern b.optional :min_max b.optional :readonly - b.use :label, class: 'col-sm-4 control-label' + b.use :label, class: 'col-sm-4 col-xs-5 control-label' - b.wrapper tag: 'div', class: 'col-sm-8' do |ba| + b.wrapper tag: 'div', class: 'col-sm-8 col-xs-7' do |ba| ba.use :input, class: 'form-control' ba.use :error, wrap_with: { tag: 'span', class: 'help-block small' } ba.use :hint, wrap_with: { tag: 'p', class: 'help-block small' } -- cgit v1.2.3