From b448f759c65907ea51c2844f07a797f54f87ebc8 Mon Sep 17 00:00:00 2001 From: Graeme Porteous Date: Tue, 31 May 2022 12:30:40 +0100 Subject: [PATCH] Add volunteer contact form Requires core changes: https://github.com/mysociety/alaveteli/pull/7063 Fixes: https://github.com/mysociety/whatdotheyknow-theme/issues/1179 --- app/assets/stylesheets/responsive/custom.scss | 8 ++ lib/alavetelitheme.rb | 4 +- lib/controller_patches.rb | 2 + lib/mailer_patches.rb | 6 ++ .../contact_mailer/volunteer_message.text.erb | 24 +++++ .../help/_contact_volunteer_form.html.erb | 91 ++++++++++++++++++ lib/views/help/contact.html.erb | 29 ++++++ lib/volunteer_contact_form.rb | 96 +++++++++++++++++++ 8 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 lib/mailer_patches.rb create mode 100644 lib/views/contact_mailer/volunteer_message.text.erb create mode 100644 lib/views/help/_contact_volunteer_form.html.erb create mode 100644 lib/volunteer_contact_form.rb diff --git a/app/assets/stylesheets/responsive/custom.scss b/app/assets/stylesheets/responsive/custom.scss index 9e436340..d0b659fb 100644 --- a/app/assets/stylesheets/responsive/custom.scss +++ b/app/assets/stylesheets/responsive/custom.scss @@ -1454,6 +1454,14 @@ dd { label { margin-bottom: 0.3em; + + input[type="radio"], input[type="checkbox"] { + margin: 0 3px 0 -20px + } + + &.form_inline { + padding-left: 20px; + } } input[type="text"], diff --git a/lib/alavetelitheme.rb b/lib/alavetelitheme.rb index 1e6ad949..6da7a303 100644 --- a/lib/alavetelitheme.rb +++ b/lib/alavetelitheme.rb @@ -61,8 +61,10 @@ def prepend_theme_assets 'controller_patches.rb', 'model_patches.rb', 'helper_patches.rb', + 'mailer_patches.rb', 'analytics_event.rb', - 'public_body_questions.rb'] + 'public_body_questions.rb', + 'volunteer_contact_form.rb'] require File.expand_path "../#{patch}", __FILE__ end diff --git a/lib/controller_patches.rb b/lib/controller_patches.rb index 4484c105..7c89a3e6 100644 --- a/lib/controller_patches.rb +++ b/lib/controller_patches.rb @@ -1,6 +1,8 @@ # Please arrange overridden classes alphabetically. Rails.configuration.to_prepare do HelpController.class_eval do + prepend VolunteerContactForm::ControllerMethods + before_action :set_history, except: :index def principles; end diff --git a/lib/mailer_patches.rb b/lib/mailer_patches.rb new file mode 100644 index 00000000..c1772cb7 --- /dev/null +++ b/lib/mailer_patches.rb @@ -0,0 +1,6 @@ +# Please arrange overridden classes alphabetically. +Rails.configuration.to_prepare do + ContactMailer.class_eval do + prepend VolunteerContactForm::MailerMethods + end +end diff --git a/lib/views/contact_mailer/volunteer_message.text.erb b/lib/views/contact_mailer/volunteer_message.text.erb new file mode 100644 index 00000000..b85bc493 --- /dev/null +++ b/lib/views/contact_mailer/volunteer_message.text.erb @@ -0,0 +1,24 @@ +Name: <%= @contact.name %> +Email: <%= @contact.email %> +Age: <%= @contact.age %> + +Why: +<%= @contact.why.strip.gsub(/^/, '> ') %> + +Tasks: +<%= @contact.tasks.map { |t| '- ' + t }.join("\n") %> + +Experience: +<%= @contact.experience.strip.gsub(/^/, '> ') %> + +Anything else: +<%= @contact.anything_else.strip.gsub(/^/, '> ') %> + +--------------------------------------------------------------------- +<%= _('Message sent using {{site_name}} volunteer contact form, ', + :site_name => site_name.html_safe) %> +<%= @logged_in_user ? + _("logged in as user {{user_name}}", + :user_name => user_url(@logged_in_user)) : + _("not logged in") %> +--------------------------------------------------------------------- diff --git a/lib/views/help/_contact_volunteer_form.html.erb b/lib/views/help/_contact_volunteer_form.html.erb new file mode 100644 index 00000000..a18b4334 --- /dev/null +++ b/lib/views/help/_contact_volunteer_form.html.erb @@ -0,0 +1,91 @@ +<%= form_for :contact, + url: help_contact_path + '#' + form_id, + html: { class: 'contact-form' } do |f| %> + <% if not @user %> +

+ + <%= f.text_field :name, size: 20, required: true %> + (or <%= link_to "sign in", signin_url(r: request.fullpath + '#' + form_id) %>) +

+ +

+ + <%= f.text_field :email, size: 20, required: true %> +

+ <% end %> + +

+ + + Please introduce yourself and tell us what interests you about FOI. If you are new to FOI and are interested in learning more through volunteering at WhatDoTheyKnow, that’s fine too!

+
+ <%= f.text_area :why, rows: 10 %> +

+ +

+ + <%= f.fields_for :tasks do |t| %> + <% VolunteerContactForm::TASKS.each do |k, v| %> + <%= t.label k, class: 'form_inline' do %> + <%= t.check_box k, {}, v %> + <%= v %> + <% end %> + <% end %> + <% end %> +

+ +

+ + + + There's a wide range of different jobs, hobbies or experiences that could be helpful in volunteering at WhatDoTheyKnow.

+ Let us know of anything you think might be relevant: maybe a link to a website you've contributed to, your social media, or campaigning that you've been involved in.

+ Perhaps you're studying for a course that has a link to transparency or FOI, such as law or media; or you've had a job that involved working with the public. Even if you've never done anything directly linked to FOI, it'd be great to hear about anything that shows you have skills that can be applied to the sort of task you're interested in.

+ Finally, if you've got a CV online, please do include the link.

+
+ + <%= f.text_area :experience, rows: 10 %> +

+ +

+ + + + Is there anything else that you’d like to tell us?

+
+ + <%= f.text_area :anything_else, rows: 10 %> +

+ +

+

+ +

+ <%= f.label :comment, 'Do not fill in this field' %> + <%= f.text_field :comment %> +

+ + <% if @recaptcha_required %> + <%= recaptcha_tags %>
+ <% end %> + +
+ <%= hidden_field_tag(:current_form, form_id) %> + <%= hidden_field_tag(:submitted_contact_form, 1) %> + <%= submit_tag "Send message to WhatDoTheyKnow team", data: { disable_with: "Sending..." } %> +
+<% end %> diff --git a/lib/views/help/contact.html.erb b/lib/views/help/contact.html.erb index 12331b56..3a35b636 100644 --- a/lib/views/help/contact.html.erb +++ b/lib/views/help/contact.html.erb @@ -89,6 +89,35 @@ +

+ +

+ + checked<% end %>> +
+ +
+ +