mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Added new cookies banner (with link to cookie policy page and the accept cookies button)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
.row
|
||||
.large-9.columns
|
||||
%p
|
||||
{{ 'legal.cookies_banner.cookies_usage' | t}}
|
||||
%p
|
||||
{{ 'legal.cookies_banner.cookies_desc' | t}}
|
||||
%p
|
||||
{{ 'legal.cookies_banner.cookies_policy_link_desc' | t}}
|
||||
-#
|
||||
%a{ 'cookies-policy-modal'=> true}
|
||||
{{ 'legal.cookies_banner.cookies_policy_link' | t}}
|
||||
|
||||
.large-3.columns
|
||||
%button{ng: { controller:"CookiesBannerCtrl", click: "acceptCookies()" }}
|
||||
{{ 'legal.cookies_banner.cookies_accept_button' | t}}
|
||||
@@ -0,0 +1,5 @@
|
||||
Darkswarm.controller "CookiesBannerCtrl", ($scope, CookiesBannerService, $http, $window)->
|
||||
|
||||
$scope.acceptCookies = ->
|
||||
$http.post('/api/cookies/consent')
|
||||
CookiesBannerService.close()
|
||||
@@ -0,0 +1,5 @@
|
||||
Darkswarm.directive 'cookiesBanner', (CookiesBannerService) ->
|
||||
restrict: 'A'
|
||||
link: (scope, elm, attr)->
|
||||
CookiesBannerService.setActive()
|
||||
CookiesBannerService.open()
|
||||
@@ -0,0 +1,20 @@
|
||||
Darkswarm.factory "CookiesBannerService", (Navigation, $modal, $location, Redirections, Loading)->
|
||||
|
||||
new class CookiesBannerService
|
||||
modalMessage: null
|
||||
isActive: false
|
||||
|
||||
open: (path, template = 'darkswarm/cookies_banner/cookies_banner.html') =>
|
||||
return unless @isActive
|
||||
@modalInstance = $modal.open
|
||||
templateUrl: template
|
||||
windowClass: "cookies-banner full"
|
||||
backdrop: 'static'
|
||||
keyboard: false
|
||||
|
||||
close: =>
|
||||
return unless @isActive
|
||||
@modalInstance.close()
|
||||
|
||||
setActive: =>
|
||||
@isActive = true
|
||||
@@ -1,4 +1,4 @@
|
||||
Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location)->
|
||||
Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location, CookiesBannerService)->
|
||||
|
||||
new class CookiesPolicyModalService
|
||||
defaultPath: "/policies/cookies"
|
||||
@@ -12,5 +12,19 @@ Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location)->
|
||||
@modalInstance = $modal.open
|
||||
templateUrl: template
|
||||
windowClass: "cookies-policy-modal medium"
|
||||
|
||||
@closeCookiesBanner()
|
||||
@onCloseReOpenCookiesBanner()
|
||||
|
||||
selectedPath = path || @defaultPath
|
||||
Navigation.navigate selectedPath
|
||||
|
||||
closeCookiesBanner: =>
|
||||
setTimeout ->
|
||||
CookiesBannerService.close()
|
||||
, 200
|
||||
|
||||
onCloseReOpenCookiesBanner: =>
|
||||
@modalInstance.result.then(
|
||||
-> CookiesBannerService.open(),
|
||||
-> CookiesBannerService.open() )
|
||||
|
||||
28
app/assets/stylesheets/darkswarm/cookies_banner.css.scss
Normal file
28
app/assets/stylesheets/darkswarm/cookies_banner.css.scss
Normal file
@@ -0,0 +1,28 @@
|
||||
.cookies-banner {
|
||||
background: #3b3b3b;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
z-index: 100000;
|
||||
top: 20vh !important;
|
||||
|
||||
@media only screen and (min-width: 640px) {
|
||||
top: 20vh !important;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 800px) and (min-height: 400px) {
|
||||
top: 40vh !important;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 1024px) and (min-height: 500px) {
|
||||
top: 60vh !important;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
p {
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
26
app/controllers/api/cookies_consent_controller.rb
Normal file
26
app/controllers/api/cookies_consent_controller.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
module Api
|
||||
class CookiesConsentController < BaseController
|
||||
include ActionController::Cookies
|
||||
respond_to :json
|
||||
|
||||
def show
|
||||
render json: { cookies_consent: cookies_consent.exists? }
|
||||
end
|
||||
|
||||
def create
|
||||
cookies_consent.set
|
||||
show
|
||||
end
|
||||
|
||||
def destroy
|
||||
cookies_consent.destroy
|
||||
show
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cookies_consent
|
||||
@cookies_consent ||= CookiesConsent.new(cookies, request.host)
|
||||
end
|
||||
end
|
||||
end
|
||||
28
app/services/cookies_consent.rb
Normal file
28
app/services/cookies_consent.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class CookiesConsent
|
||||
COOKIE_NAME = 'cookies_consent'.freeze
|
||||
|
||||
def initialize(cookies, domain)
|
||||
@cookies = cookies
|
||||
@domain = domain
|
||||
end
|
||||
|
||||
def exists?
|
||||
cookies.key?(COOKIE_NAME)
|
||||
end
|
||||
|
||||
def destroy
|
||||
cookies.delete(COOKIE_NAME, domain: domain)
|
||||
end
|
||||
|
||||
def set
|
||||
cookies[COOKIE_NAME] = {
|
||||
value: COOKIE_NAME,
|
||||
expires: 1.year.from_now,
|
||||
domain: domain
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :cookies, :domain
|
||||
end
|
||||
@@ -143,7 +143,7 @@
|
||||
%div
|
||||
= t :footer_legal_data_text
|
||||
= t :footer_legal_data_call
|
||||
%a{'cookies-policy-modal'=> true}
|
||||
%a{'cookies-policy-modal'=> true, 'cookies-banner'=> !CookiesConsent.new(cookies, request.host).exists? }
|
||||
= t :footer_legal_data_cookies_policy
|
||||
|
||||
.medium-2.columns.text-center
|
||||
|
||||
@@ -1291,6 +1291,13 @@ en:
|
||||
disabling_cookies_ie_link: "https://support.microsoft.com/en-us/help/17442/windows-internet-explorer-delete-manage-cookies"
|
||||
disabling_cookies_safari_link: "https://www.apple.com/legal/privacy/en-ww/cookies/"
|
||||
disabling_cookies_note: "But be aware that if you delete or modify the essential cookies used by Open Food Network, the website won’t work, you will not be able to add anything to your cart neither to checkout for instance."
|
||||
cookies_banner:
|
||||
cookies_usage: "This site uses cookies in order to make your navigation frictionless and secure, and to help us understand how you use it in order to improve the features we offer."
|
||||
cookies_definition: "Cookies are very small text files that are stored on your computer when you visit some websites."
|
||||
cookies_desc: "We use only the cookies that are necessary for delivering you the service of selling/buying food online. We don’t sell any of your data. We use cookies mainly to remember who you are if you ‘log in’ to the service, or to be able to remember the items you put in your cart even if you are not logged in. If you keep navigating on the website without clicking on “Accept cookies”, we assume you are giving us consent to store the cookies that are essential for the functioning of the website."
|
||||
cookies_policy_link_desc: "If you want to learn more, check our"
|
||||
cookies_policy_link: "cookies policy"
|
||||
cookies_accept_button: "Accept Cookies"
|
||||
|
||||
home_shop: Shop Now
|
||||
|
||||
|
||||
@@ -95,6 +95,10 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get :job_queue
|
||||
end
|
||||
|
||||
scope '/cookies' do
|
||||
resource :consent, only: [:show, :create, :destroy], :controller => "cookies_consent"
|
||||
end
|
||||
|
||||
resources :customers, only: [:index, :update]
|
||||
|
||||
post '/product_images/:product_id', to: 'product_images#update_product_image'
|
||||
@@ -110,5 +114,4 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user