diff --git a/Gemfile b/Gemfile index 15c640607..5ce860275 100644 --- a/Gemfile +++ b/Gemfile @@ -56,7 +56,7 @@ gem 'jquery-rails', '~> 2.3' gem 'jquery-migrate-rails' gem 'ruby-haml-js', '~> 0.0.5' gem 'slim' -gem 'simple_form' +gem 'simple_form', '3.1.0.rc2' gem 'friendly_id', '~> 5.0' gem 'rack-throttle', '~> 0.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index b7c7a2616..38cd1b653 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -450,7 +450,7 @@ GEM shoulda-context (1.2.1) shoulda-matchers (2.6.2) activesupport (>= 3.0.0) - simple_form (3.0.2) + simple_form (3.1.0.rc2) actionpack (~> 4.0) activemodel (~> 4.0) sinatra (1.4.5) @@ -615,7 +615,7 @@ DEPENDENCIES shotgun shoulda shoulda-matchers - simple_form + simple_form (= 3.1.0.rc2) sitemap_generator skype slim diff --git a/app/controllers/platforms/mass_builds_controller.rb b/app/controllers/platforms/mass_builds_controller.rb index 8feef68c3..1ac10528d 100644 --- a/app/controllers/platforms/mass_builds_controller.rb +++ b/app/controllers/platforms/mass_builds_controller.rb @@ -14,7 +14,8 @@ class Platforms::MassBuildsController < Platforms::BaseController @mass_build = @platform.mass_builds.find(params[:mass_build_id]).dup @mass_build.arches = Arch.where(name: @mass_build.arch_names.split(', ')).pluck(:id) end - @mass_build.arches ||= @platform.platform_arch_settings.by_default.pluck(:arch_id) + @mass_build.arches ||= @platform.platform_arch_settings.by_default.pluck(:arch_id) + @mass_build.repositories ||= [] @mass_build.arches.map!(&:to_s) end @@ -22,7 +23,9 @@ class Platforms::MassBuildsController < Platforms::BaseController end def create - @mass_build.user, @mass_build.arches = current_user, params[:arches] || [] + @mass_build.user = current_user + @mass_build.arches = params[:arches] || [] + @mass_build.repositories ||= params[:repositories] || [] if @mass_build.save redirect_to(platform_mass_builds_path(@platform), notice: t("flash.platform.build_all_success")) diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index b1a9269e0..a298b3209 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -40,7 +40,6 @@ class Platforms::PlatformsController < Platforms::BaseController redirect_to @platform else flash[:error] = I18n.t("flash.platform.create_error") - flash[:warning] = @platform.errors.full_messages.join('. ') render action: :new end end @@ -61,7 +60,6 @@ class Platforms::PlatformsController < Platforms::BaseController redirect_to @platform else flash[:error] = I18n.t("flash.platform.save_error") - flash[:warning] = @platform.errors.full_messages.join('. ') render action: :edit end end diff --git a/app/helpers/mass_build_helper.rb b/app/helpers/mass_build_helper.rb index d3821129f..ea5bf5eeb 100644 --- a/app/helpers/mass_build_helper.rb +++ b/app/helpers/mass_build_helper.rb @@ -24,6 +24,12 @@ module MassBuildHelper } ] + def mass_build_platform_options + Platform.main.each do |p| + [ p.name, p.id ] + end + end + def link_to_list platform, mass_build, which link_to t("layout.mass_builds.#{which}"), get_list_platform_mass_build_path(platform, mass_build, kind: which, format: :txt), diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index e76edef72..f1a00511a 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -44,11 +44,12 @@ class MassBuild < ActiveRecord::Base scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) } scope :search, -> (q) { where("#{table_name}.description ILIKE ?", "%#{q}%") if q.present? } - attr_accessor :arches + attr_accessor :arches, :repositories attr_accessible :arches, :auto_publish_status, :projects_list, :build_for_platform_id, :extra_repositories, :extra_build_lists, :increase_release_tag, :use_cached_chroot, :use_extra_tests, :description, :extra_mass_builds, - :include_testing_subrepository, :auto_create_container, :external_nodes + :include_testing_subrepository, :auto_create_container, :external_nodes, + :repositories validates :save_to_platform_id, :build_for_platform_id, diff --git a/app/views/platforms/contents/index.html.slim b/app/views/platforms/contents/index.html.slim index e3290145a..1baeb0668 100644 --- a/app/views/platforms/contents/index.html.slim +++ b/app/views/platforms/contents/index.html.slim @@ -10,28 +10,13 @@ #contents ng-controller='ContentsController' = simple_form_for @platform, html: { 'ng-submit' => 'search()', id: 'search_contents_form' } do |f| - fieldset - = f.hidden_field :name - = hidden_field_tag 'path' - = hidden_field_tag 'page' - = f.input :term + = f.hidden_field :name + = hidden_field_tag 'path' + = hidden_field_tag 'page' + = f.input :term - .button_block - button type="submit" class="btn btn-default" data-disable-with=t('layout.processing') - = t('layout.search.header') - - / input name='term' type='text' placeholder=t('layout.platforms.search_contents') - / |   - / = f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}, class: 'btn btn-sm btn-primary' - - / = form_for @platform, html: { class: :form, 'ng-submit' => 'search()', id: 'search_contents_form' } do |f| - / = f.hidden_field :name - / = hidden_field_tag 'path' - / = hidden_field_tag 'page' - / input name='term' type='text' placeholder=t('layout.platforms.search_contents') - / |   - / = f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}, class: 'btn btn-sm btn-primary' - br + = f.button :submit, t('layout.search.header') + hr .path a ng-repeat='folder in folders' diff --git a/app/views/platforms/key_pairs/_new.html.slim b/app/views/platforms/key_pairs/_new.html.slim index 8b47ef30a..ed429c0eb 100644 --- a/app/views/platforms/key_pairs/_new.html.slim +++ b/app/views/platforms/key_pairs/_new.html.slim @@ -2,12 +2,8 @@ h3 = t("layout.key_pairs.header") = simple_form_for @key_pair, url: platform_key_pairs_path(@platform) do |f| + = f.input :public, as: :text + = f.input :secret, as: :text + = f.input :repository_id, collection: key_pair_repository_options(@platform) - fieldset - = f.input :public, as: :text - = f.input :secret, as: :text - = f.input :repository_id, collection: key_pair_repository_options(@platform) - - .button_block - button type="submit" class="btn btn-default" data-disable-with=t('layout.saving') - = t('layout.save') \ No newline at end of file + = f.button :submit, t('layout.save') \ No newline at end of file diff --git a/app/views/platforms/key_pairs/index.html.slim b/app/views/platforms/key_pairs/index.html.slim index a062bf3a5..6524d6fd2 100644 --- a/app/views/platforms/key_pairs/index.html.slim +++ b/app/views/platforms/key_pairs/index.html.slim @@ -3,5 +3,7 @@ .container .row - = render 'new' if can? :edit, @platform + - if can? :edit, @platform + = render 'new' + hr = render 'list' diff --git a/app/views/platforms/maintainers/_list.html.slim b/app/views/platforms/maintainers/_list.html.slim index af49345d4..7c30e34c3 100644 --- a/app/views/platforms/maintainers/_list.html.slim +++ b/app/views/platforms/maintainers/_list.html.slim @@ -1,13 +1,13 @@ = simple_form_for @maintainer, url: platform_maintainers_path(@platform), method: :get do |f| - fieldset - = f.input :name - .button_block - = submit_tag t('layout.search.header'), data: {'disable-with' => t('layout.processing')}, class: 'btn btn-sm btn-primary' - |   - = t('layout.or') - |   - a href=platform_maintainers_path(@platform) - = t('layout.clear') + = f.input :name + + = f.button :submit, t('layout.search.header') + |   + = t('layout.or') + |   + a href=platform_maintainers_path(@platform) + = t('layout.clear') +hr table.table.table-striped thead tr diff --git a/app/views/platforms/mass_builds/index.html.slim b/app/views/platforms/mass_builds/index.html.slim index 390f93956..5c151f64b 100644 --- a/app/views/platforms/mass_builds/index.html.slim +++ b/app/views/platforms/mass_builds/index.html.slim @@ -15,7 +15,7 @@ .button_block button type="submit" class="btn btn-default" data-disable-with=t('layout.processing') = t('layout.search.header') - + hr table.table.table-striped thead tr diff --git a/app/views/platforms/mass_builds/new.html.haml b/app/views/platforms/mass_builds/new.html.haml deleted file mode 100644 index 91f13db07..000000000 --- a/app/views/platforms/mass_builds/new.html.haml +++ /dev/null @@ -1,64 +0,0 @@ -- set_meta_tags title: [title_object(@platform), t('layout.mass_builds.new')] - -= render 'platforms/base/submenu' -= render 'platforms/base/sidebar' - -= form_for [@platform, @mass_build], html: { class: 'form mass_build', method: :post } do |f| - %section.left - %h3=t('layout.mass_builds.repositories') - - @platform.repositories.each do |rep| - .both - = check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), id: "repositories_#{rep.id}", href: "#{projects_list_platform_repository_path(@platform, rep)}?text=true" - = label_tag "repositories_#{rep.id}", rep.name - %h3=t('activerecord.attributes.mass_build.description') - = f.text_area :description - %br - %h3=t('layout.mass_builds.projects_list') - = f.text_area :projects_list - %br - = f.submit t('layout.projects.build_button'), data: {'disable-with' => t('layout.processing')} - %section.right - %h3= t("activerecord.attributes.build_list.arch") - - Arch.recent.each do |arch| - .lefter - = check_box_tag "arches[]", arch.id, @mass_build.arches.include?(arch.id.to_s), id: "arches_#{arch.id}" - = label_tag "arches_#{arch.id}", arch.name - .both - - if @platform.personal? - %h3= t('activerecord.attributes.build_list.build_for_platform') - = f.collection_select :build_for_platform_id, Platform.main, :id, :name - .both - = hidden_field_tag :autocomplete_extra_repos_path, - "#{autocomplete_extra_repositories_autocompletes_path}?#{{platform_id: @mass_build.save_to_platform.try(:id)}.to_param}" - = render 'shared/autocomplete_form', - field: :extra_repositories, - field_class: Repository, - placeholder: 'uxteam_personal', - subject: @mass_build, - autocomplete_path: autocomplete_extra_repositories_autocompletes_path - = render 'shared/autocomplete_form', - field: :extra_mass_builds, - field_class: MassBuild, - placeholder: '1000000', - subject: @mass_build, - autocomplete_path: autocomplete_extra_mass_build_autocompletes_path - = render 'shared/autocomplete_form', - field: :extra_build_lists, - field_class: BuildList, - placeholder: '1000000', - subject: @mass_build, - autocomplete_path: autocomplete_extra_build_list_autocompletes_path - %h3= t("activerecord.attributes.build_list.preferences") - .both - = f.select :auto_publish_status, auto_publish_statuses - = f.label :auto_publish_status - - %i(auto_create_container increase_release_tag include_testing_subrepository use_cached_chroot use_extra_tests).each do |field| - .both - = f.check_box field - = f.label field - - .both - = f.select :external_nodes, external_nodes, include_blank: true - = f.label :external_nodes - -.both diff --git a/app/views/platforms/mass_builds/new.html.slim b/app/views/platforms/mass_builds/new.html.slim new file mode 100644 index 000000000..4e2539fb8 --- /dev/null +++ b/app/views/platforms/mass_builds/new.html.slim @@ -0,0 +1,106 @@ +- set_meta_tags title: [title_object(@platform), t('layout.mass_builds.new')] + += render 'platforms/base/submenu' + +.container + + .row + = simple_form_for @mass_build, url: platform_mass_builds_path(@platform) do |f| + .col-md-6 + .row + .col-md-6 + b + = t('layout.mass_builds.repositories') + - @platform.repositories.each do |rep| + .checkbox + label + input[type = "checkbox" + value = rep.id + name = 'repositories[]' + checked = @mass_build.repositories.include?(rep.id.to_s)] + = rep.name + / = check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), id: "repositories_#{rep.id}", href: "#{projects_list_platform_repository_path(@platform, rep)}?text=true" + / = label_tag "repositories_#{rep.id}", rep.name + .col-md-6 + = f.input :projects_list, as: :text + .row + .col-md-12 + = f.input :description, as: :text + + .col-md-6 + .row + .col-md-6 + b + = t("activerecord.attributes.build_list.arch") + - Arch.recent.each do |arch| + .checkbox + label + input[type="checkbox" value=arch.id name='arches[]' + checked=@mass_build.arches.include?(arch.id.to_s)] + = arch.name + .col-md-6 + - if @platform.personal? + = f.input :build_for_platform_id, collection: mass_build_platform_options + + + = f.button :submit, t('layout.projects.build_button') + +/ = form_for [@platform, @mass_build], html: { class: 'form mass_build', method: :post } do |f| +/ %section.left +/ %h3=t('layout.mass_builds.repositories') +/ - @platform.repositories.each do |rep| +/ .both +/ = check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), id: "repositories_#{rep.id}", href: "#{projects_list_platform_repository_path(@platform, rep)}?text=true" +/ = label_tag "repositories_#{rep.id}", rep.name +/ %h3=t('activerecord.attributes.mass_build.description') +/ = f.text_area :description +/ %br +/ %h3=t('layout.mass_builds.projects_list') +/ = f.text_area :projects_list +/ %br +/ = f.submit t('layout.projects.build_button'), data: {'disable-with' => t('layout.processing')} +/ %section.right +/ %h3= t("activerecord.attributes.build_list.arch") +/ - Arch.recent.each do |arch| +/ .lefter +/ = check_box_tag "arches[]", arch.id, @mass_build.arches.include?(arch.id.to_s), id: "arches_#{arch.id}" +/ = label_tag "arches_#{arch.id}", arch.name +/ .both +/ - if @platform.personal? +/ %h3= t('activerecord.attributes.build_list.build_for_platform') +/ = f.collection_select :build_for_platform_id, Platform.main, :id, :name +/ .both +/ = hidden_field_tag :autocomplete_extra_repos_path, +/ "#{autocomplete_extra_repositories_autocompletes_path}?#{{platform_id: @mass_build.save_to_platform.try(:id)}.to_param}" +/ = render 'shared/autocomplete_form', +/ field: :extra_repositories, +/ field_class: Repository, +/ placeholder: 'uxteam_personal', +/ subject: @mass_build, +/ autocomplete_path: autocomplete_extra_repositories_autocompletes_path +/ = render 'shared/autocomplete_form', +/ field: :extra_mass_builds, +/ field_class: MassBuild, +/ placeholder: '1000000', +/ subject: @mass_build, +/ autocomplete_path: autocomplete_extra_mass_build_autocompletes_path +/ = render 'shared/autocomplete_form', +/ field: :extra_build_lists, +/ field_class: BuildList, +/ placeholder: '1000000', +/ subject: @mass_build, +/ autocomplete_path: autocomplete_extra_build_list_autocompletes_path +/ %h3= t("activerecord.attributes.build_list.preferences") +/ .both +/ = f.select :auto_publish_status, auto_publish_statuses +/ = f.label :auto_publish_status +/ - %i(auto_create_container increase_release_tag include_testing_subrepository use_cached_chroot use_extra_tests).each do |field| +/ .both +/ = f.check_box field +/ = f.label field + +/ .both +/ = f.select :external_nodes, external_nodes, include_blank: true +/ = f.label :external_nodes + +/ .both diff --git a/app/views/platforms/platforms/_form.html.slim b/app/views/platforms/platforms/_form.html.slim index 9baf9ca67..84dc2eff8 100644 --- a/app/views/platforms/platforms/_form.html.slim +++ b/app/views/platforms/platforms/_form.html.slim @@ -1,71 +1,65 @@ -fieldset +- unless %w(edit update).include? controller.action_name + = f.input :name - - unless %w(edit update).include? controller.action_name - = f.input :name += f.input :description, as: :text - = f.input :description, as: :text +- unless %w(edit update).include? controller.action_name + = f.input :distrib_type, + collection: APP_CONFIG['distr_types'], + include_blank: false - - unless %w(edit update).include? controller.action_name - = f.input :distrib_type, - collection: APP_CONFIG['distr_types'], - include_blank: false + = f.input :visibility, + collection: platform_visibility_options, + include_blank: false - = f.input :visibility, - collection: platform_visibility_options, - include_blank: false +- unless @platform.personal? + = f.input :released, as: :boolean, wrapper: :vertical_boolean + = f.input :admin_id, + url: autocomplete_user_uname_autocompletes_path, + as: :autocomplete, + id_element: '#admin_id_field', + input_html: { value: @admin_uname, class: 'form-control' } + = hidden_field_tag 'admin_id', @admin_id, id: 'admin_id_field' + +- if %w(edit update).include? controller.action_name + + - if can? :change_visibility, @platform + dl.dl-horizontal + dt + = t('activerecord.attributes.platform.visibility') + dd + = link_to t("layout.platforms.change_visibility_from_#{@platform.visibility}"), + change_visibility_platform_path(@platform), + method: :post, + data: { confirm: t("layout.platforms.confirm_change_visibility") }, + class: 'btn btn-xs btn-warning' - unless @platform.personal? - = f.input :released, as: :boolean - = f.input :admin_id, - url: autocomplete_user_uname_autocompletes_path, - as: :autocomplete, - id_element: '#admin_id_field', - input_html: { value: @admin_uname } - = hidden_field_tag 'admin_id', @admin_id, id: 'admin_id_field' - - - if %w(edit update).include? controller.action_name - - - if can? :change_visibility, @platform - dl.dl-horizontal - dt - = t('activerecord.attributes.platform.visibility') - dd - = link_to t("layout.platforms.change_visibility_from_#{@platform.visibility}"), - change_visibility_platform_path(@platform), - method: :post, - data: { confirm: t("layout.platforms.confirm_change_visibility") }, - class: 'btn btn-xs btn-warning' - - - unless @platform.personal? - h3 - = t('layout.platform_arch_settings.extra_settings') - table.table - thead + h3 + = t('layout.platform_arch_settings.extra_settings') + table.table + thead + tr + th.lpadding16= t("activerecord.models.arch") + th.lpadding16= t("activerecord.attributes.platform_arch_setting.default") + th.lpadding16= t("activerecord.attributes.platform_arch_setting.time_living") + tbody + - platform_arch_settings(@platform).each do |setting| tr - th.lpadding16= t("activerecord.models.arch") - th.lpadding16= t("activerecord.attributes.platform_arch_setting.default") - th.lpadding16= t("activerecord.attributes.platform_arch_setting.time_living") - tbody - - platform_arch_settings(@platform).each do |setting| - tr - = f.fields_for :platform_arch_settings, setting do |s_form| - td - = setting.arch.name - = s_form.hidden_field :arch_id - td.center - = s_form.input :default, as: :boolean, label: false - td.right - = s_form.input :time_living, - input_html: { value: setting.time_living / 60 }, - label: false - - -.button_block - button type="submit" class="btn btn-default" data-disable-with=t('layout.saving') - = t('layout.save') - |   - = t('layout.or') - |   - = link_to t('layout.cancel'), - @platform.new_record? ? root_path : platform_path(@platform) + = f.fields_for :platform_arch_settings, setting do |s_form| + td + = setting.arch.name + = s_form.hidden_field :arch_id + td.center + = s_form.input :default, as: :boolean, label: false + td.right + = s_form.input :time_living, + input_html: { value: setting.time_living / 60 }, + label: false += f.button :submit, t('layout.save') +|   += t('layout.or') +|   +a href=(@platform.new_record? ? root_path : platform_path(@platform)) + = t('layout.cancel') diff --git a/app/views/platforms/platforms/edit.html.slim b/app/views/platforms/platforms/edit.html.slim index afd3c0810..4a9d05746 100644 --- a/app/views/platforms/platforms/edit.html.slim +++ b/app/views/platforms/platforms/edit.html.slim @@ -5,8 +5,8 @@ .row = simple_form_for @platform do |f| = render 'form', f: f - - .row.well + hr + .row - if can? :regenerate_metadata, @platform h4= t('layout.platforms.metadata') diff --git a/app/views/platforms/tokens/index.html.slim b/app/views/platforms/tokens/index.html.slim index 9a5172f81..2f929ca3b 100644 --- a/app/views/platforms/tokens/index.html.slim +++ b/app/views/platforms/tokens/index.html.slim @@ -4,6 +4,7 @@ .row a.btn.btn-primary href=new_platform_token_path(@platform) = t('layout.tokens.new') + hr .row table.table.table-striped diff --git a/app/views/platforms/tokens/new.html.slim b/app/views/platforms/tokens/new.html.slim index c71102238..83b1459cb 100644 --- a/app/views/platforms/tokens/new.html.slim +++ b/app/views/platforms/tokens/new.html.slim @@ -7,9 +7,6 @@ = t('layout.tokens.new') = simple_form_for @token, url: platform_tokens_path(@platform) do |f| - fieldset - = f.input :description, as: :text + = f.input :description, as: :text - .button_block - button type="submit" class="btn btn-default" data-disable-with=t('layout.saving') - = t('layout.save') + = f.button :submit, t('layout.save') \ No newline at end of file diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 1a92369ed..74ce91763 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -22,9 +22,9 @@ SimpleForm.setup do |config| b.use :placeholder ## Optional extensions - # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup` + # They are disabled unless you pass `f.input EXTENSION_NAME => true` # to the input. If so, they will retrieve the values from the model - # if any exists. If you want to enable the lookup for any of those + # if any exists. If you want to enable any of those # extensions by default, you can change `b.optional` to `b.use`. # Calculates maxlength from length validations for string inputs @@ -43,18 +43,22 @@ SimpleForm.setup do |config| b.use :label_input b.use :hint, wrap_with: { tag: :span, class: :hint } b.use :error, wrap_with: { tag: :span, class: :error } + + ## full_messages_for + # If you want to display the full error message for the attribute, you can + # use the component :full_error, like: + # + # b.use :full_error, wrap_with: { tag: :span, class: :error } end # The default wrapper to be used by the FormBuilder. - # config.default_wrapper = :default - config.default_wrapper = :bootstrap + config.default_wrapper = :default # Define the way to render check boxes / radio buttons with labels. # Defaults to :nested for bootstrap config. # inline: input + label # nested: label > input - # config.boolean_style = :nested - config.boolean_style = :inline + config.boolean_style = :nested # Default class for buttons config.button_class = 'btn' @@ -68,7 +72,7 @@ SimpleForm.setup do |config| config.error_notification_tag = :div # CSS class to add for error notification helper. - config.error_notification_class = 'alert alert-error' + config.error_notification_class = 'error_notification' # ID to add for error notification helper. # config.error_notification_id = nil @@ -94,14 +98,13 @@ SimpleForm.setup do |config| # config.item_wrapper_class = nil # How the label text should be generated altogether with the required text. - # config.label_text = lambda { |label, required| "#{required} #{label}" } + # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" } # You can define the class to use on all labels. Default is nil. - config.label_class = 'col-sm-2 control-label' + # config.label_class = nil # You can define the class to use on all forms. Default is simple_form. # config.form_class = :simple_form - config.form_class = 'well form-horizontal' # You can define which elements should obtain additional classes # config.generate_additional_classes_for = [:wrapper, :label, :input] @@ -128,6 +131,10 @@ SimpleForm.setup do |config| # type as key and the wrapper that will be used for all inputs with specified type. # config.wrapper_mappings = { string: :prepend } + # Namespaces where SimpleForm should look for custom input classes that + # override default inputs. + # config.custom_inputs_namespaces << "CustomInputs" + # Default priority for time_zone inputs. # config.time_zone_priority = nil @@ -145,5 +152,24 @@ SimpleForm.setup do |config| # Default class for inputs # config.input_class = nil - config.input_class = 'form-control' + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = 'checkbox' + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true + + # Defines which i18n scope will be used in Simple Form. + # config.i18n_scope = 'simple_form' +end + +# See: http://www.railsonmaui.com/blog/2014/02/23/simple-form-and-disable-processing-by-default +SimpleForm::FormBuilder.class_eval do + def submit_with_override(field, options = {}) + data_disable_with = { disable_with: I18n.t('layout.processing') } + options[:data] = data_disable_with.merge(options[:data] || {}) + submit_without_override(field, options) + end + alias_method_chain :submit, :override end diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index b88cee0ef..6a28d6860 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -1,45 +1,129 @@ # Use this setup block to configure all options available in SimpleForm. SimpleForm.setup do |config| - config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'error' do |b| + config.error_notification_class = 'alert alert-danger' + config.button_class = 'btn btn-primary' + config.boolean_label_class = nil + + config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.use :label - b.wrapper tag: 'div', class: 'col-sm-10' do |ba| - ba.use :input - ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + b.optional :maxlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'control-label' + + b.use :input, class: 'form-control' + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :readonly + b.use :label, class: 'control-label' + + b.use :input + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + + b.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input + end + + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + b.use :label_input + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input, class: 'form-control' + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :prepend, tag: 'div', class: "form-group", error_class: 'error' do |b| + config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.use :label - b.wrapper tag: 'div', class: 'col-sm-10' do |input| - input.wrapper tag: 'div', class: 'input-prepend' do |prepend| - prepend.use :input - end - input.use :hint, wrap_with: { tag: 'span', class: 'help-block' } - input.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + b.optional :maxlength + b.optional :readonly + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :append, tag: 'div', class: "form-group", error_class: 'error' do |b| + config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 - b.use :placeholder - b.use :label - b.wrapper tag: 'div', class: 'col-sm-10' do |input| - input.wrapper tag: 'div', class: 'input-append' do |append| - append.use :input + b.optional :readonly + + b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr| + wr.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input, class: 'col-sm-9' end - input.use :hint, wrap_with: { tag: 'span', class: 'help-block' } - input.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + + wr.use :error, wrap_with: { tag: 'span', class: 'help-block' } + wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - # Wrappers for forms and inputs using the Twitter Bootstrap toolkit. - # Check the Bootstrap docs (http://twitter.github.com/bootstrap) + config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + + b.use :label, class: 'col-sm-3 control-label' + + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| + ba.use :input + ba.use :error, wrap_with: { tag: 'span', class: 'help-block' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + end + + config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :maxlength + b.optional :pattern + b.optional :min_max + b.optional :readonly + b.use :label, class: 'sr-only' + + b.use :input, class: 'form-control' + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end + + # Wrappers for forms and inputs using the Bootstrap toolkit. + # Check the Bootstrap docs (http://getbootstrap.com) # to learn about the different styles for forms and inputs, # buttons and other elements. - config.default_wrapper = :bootstrap + config.default_wrapper = :vertical_form end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 0df11fe0f..237438334 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -10,7 +10,7 @@ en: # html: '*' error_notification: default_message: "Please review the problems below:" - # Labels and hints examples + # Examples # labels: # defaults: # password: 'Password' @@ -23,4 +23,9 @@ en: # defaults: # username: 'User name to sign in.' # password: 'No special characters, please.' - + # include_blanks: + # defaults: + # age: 'Rather not say' + # prompts: + # defaults: + # age: 'Select your age'