Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit d491ff1

Browse files
committed
Use custom login/logout events so that individual modules can bind themselves rather than calling everything in bookfuncs.js
1 parent 7f4bee9 commit d491ff1

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

runestone/activecode/js/activecode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ function loadEditor(data, status, whatever) {
10121012
}
10131013

10141014
function disableAcOpt() {
1015+
console.log("setup buttons for logged out");
10151016
$jqTheme('button.ac_opt').each(function (index, value) {
10161017
value.className = value.className + ' disabled';
10171018
$jqTheme(value).attr('onclick', 'return false;');
@@ -1252,3 +1253,4 @@ function injectCodeCoach(div_id) {
12521253
$(document).ready(createEditors);
12531254
$(document).ready(createScratchActivecode);
12541255
$(document).ready(styleUnittestResults);
1256+
$(document).bind("runestone:logout",disableAcOpt);

runestone/common/js/bookfuncs.js

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function gotUser(data, status, whatever) {
8787
if (confirm("Error: " + err.toString() + "Please report this error! Click OK to continue without logging in. Cancel to retry.")) {
8888
caughtErr = true;
8989
mess = "Not logged in";
90-
disableAcOpt();
90+
$(document).trigger("runestone:logout")
9191
$('li.loginout').html('<a href="' + eBookConfig.app + '/default/user/login">Login</a>')
9292
} else {
9393
window.location.href = eBookConfig.app + '/default/user/login?_next=' + window.location.href
@@ -99,16 +99,15 @@ function gotUser(data, status, whatever) {
9999
window.location.href = eBookConfig.app + '/default/user/login?_next=' + window.location.href
100100
} else {
101101
mess = "Not logged in";
102-
disableAcOpt();
102+
$(document).trigger("runestone:logout")
103103
$('li.loginout').html('<a href="' + eBookConfig.app + '/default/user/login">Login</a>')
104104
}
105105
} else {
106106
if (!caughtErr) {
107107
mess = d.email;
108108
eBookConfig.isLoggedIn = true;
109109
eBookConfig.cohortId = d.cohortId;
110-
addNavbarLoginLink(); // will change navbar login link to say 'Log Out'
111-
enableUserHighlights();
110+
$(document).trigger("runestone:login")
112111
timedRefresh();
113112
}
114113
}
@@ -152,43 +151,43 @@ function isLoggedIn() {
152151
return false;
153152
}
154153

155-
function addUserToFooter() {
156-
// test to see if online before doing this.
157-
var x = "user ";
154+
function handleLoginLogout() {
158155
if (shouldLogin()) {
159156
jQuery.get(eBookConfig.ajaxURL + 'getuser', null, gotUser)
160157
} else {
161-
$(".footer").html(x + 'not logged in');
162-
disableAcOpt();
163-
logBookEvent({'event': 'page', 'act': 'view', 'div_id': window.location.pathname})
158+
$(document).trigger("runestone:logout")
164159
}
165160
}
166161

167-
function addNavbarLoginLink() {
168-
if (isLoggedIn()) {
169-
if (eBookConfig.cohortId == null || eBookConfig.cohortId == "") {
170-
$('#joinGroupLink').show();
171-
$('#groupScheduleLink').hide();
172-
$('#newChapterLink').hide();
173-
$('#manageGroupLink').hide();
174-
} else {
175-
$('#joinGroupLink').hide();
176-
$('#groupScheduleLink').show();
177-
$('#newChapterLink').show();
178-
$('#manageGroupLink').show();
179-
}
180-
$('#profilelink').show();
181-
$('#passwordlink').show();
182-
$('#registerlink').hide();
183-
$('li.loginout').html('<a href="' + eBookConfig.app + '/default/user/logout">Log Out</a>')
162+
function setupNavbarLoggedIn() {
163+
if (eBookConfig.cohortId == null || eBookConfig.cohortId == "") {
164+
$('#joinGroupLink').show();
165+
$('#groupScheduleLink').hide();
166+
$('#newChapterLink').hide();
167+
$('#manageGroupLink').hide();
184168
} else {
185-
$('#registerlink').show();
186-
$('#profilelink').hide();
187-
$('#passwordlink').hide();
188-
$('li.loginout').html('<a href="' + eBookConfig.app + '/default/user/login">Login</a>')
169+
$('#joinGroupLink').hide();
170+
$('#groupScheduleLink').show();
171+
$('#newChapterLink').show();
172+
$('#manageGroupLink').show();
189173
}
174+
$('#profilelink').show();
175+
$('#passwordlink').show();
176+
$('#registerlink').hide();
177+
$('li.loginout').html('<a href="' + eBookConfig.app + '/default/user/logout">Log Out</a>')
190178
}
191-
179+
$(document).bind("runestone:login", setupNavbarLoggedIn);
180+
181+
function setupNavbarLoggedOut() {
182+
console.log("setup navbar for logged out");
183+
$('#registerlink').show();
184+
$('#profilelink').hide();
185+
$('#passwordlink').hide();
186+
$('li.loginout').html('<a href="' + eBookConfig.app + '/default/user/login">Login</a>')
187+
$(".footer").html('user not logged in');
188+
logBookEvent({'event': 'page', 'act': 'view', 'div_id': window.location.pathname})
189+
}
190+
$(document).bind("runestone:logout",setupNavbarLoggedOut);
192191

193192
function getNumUsers() {
194193
if (eBookConfig.useRunestoneServices) {
@@ -256,8 +255,7 @@ function addDelay(directive, action, delay) {
256255

257256

258257
// initialize stuff
259-
$(document).ready(addUserToFooter);
260-
$(document).ready(addNavbarLoginLink);
258+
$(document).ready(handleLoginLogout);
261259
$(document).ready(getNumUsers);
262260
$(document).ready(getOnlineUsers);
263261

runestone/common/js/user-highlights.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ function enableUserHighlights() {
299299
// in-progress or completed sections.
300300
decorateTableOfContents(); //todo: use document.ready to call
301301
}
302+
// call enable user highlights after login
303+
$(document).bind("runestone:login",enableUserHighlights);
302304

303305
function findHighlightClass(classList) {
304306
var className;

0 commit comments

Comments
 (0)