diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index e862f876..4f598c4b 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -71,6 +71,10 @@ main img {
margin-bottom: govuk-spacing(8);
}
+ #flash .govuk-notification-banner {
+ margin-bottom: govuk-spacing(4);
+ }
+
@include govuk-media-query($until: tablet) {
.govuk-grid-column-one-half>p,
diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb
index 71f3c99d..818dd506 100644
--- a/app/controllers/settings_controller.rb
+++ b/app/controllers/settings_controller.rb
@@ -1,19 +1,57 @@
class SettingsController < ApplicationController
+ def show
+ if template_valid?
+ track('static_page')
+ render template
+ else
+ render 'errors/not_found'
+ end
+ end
+
def create
set_cookie_pref
- redirect_to params[:return_url]
- end
-private
+ if settings_params[:settings_updated].present?
+ flash[:notice] = t(:flash, scope: 'cookie_policy')
+ end
- def track_analytics
- params.fetch(:track_analytics, 'No')
+ redirect_to request_path
end
+private
+
def set_cookie_pref
- cookies[:track_analytics] = { value: track_analytics, expires: 6.months.from_now }
+ cookies[:track_analytics] = {
+ value: settings_params[:track_analytics],
+ expires: 6.months.from_now,
+ }
+
if params.fetch(:notify_if_successful, false)
flash[:notice] = t(:preferences_saved_html, return_url: helpers.root_path, scope: :settings)
end
end
+
+ def request_path
+ if params[:request_path]
+ params[:request_path]
+ else
+ params[:return_url]
+ end
+ end
+
+ def settings_params
+ params.permit(:request_path, :track_analytics, :settings_updated)
+ end
+
+ def track_analytics
+ params.fetch(:track_analytics, 'No')
+ end
+
+ def template
+ page_params[:id].underscore
+ end
+
+ def page_params
+ params.permit(:id)
+ end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0defd9c6..0d6cbf4d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -22,4 +22,8 @@ def menu
def footer_menu
@footer_menu ||= Page.footer.pages
end
+
+ def track_analytics?
+ cookies[:track_analytics] == 'Yes'
+ end
end
diff --git a/app/views/layouts/_flash.html.slim b/app/views/layouts/_flash.html.slim
new file mode 100644
index 00000000..155d6103
--- /dev/null
+++ b/app/views/layouts/_flash.html.slim
@@ -0,0 +1,5 @@
+- if flash.any?
+ #flash.govuk-grid-row
+ .govuk-grid-column-full
+ - flash.each do |variant, message|
+ = govuk_notification_banner title_text: t("banners.#{variant}"), text: m(message), success: %w[notice].include?(variant), classes: "govuk-notification-banner--#{variant}"
diff --git a/app/views/pages/index.html.slim b/app/views/pages/index.html.slim
index 218669fd..a0a9146e 100644
--- a/app/views/pages/index.html.slim
+++ b/app/views/pages/index.html.slim
@@ -8,8 +8,13 @@
.govuk-grid-row class=('govuk-!-margin-bottom-6' unless index == (page.pages.count / 3.0 - 1).ceil)
= render partial: 'shared/card', collection: row
+= render 'layouts/flash'
+
= m(page.body)
+if page.slug == 'cookie-policy'
+ = render 'settings/cookie_policy'
+
= render 'shared/ctas'
= render 'shared/other_resources'
diff --git a/app/views/settings/_cookie_policy.html.slim b/app/views/settings/_cookie_policy.html.slim
new file mode 100644
index 00000000..dc30c6ba
--- /dev/null
+++ b/app/views/settings/_cookie_policy.html.slim
@@ -0,0 +1,10 @@
+.govuk-grid-row class='govuk-!-margin-bottom-7'
+ .govuk-grid-column-two-thirds-from-desktop
+ = form_with url: settings_path, method: :post, local: true do |f|
+ = f.hidden_field :request_path, value: request.path
+ = f.hidden_field :settings_updated, value: 'Yes'
+ = f.govuk_radio_buttons_fieldset(:checked, legend: { size: 'm', text: t('cookie_policy.legend') }, inline: true ) do
+ = f.govuk_radio_button :track_analytics, 'Yes', label: { text: 'Yes' }, checked: track_analytics?
+ = f.govuk_radio_button :track_analytics, 'No', label: { text: 'No' }, checked: !track_analytics?
+
+ = f.govuk_submit 'Save cookie settings'
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0c3f746c..9df86828 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -132,6 +132,10 @@ en:
blank: First name must not be blank
last_name:
blank: Last name must not be blank
+ cookie_policy:
+ title: Cookie policy
+ legend: Do you want to accept analytics cookies?
+ flash: Your cookie settings were savedGo back to Help for early years providers
settings:
cookie-policy: Cookies
preferences_saved_html: Your cookie settings were savedGo back to Help for early years providers