Added new cookies banner (with link to cookie policy page and the accept cookies button)

This commit is contained in:
luisramos0
2018-06-28 01:52:09 +01:00
committed by Maikel Linke
parent 08c5d8f3ab
commit 92f9cbd00a
11 changed files with 154 additions and 3 deletions

View File

@@ -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}}

View File

@@ -0,0 +1,5 @@
Darkswarm.controller "CookiesBannerCtrl", ($scope, CookiesBannerService, $http, $window)->
$scope.acceptCookies = ->
$http.post('/api/cookies/consent')
CookiesBannerService.close()

View File

@@ -0,0 +1,5 @@
Darkswarm.directive 'cookiesBanner', (CookiesBannerService) ->
restrict: 'A'
link: (scope, elm, attr)->
CookiesBannerService.setActive()
CookiesBannerService.open()

View File

@@ -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

View File

@@ -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() )

View 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;
}
}

View 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

View 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

View File

@@ -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

View File

@@ -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 wont 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 dont 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

View File

@@ -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