Skip to content

Commit aa70fea

Browse files
Asespinelormsbee
authored andcommitted
feat: hide the survey report banner for a month after clicking the dismiss button (#34914)
This hides the survey report banner from the Django Admin for a particular user for one month after they click on the "dismiss" button. This is done completely on the client side using localStorage, so the same user could see the banner again if they're logging in with a different browser.
1 parent 6ab0b7a commit aa70fea

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

openedx/features/survey_report/static/survey_report/js/admin_banner.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
$(document).ready(function(){
2+
// Function to get user ID
3+
function getUserId() {
4+
return $('#userIdSurvey').val();
5+
}
6+
7+
// Function to get current time in milliseconds
8+
function getCurrentTime() {
9+
return new Date().getTime();
10+
}
11+
12+
// Function to set dismissal time and expiration time in local storage
13+
function setDismissalAndExpirationTime(userId, dismissalTime) {
14+
let expirationTime = dismissalTime + (30 * 24 * 60 * 60 * 1000); // 30 days
15+
localStorage.setItem('bannerDismissalTime_' + userId, dismissalTime);
16+
localStorage.setItem('bannerExpirationTime_' + userId, expirationTime);
17+
}
18+
19+
// Function to check if banner should be shown or hidden
20+
function checkBannerVisibility() {
21+
let userId = getUserId();
22+
let bannerDismissalTime = localStorage.getItem('bannerDismissalTime_' + userId);
23+
let bannerExpirationTime = localStorage.getItem('bannerExpirationTime_' + userId);
24+
let currentTime = getCurrentTime();
25+
26+
if (bannerDismissalTime && bannerExpirationTime && currentTime > bannerExpirationTime) {
27+
// Banner was dismissed and it's not within the expiration period, so show it
28+
$('#originalContent').show();
29+
} else if (bannerDismissalTime && bannerExpirationTime && currentTime < bannerExpirationTime) {
30+
// Banner was dismissed and it's within the expiration period, so hide it
31+
$('#originalContent').hide();
32+
} else {
33+
// Banner has not been dismissed ever so we need to show it.
34+
$('#originalContent').show();
35+
}
36+
}
37+
38+
// Click event for dismiss button
239
$('#dismissButton').click(function() {
340
$('#originalContent').slideUp('slow', function() {
4-
// If you want to do something after the slide-up, do it here.
5-
// For example, you can hide the entire div:
6-
// $(this).hide();
41+
let userId = getUserId();
42+
let dismissalTime = getCurrentTime();
43+
setDismissalAndExpirationTime(userId, dismissalTime);
744
});
845
});
46+
47+
// Check banner visibility on page load
48+
checkBannerVisibility();
949
// When the form is submitted
1050
$("#survey_report_form").submit(function(event){
1151
event.preventDefault(); // Prevent the form from submitting traditionally

openedx/features/survey_report/templates/survey_report/admin_banner.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% block survey_report_banner %}
22
{% load static %}
33
{% if show_survey_report_banner %}
4-
<div id="originalContent" style="border: 3px solid #06405d; margin-bottom: 50px; rgb(0 0 0 / 18%) 0px 3px 5px;">
4+
<div id="originalContent" style="border: 3px solid #06405d; margin-bottom: 50px; rgb(0 0 0 / 18%) 0px 3px 5px; display: none;">
55
<div style="background-color: #06405d;padding: 17px 37px;">
66
<h1 style="margin: 0; color: #FFFF; font-weight: 600;">Join the Open edX Data Sharing Initiative and shape the future of learning</h1>
77
</div>
@@ -15,6 +15,7 @@ <h1 style="margin: 0; color: #FFFF; font-weight: 600;">Join the Open edX Data Sh
1515
<button id="dismissButton" type="button" style="background-color:var(--close-button-bg); color: var(--button-fg); border: none; border-radius: 4px; padding: 10px 20px; margin-right: 10px; cursor: pointer;">Dismiss</button>
1616
<form id='survey_report_form' method="POST" action="/survey_report/generate_report" style="margin: 0; padding: 0;">
1717
{% csrf_token %}
18+
<input type="hidden" id="userIdSurvey" value="{{ user.id }}">
1819
<button type="submit" style="background-color: #377D4D; color: var(--button-fg); border: none; border-radius: 4px; padding: 10px 20px; cursor: pointer;">Send Report</button>
1920
</form>
2021
</div>

0 commit comments

Comments
 (0)