Skip to content

Commit 7973fcc

Browse files
committed
Make the "Include OPL" and "Include Contrib" check states in the library browser persistent.
The status of the checks is saved to local storage and updated when the page loads. So whatever state they had the last time the page was open is restored. Note that the settings are saved per user id and course. So you can set the checks differently for each course. This was (essentially) asked for in issue #2857.
1 parent 0f46cbc commit 7973fcc

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

htdocs/js/SetMaker/setmaker.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@
7979

8080
const countLine = document.getElementById('library_count_line');
8181

82+
const settingStoreID = `WW.${document.getElementsByName('hidden_course_id')[0]?.value ?? 'unknownCourse'}.${
83+
document.getElementsByName('user')[0]?.value ?? 'unknownUser'
84+
}.setmaker`;
85+
const includeOPLInitialStatus = includeOPL?.checked;
86+
const includeContribInitialStatus = includeContrib?.checked;
87+
if (includeOPL)
88+
includeOPL.checked = localStorage.getItem(`${settingStoreID}.includeOPLChecked`) !== 'false' ? true : false;
89+
if (includeContrib)
90+
includeContrib.checked =
91+
localStorage.getItem(`${settingStoreID}.includeContribChecked`) !== 'false' ? true : false;
92+
8293
const lib_update = async (who, what) => {
8394
const child = { subject: 'chapter', chapter: 'section', section: 'count' };
8495

@@ -200,11 +211,22 @@
200211
libraryChapter?.addEventListener('change', () => lib_update('section', 'get'));
201212
librarySubject?.addEventListener('change', () => lib_update('chapter', 'get'));
202213
librarySection?.addEventListener('change', () => lib_update('count', 'clear'));
203-
includeOPL?.addEventListener('change', () => lib_update('count', 'clear'));
204-
includeContrib?.addEventListener('change', () => lib_update('count', 'clear'));
214+
includeOPL?.addEventListener('change', () => {
215+
localStorage.setItem(`${settingStoreID}.includeOPLChecked`, includeOPL.checked);
216+
lib_update('count', 'clear');
217+
});
218+
includeContrib?.addEventListener('change', () => {
219+
localStorage.setItem(`${settingStoreID}.includeContribChecked`, includeContrib.checked);
220+
lib_update('count', 'clear');
221+
});
205222
levels.forEach((level) => level.addEventListener('change', () => lib_update('count', 'clear')));
206223
libraryKeywords?.addEventListener('change', () => lib_update('count', 'clear'));
207224

225+
// If the local storage status of the checks are different than what they
226+
// were when the page loaded, then the count needs to be updated.
227+
if (includeOPL?.checked !== includeOPLInitialStatus || includeContrib?.checked !== includeContribInitialStatus)
228+
lib_update('count', 'clear');
229+
208230
// Set up the advanced view selects to submit the form when changed.
209231
const libraryBrowserForm = document.forms['library_browser_form'];
210232
if (libraryBrowserForm) {

0 commit comments

Comments
 (0)