Skip to content

Commit

Permalink
working cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
jendiamond committed Jul 6, 2023
1 parent 76a03a1 commit 8c3bbd2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 90 deletions.
23 changes: 13 additions & 10 deletions app/assets/stylesheets/base/layout/body/_body.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,33 @@
}
}

/* --------------- */

// Terms of User Modal
// terms_of_use_90day
// Terms of Use Modal - appears every 90 days

/* The Modal (background) */
.modal {
position: fixed; /* Stay in place */
top: 0;
left: 0;
position: absolute; /* Stay in place */
top: 15%;
left: 25%;
display: none; /* Hidden by default */
align-self: center;
overflow: auto; /* Enable scroll if needed */
max-width: 500px;
max-width: 600px;
height: 100%; /* Full height */
z-index: 5; /* Sit on top */

@media (max-width: 767px) {
top: 0;
left: 0;
}
}

/* Modal Content/Box */
.modal-content {
margin: 4% auto;
padding: 25%;
padding: 30%;
width: 92%;
background-color: #fff;
border: 1.5px solid #f7f2ea;
border: 1px solid #87331a;
}

.modal__terms-of-use {
Expand All @@ -96,6 +98,7 @@
align-self: flex-start;
color: #87331a;
text-transform: uppercase;

@media (max-width: 800px) {
font-size: $text-20;
}
Expand Down
19 changes: 15 additions & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
before_action :display_banner?, :sinai_authn_check, :add_legacy_views, :cors_preflight_check, :set_default_sort, :set_term_of_use_cookie, :terms_of_use_modal_check
before_action :display_banner?, :sinai_authn_check, :add_legacy_views, :cors_preflight_check, :set_default_sort, :display_term_of_use?
after_action :cors_set_access_control_headers

def add_legacy_views
Expand Down Expand Up @@ -95,16 +95,27 @@ def set_auth_cookies
}
end

# TERMS OF USE MODAL
def term_of_use_cookie?
cookies[:set_modal]
end

def set_term_of_use_cookie
cookies[:set_modal] = {
value: 'Set this Modal',
expires: Time.zone.now + 1.minutes
expires: Time.zone.now + 90.days
}
end

def terms_of_use_modal_check
return true if cookies[:sinai_authenticated_3day] = 'true'
def display_term_of_use?
if term_of_use_cookie?
@term_of_use_modal_option = "none"
else
@term_of_use_modal_option = "block"
set_term_of_use_cookie
end
end
# End Terms of Use Modal

def create_encrypted_string
cipher.encrypt
Expand Down
85 changes: 21 additions & 64 deletions app/views/layouts/blacklight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,59 +43,33 @@
<% end %>

<div class="site-container" <%= schema_org_markup %>>
<!-- HEADER -->
<%= render partial: 'shared/header/header_navbar' %>
<%= render 'catalog/banners/homepage_banner' %>

<!-- TERMS OF USE MODAL -->
<% if cookies[:sinai_authenticated_3day] %>
<% if cookies[:set_modal] %>

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>
CURRENT USER: <%= current_user %> |
SIGNED IN: <%= user_signed_in? %> |
USER SESSION: <%= user_session %> |
<% if cookies[:sinai_authenticated_3day] %>
<%= cookies[:sinai_authenticated_3day] %>
<% end %>
<% if cookies[:set_modal] %>
Set Modal: <%= cookies[:set_modal] %>
| <%= :terms_of_use_modal? %>
<% end %>
<% if :terms_of_use_modal_check %>
:terms_of_use_modal_check is true
<% end %>

<!-- The Modal -->
<div id="termsOfUseModal" class="modal">
<!-- Modal content -->
<div class="modal-content">

<!-- HEADER -->
<div class='modal__logo-title'>Sinai Manuscripts Digital Library
</div>
<!-- End of Header -->
<% if @term_of_use_modal_option == "block" %>
<div id="termsOfUseModal" style="display: block" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class='modal__logo-title'>Sinai Manuscripts Digital Library</div>

<div class='modal__terms-of-use'>
<p>Manuscript images from the Sinai Manuscripts Digital Library should not be used without the express consent of St. Catherine's Monastery of the Sinai. This includes use in published works and social media.</p>
<br>
<p>For more information, see the Terms of Use.</p>
<div class='modal__terms-of-use'>
<p>Manuscript images from the Sinai Manuscripts Digital Library should not be used without the express consent of St. Catherine's Monastery of the Sinai. This includes use in published works and social media.</p>
<br>

<p>Click "I AGREE" to continue using the site.</p>
</div>
<p>For more information, see the Terms of Use.</p>

<button class="modal-button"><span class="close">I AGREE</span></button>
<p>Click "I AGREE" to continue using the site.</p>
</div>

<button class="modal-button" onclick="closeModal()"><span class="close">I AGREE</span></button>
</div>
</div>
</div>
<!-- End of Modal -->
<% end %>
<% end %>
<!-- End of Modal -->

<!-- BODY -->
<% if controller.controller_name == 'catalog' && controller.action_name == 'show' %>

<main class="main-content-container container-constrained container-constrained__item-page--sinai">
Expand All @@ -110,36 +84,19 @@
</main>
<% end %>

<!-- FOOTER -->
<%= render partial: 'shared/footer/footer' %>
<%= render partial: 'shared/modal' %>
</div>
</body>
</html>

<script>
// Get the modal
var modal = document.getElementById("termsOfUseModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// Get the modal
var modal = document.getElementById("termsOfUseModal");

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
// When the user clicks on "I Agree", close the modal
function closeModal() {
modal.style.display = "none";
}
}
</script>
11 changes: 0 additions & 11 deletions app/views/shared/header/_header_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@

<div class='site-navbar__link-block--sinai'>
<ul class='nav'>
<li class='nav-item site-navbar__item--sinai'>
XX<%= cookies[:sinai_authenticated_3day] %>
<% if cookies[:sinai_authenticated_3day] %>
SET A NEW COOKIE for 30 DAYS
<% end %>
<% if user_signed_in? %>
<%= @user.first_name.capitalize %>
Current User: <%= current_user %>
<%= user_signed_in? %>
<% end %>
</li>
<li class='nav-item site-navbar__item--sinai'><%= link_to "Search#{image_tag('sinai-logos/search-icon-bold.svg', class: 'site-header__search-icon--sinai', alt: 'Search icon')}".html_safe, '/catalog?utf8=%E2%9C%93&q=&search_field=all_fields' %></li>
<li class='nav-item site-navbar__item--sinai'><%= link_to 'About', about_path %></li>
<% if !cookies[:sinai_authenticated_3day] %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
concerns :range_searchable
end

devise_for :users, skip: :all
devise_for :users
concern :exportable, Blacklight::Routes::Exportable.new

resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog' do
Expand Down

0 comments on commit 8c3bbd2

Please sign in to comment.