From: Andy Allan Date: Wed, 12 Aug 2020 14:55:34 +0000 (+0200) Subject: Refactor reports form to use bootstrap X-Git-Tag: live~2805^2~3 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/8df30107667e28bfb7f99a13c679c174645b81bf Refactor reports form to use bootstrap --- diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 70c9adac6..f9cc99621 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -1,5 +1,14 @@ +require "ostruct" + module ReportsHelper def report_link(name, reportable) link_to name, new_report_url(:reportable_id => reportable.id, :reportable_type => reportable.class.name) end + + # Convert a list of strings into objects with methods that the collection_radio_buttons helper expects + def report_categories(reportable) + Report.categories_for(reportable).map do |c| + OpenStruct.new(:id => c, :label => t(".categories.#{reportable.class.name.underscore}.#{c}_label")) + end + end end diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index a29104ae7..6c12c14e3 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -11,32 +11,13 @@ -<%= form_for(@report) do |f| %> - <%= f.error_messages %> -
- <%= f.fields_for @report.issue do |issue_form| %> - <%= issue_form.hidden_field :reportable_id %> - <%= issue_form.hidden_field :reportable_type %> - <% end %> +<%= bootstrap_form_for(@report) do |f| %> + <%= f.fields_for @report.issue do |issue_form| %> + <%= issue_form.hidden_field :reportable_id %> + <%= issue_form.hidden_field :reportable_type %> + <% end %> -
-

<%= t(".select") %>

-
    - <% Report.categories_for(@report.issue.reportable).each do |c| %> -
  • - <%= radio_button :report, :category, c, :required => true %> - <%= label_tag "report_category_#{c}", t(".categories.#{@report.issue.reportable.class.name.underscore}.#{c}_label") %> -
  • - <% end %> -
-
- -
- <%= text_area :report, :details, :cols => 20, :rows => 5, :placeholder => t(".details") %> -
- -
- <%= f.submit %> -
-
+ <%= f.collection_radio_buttons :category, report_categories(@report.issue.reportable), :id, :label %> + <%= f.text_area :details, :rows => 5, :label_as_placeholder => true %> + <%= f.primary %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 185129e83..fe07bab92 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -104,6 +104,9 @@ en: title: "Subject" body: "Body" recipient: "Recipient" + report: + category: Select a reason for your report + details: Please provide some more details about the problem (required). user: email: "Email" active: "Active" @@ -1118,8 +1121,6 @@ en: new: title_html: "Report %{link}" missing_params: "Cannot create a new report" - details: Please provide some more details about the problem (required). - select: "Select a reason for your report:" disclaimer: intro: "Before sending your report to the site moderators, please ensure that:" not_just_mistake: You are certain that the problem is not just a mistake