blob: f528850ba073741af253ef2576f6c0903355f607 [file] [log] [blame]
j7940eec2020-12-28 14:00:41 -06001/**
2 * @file DTPS Core functions and module loader
3 * @author jottocraft
jd4e75d02023-08-22 12:45:59 -07004 * @version v3.9.2
j7940eec2020-12-28 14:00:41 -06005 *
j6e1a7bf2026-10-13 03:37:04 +00006 * @copyright Copyright (c) jottocraft 2020
j40db0272022-01-14 15:18:29 -08007 * @license MIT
j7940eec2020-12-28 14:00:41 -06008 */
9
10//Make sure DTPS isn't already loading
j0f3d7db2026-10-13 04:56:55 +000011if (typeof dtps !== "undefined") throw new Error("Error: DTPS is already loading");
j7940eec2020-12-28 14:00:41 -060012
13/**
14 * Global DTPS object
15 * All global DTPS functions and variables are stored in this object
16 *
17 * @global
18 * @namespace dtps
19 * @property {number} ver Comparable version number
20 * @property {string} env DTPS enviornment ("prod" or "dev")
21 * @property {string} readableVer Formatted semantic version number
22 * @property {Class[]} classes Array of classes the current user is in
23 * @property {string} baseURL The base URL that DTPS is being loaded from
24 * @property {boolean} unstable This is true if loading an unstable version of DTPS
25 * @property {boolean} gradebookExpanded True if gradebook details (Show more...) is open. Used in the generic gradebook and may be used in custom gradebook implementations.
jdc6ea0e2022-04-26 16:03:27 -070026 * @property {boolean} reloadPending True if the user has made changes that require a reload
j0f3d7db2026-10-13 04:56:55 +000027 * @property {string|undefined} popup Popup to show when loaded. Either undefined (no popup) or "firstrun".
j7940eec2020-12-28 14:00:41 -060028 * @property {User} user Current user, fetched with dtps.init
29 * @property {number|string} selectedClass The selected class number, or "dash" if the dashboard is selected. Set when the first screen is loaded in dtps.init.
30 * @property {string} selectedContent The selected class content/tab. Set when the first class content is loaded. Defaults to "stream".
31 * @property {number|undefined} bgTimeout Background transition timeout when switching between classes
32 * @property {Array<Assignment|Announcement>} updates Array of up to 10 recently graded assignments or announcements.
33 * @property {DashboardItem[]} dashboardItems Array of items that can be shown on the dashboard
34 * @property {DashboardItem[]} leftDashboard Items on the left side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
35 * @property {DashboardItem[]} rightDashboard Items on the right side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
j7940eec2020-12-28 14:00:41 -060036 * @property {boolean} searchScrollListener True if the search scroll listener has been added
37 */
38var dtps = {
jd4e75d02023-08-22 12:45:59 -070039 ver: 3_09_2,
40 readableVer: "v3.9.2",
j0f3d7db2026-10-13 04:56:55 +000041 env: new URL(window.dtpsBaseURL || "https://powerplus.app").hostname == "localhost" ? "dev" : "prod",
j7940eec2020-12-28 14:00:41 -060042 classes: [],
43 baseURL: window.dtpsBaseURL || "https://powerplus.app",
44 unstable: window.dtpsBaseURL !== "https://powerplus.app",
45 gradebookExpanded: false,
jdc6ea0e2022-04-26 16:03:27 -070046 reloadPending: false,
j7940eec2020-12-28 14:00:41 -060047 updates: [],
48 dashboardItems: [
49 {
50 name: "Calendar",
51 id: "dtps.calendar",
52 icon: "event",
53 size: 100,
54 defaultSide: "left"
55 }, {
56 name: "Updates",
57 id: "dtps.updates",
58 icon: "calendar_view_day",
59 size: 170,
60 defaultSide: "left"
61 }, {
62 name: "Due Today",
63 id: "dtps.dueToday",
64 icon: "check_circle_outline",
65 size: 20,
66 defaultSide: "right"
67 }, {
68 name: "Upcoming Assignments",
69 id: "dtps.upcoming",
70 icon: "view_stream",
71 size: 250,
72 defaultSide: "right"
73 }
j0f3d7db2026-10-13 04:56:55 +000074 ]
j7940eec2020-12-28 14:00:41 -060075};
76
77//Load jQuery ASAP
j6ca9c7e2026-10-13 20:39:55 +000078jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/jquery.min.js");
j7940eec2020-12-28 14:00:41 -060079
80/**
81 * Debugging shortcut for getting the selected class. This should only be used in the web inspector and not in actual code.
82 *
83 * @return {object|undefined} The selected class
84 */
85dtps.class = function () {
86 return dtps.classes[dtps.selectedClass];
jd80b6e02021-04-19 20:16:38 -070087};
88
89//Detect debug info shortcut
90document.onkeydown = function (event) {
91 if (event.ctrlKey && event.altKey && (event.code == "KeyD")) {
j5bcb1122021-05-25 12:53:21 -070092 var replacer = function (key, value) {
jd80b6e02021-04-19 20:16:38 -070093 //Truncate long properties
94 if (["assignments", "people", "modules", "discussions", "pages", "outcomes"].includes(key)) {
95 if (value instanceof Array) return "[truncated] (array, length " + value.length + ")";
96 if (typeof value == "object") return "[truncated] (object, keys " + Object.keys(value).length + ")";
97 return value;
98 }
99
100 //Remove sensitive properties/PII
101 if (["letter", "number75", "grade", "lowestScore"].includes(key)) return "[redacted] (" + (typeof value) + ")";
102
103 return value;
104 };
105
106 $(".card.details").html(/*html*/`
107 <i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="fluid-icon close">close</i>
108
109 <h4 style="font-weight: bold;">Debug</h4>
110
111 <div style="margin: 40px 0px;">
112 <h5>User</h5>
j6ca9c7e2026-10-13 20:39:55 +0000113 <pre><code class="prettyprint">${DOMPurify.sanitize(JSON.stringify(dtps.user, null, '\t'))}</code></pre>
jd80b6e02021-04-19 20:16:38 -0700114 </div>
115
j5bcb1122021-05-25 12:53:21 -0700116 ${dtps.classes[dtps.selectedClass] ? /*html*/`
jd80b6e02021-04-19 20:16:38 -0700117 <div style="margin: 40px 0px;">
118 <h5>Selected class</h5>
j6ca9c7e2026-10-13 20:39:55 +0000119 <pre><code class="prettyprint">${DOMPurify.sanitize(JSON.stringify(dtps.classes[dtps.selectedClass], replacer, '\t'))}</code></pre>
jd80b6e02021-04-19 20:16:38 -0700120 </div>
121 ` : ``
122 }
123 `);
124
125 if (!window.PR) {
j6ca9c7e2026-10-13 20:39:55 +0000126 $.getScript("https://cdn.jottocraft.com/3rdparty/scripts/run_prettify.js");
jd80b6e02021-04-19 20:16:38 -0700127 } else {
128 PR.prettyPrint();
129 }
130
131 //Close other active cards and open the assignment details card
132 fluid.cards.close(".card.focus");
133 fluid.cards(".card.details");
134 }
j7940eec2020-12-28 14:00:41 -0600135}
136
137/**
j7940eec2020-12-28 14:00:41 -0600138 * Logs debugging messages
139 *
j58471992021-01-17 19:29:37 -0800140 * @param {...*} msg The debugging messages to log
j7940eec2020-12-28 14:00:41 -0600141 */
j58471992021-01-17 19:29:37 -0800142dtps.log = function () {
jdc6ea0e2022-04-26 16:03:27 -0700143 console.log("[DTPS]", ...arguments);
j7940eec2020-12-28 14:00:41 -0600144}
145
j6ca9c7e2026-10-13 20:39:55 +0000146/**
147 * Escapes a string for use inside a quoted HTML attribute value.
148 * DOMPurify.sanitize does not escape quotes, so it can't be used for attribute values.
149 *
150 * @param {*} str The value to escape
151 * @return {string} Escaped string
152 */
153dtps.escapeAttr = function (str) {
154 return String(str).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
155}
156
157/**
158 * Sanitizes rich HTML content from the LMS (assignment bodies, pages, posts, etc.).
159 * Embedded iframes (e.g. videos) and link targets are allowed.
160 *
161 * @param {string} html The HTML to sanitize
162 * @return {string} Sanitized HTML
163 */
164dtps.sanitizeContent = function (html) {
165 return DOMPurify.sanitize(html, { ADD_TAGS: ["iframe"], ADD_ATTR: ["allow", "allowfullscreen", "frameborder", "scrolling", "target"] });
166}
167
168/**
169 * Ensures that a URL is safe
170 *
171 * @param {string} url The URL to check
172 * @returns {string} The URL if it is safe, otherwise "about:blank"
173 */
174dtps.safeURL = function (url) {
175 try {
176 var protocol = new URL(url, window.location.href).protocol;
177 if (["http:", "https:", "mailto:", "tel:"].includes(protocol)) return url;
178 } catch (e) { }
179 return "about:blank";
180}
181
182/**
183 * Shows an error message alert and logs to console, WITHOUT SANITIZING INPUT
184 *
185 * @param {string} msg The error to display
186 * @param {string} [devNotes] Technical error details displayed in a smaller font
187 * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
188 */
189dtps.unsafeError = function (msg, devNotes, err) {
190 if (err !== null) {
191 var formattedDevNotes = "";
192 if (devNotes) {
193 formattedDevNotes = '<div style="font-size: 12px; color: var(--secText, gray); margin-top: 10px;">' + devNotes + '</div>';
194 }
195 console.error("[DTPS !!ERROR!!]", devNotes + ": ", err);
196 fluid.alert("Error", msg + formattedDevNotes, "error");
197 }
198}
j7940eec2020-12-28 14:00:41 -0600199
200/**
201 * Shows an error message alert and logs to console
202 *
203 * @param {string} msg The error to display
204 * @param {string} [devNotes] Technical error details displayed in a smaller font
205 * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
206 */
207dtps.error = function (msg, devNotes, err) {
j6ca9c7e2026-10-13 20:39:55 +0000208 dtps.unsafeError(
209 DOMPurify.sanitize(msg),
210 DOMPurify.sanitize(devNotes),
211 err
212 );
j7940eec2020-12-28 14:00:41 -0600213}
214
215/**
216 * Renders "Welcome to Project DTPS" screen on the first run
217 */
218dtps.firstrun = function () {
219 //Set latest changelog version to current version
220 window.localStorage.setItem('dtps', dtps.ver);
221
222 //Welcome to DTPS screen HTML
223 jQuery(".card.changelog").html(/*html*/`
224 <h3 style="margin-bottom: 0px;">Welcome to Power+</h3>
225 <h5 style="color: var(--secText); font-weight: bold; font-size: 22px;">${dtps.readableVer}</h5>
226
227 <div class="welcomeSection">
228 <i class="fluid-icon">dashboard</i>
j0f3d7db2026-10-13 04:56:55 +0000229 <h5>Manage your coursework</h5>
j7940eec2020-12-28 14:00:41 -0600230 <p>Power+ organizes all of your coursework so you can easily see what you need to do next. The dashboard shows upcoming assignments, recent grades, and announcements.
j0f3d7db2026-10-13 04:56:55 +0000231 ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of October 2026, all d.tech-specific features, including CBL grade calculation, have been removed from Power+.</b></p>` : ``}
j7940eec2020-12-28 14:00:41 -0600232 </div>
233
234 ${dtpsLMS.isDemoLMS ? /*html*/`
235 <div class="welcomeSection">
236 <i class="fluid-icon">priority_high</i>
237 <h5>This is a demo</h5>
238 <p>Assignment information, grades, and other content displayed is not real and is for demonstration purposes only. This demo does not retrieve or collect any data.</p>
239 </div>
240 ` : /*html*/`
241 <div class="welcomeSection">
242 <i class="fluid-icon">security</i>
243 <h5>Privacy</h5>
j5e67d8e2022-11-08 22:55:04 -0800244 <p>
245 Power+ records your device and network type, Canvas institution, and region when you load Power+.
246 Analytics events are associated with a unique ID generated with a one-way-hash from your Canvas ID and institution.
247 Data is collected directly by Power+ and is never shared with or sold to any third parties.
jb39e6d92021-01-30 20:34:04 -0800248 Power+ does <b>not</b> and will <b>never</b> collect any personal information, such as names, classes, or grades.
j5e67d8e2022-11-08 22:55:04 -0800249 </p>
j7940eec2020-12-28 14:00:41 -0600250 </div>
251 <div class="welcomeSection">
252 <i class="fluid-icon">priority_high</i>
253 <h5>Power+ is not official</h5>
254 <p>Assignment information, grades, and other content displayed in Power+ are not official. Power+ is neither created nor endorsed by ${dtpsLMS.legalName}.
255 Power+ may have bugs that could cause it to display inaccurate information. Use Power+ at your own risk.</p>
256 </div>
257 `}
258
259 <br />
260 <button onclick="window.localStorage.setItem('dtpsInstalled', 'true'); fluid.cards.close('.card.changelog');" class="btn">
261 <i class="fluid-icon">arrow_forward</i> Continue
262 </button>
263 `);
264
265 //Show Welcome to DTPS card
266 fluid.cards.close(".card.focus");
267 fluid.cards(".card.changelog", "stayOpen");
268};
269
270/**
271 * Renders the DTPS loading screen
272 */
273dtps.renderLoadingScreen = function () {
274 if (!window.dtpsPreLoader || dtps.user) {
275 //Only show the loader if the extension hasn't already shown it
276 jQuery("body").append(/*html*/`
277 <div id="dtpsNativeOverlay" style="background-color: #151515; position: fixed; top: 0px; left: 0px; width: 100%; height: 100vh; z-index: 99;text-align: center;z-index: 999;transition: opacity 0.2s;">
278 <img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/7dDUVh2.png" />
279 <br />
280 <div class="progress"><div class="indeterminate"></div></div>
281 <style>body {background-color: #151515; overflow: hidden;}*,:after,:before{box-sizing:border-box}.progress{position:relative;width:600px;height:5px;overflow:hidden;border-radius:12px;background:#262626;backdrop-filter:opacity(.4);display:inline-block;margin-top:75px}.progress .indeterminate{position:absolute;background:#e3ba4b;height:5px;animation:indeterminate 1.4s infinite;animation-timing-function:linear}@keyframes indeterminate{0%{width:5%;left:-15%}to{width:100%;left:110%}}</style>
282 </div>
283 `);
284 }
285}
286
287/**
288 * Load all external JavaScript libraries
289 *
290 * @param {function} cb Callback function
291 */
jb39e6d92021-01-30 20:34:04 -0800292dtps.JS = function () {
293 return new Promise((resolve, reject) => {
294 //Moment & Fullcalendar are used for the calendar on the dashboard
j6ca9c7e2026-10-13 20:39:55 +0000295 jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/fullcalendar_main.min.js", function () {
296 jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/fullcalendar_locales-all.min.js");
jb39e6d92021-01-30 20:34:04 -0800297 });
j7940eec2020-12-28 14:00:41 -0600298
jb39e6d92021-01-30 20:34:04 -0800299 //Lunr is used for search
j6ca9c7e2026-10-13 20:39:55 +0000300 jQuery.getScript('https://cdn.jottocraft.com/3rdparty/scripts/lunr.min.js');
j7940eec2020-12-28 14:00:41 -0600301
jb39e6d92021-01-30 20:34:04 -0800302 //jQuery UI for dashboard settings page
j6ca9c7e2026-10-13 20:39:55 +0000303 jQuery.getScript('https://cdn.jottocraft.com/3rdparty/scripts/jquery-ui.min.js');
j7940eec2020-12-28 14:00:41 -0600304
jb39e6d92021-01-30 20:34:04 -0800305 //Tinycolor used for better dark mode support
306 jQuery.getScript("https://cdn.jottocraft.com/tinycolor.js");
j7940eec2020-12-28 14:00:41 -0600307
jce0d1cb2022-01-07 11:16:20 -0800308 //dtao/nearest-color is used for finding the nearest class color
309 jQuery.getScript("https://cdn.jottocraft.com/nearest-color.dtao.js", () => {
310 //Fluid UI for core UI elements
j6ca9c7e2026-10-13 20:39:55 +0000311 jQuery.getScript(dtps.baseURL + "/fluid/fluid.js", () => {
312 jQuery.getScript("https://cdn.jottocraft.com/3rdparty/scripts/purify.min.js", resolve);
313 });
j5f5942c2021-02-01 08:38:43 -0800314 });
j7940eec2020-12-28 14:00:41 -0600315 });
316}
317
318/**
319 * Load all DTPS CSS files
320 */
321dtps.CSS = function () {
322 jQuery("<link/>", {
323 rel: "stylesheet",
324 type: "text/css",
jdc6ea0e2022-04-26 16:03:27 -0700325 href: dtps.baseURL + "/fluid/fluid.css",
j7940eec2020-12-28 14:00:41 -0600326 class: "dtpsHeadItem"
327 }).appendTo("head");
328
329 jQuery("<link/>", {
330 rel: "stylesheet",
331 type: "text/css",
332 href: dtps.baseURL + "/dtps.css",
333 class: "dtpsHeadItem"
334 }).appendTo("head");
335
336 jQuery("<link/>", {
337 rel: "stylesheet",
338 type: "text/css",
339 href: "https://fonts.googleapis.com/css?family=Material+Icons+Round",
340 class: "dtpsHeadItem"
341 }).appendTo("head");
342
343 jQuery("<link/>", {
344 rel: "stylesheet",
345 type: "text/css",
346 href: "https://cdn.jsdelivr.net/npm/[email protected]/main.min.css",
347 class: "dtpsHeadItem"
348 }).appendTo("head");
349
350 jQuery("<link/>", {
351 rel: "stylesheet",
352 type: "text/css",
353 href: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
354 class: "dtpsHeadItem"
355 }).appendTo("head");
356}
357
358/**
j29812c42022-04-27 15:41:40 -0700359 * Gets the amount of minutes elapsed in the day
360 *
361 * @param {date} d The day
362 * @returns The amount of minutes or null if the date is invalid
363 */
364dtps.dayTimeMinutes = function (d) {
365 if (!d) return null;
366
367 d = new Date(d);
368 if (isNaN(d.getTime())) return null;
369
370 return (d.getHours() * 60) + d.getMinutes();
371}
372
373/**
j7940eec2020-12-28 14:00:41 -0600374 * Starts DTPS (entrypoint function)
375 */
376dtps.init = function () {
377 //Initial log
378 dtps.log("Starting DTPS " + dtps.readableVer + "...");
379
jb39e6d92021-01-30 20:34:04 -0800380 //Disable dev version
381 if (window.localStorage.getItem('dtpsLoaderPref') == "dev") {
382 window.localStorage.removeItem('dtpsLoaderPref');
383 }
384
j7940eec2020-12-28 14:00:41 -0600385 //Check for LMS config
386 if (!window.dtpsLMS) {
j0f3d7db2026-10-13 04:56:55 +0000387 throw new Error("No DTPS LMS configuration found");
j7940eec2020-12-28 14:00:41 -0600388 }
389
390 //Determine if this is the first time loading DTPS
391 if (window.localStorage.dtpsInstalled !== "true") {
392 dtps.popup = "firstrun";
393 }
394
395 //Render loading screen
396 dtps.renderLoadingScreen();
397
398 //Get URL parameters
399 var urlParams = new URLSearchParams(window.location.search);
400 if (Array.from(urlParams).length) window.history.replaceState(null, null, window.location.pathname);
401
402 //Fluid UI settings
403 window.fluidConfig = {
404 config: {
405 autoLoad: false,
406 allowThemeMenu: false //This is false because Power+ uses its own theme settings UI
407 }
408 };
409
410 //Set env discovery
411 window.localStorage.setItem("jottocraftEnv", true);
412
413 //Default selected content
414 dtps.selectedContent = "stream";
415
416 //Begin loading CSS
417 dtps.CSS();
418
419 //Begin loading static DTPS HTML
420 dtps.render();
421
j0f3d7db2026-10-13 04:56:55 +0000422 //Fetch JavaScript modules
423 dtps.JS().then(() => {
j7940eec2020-12-28 14:00:41 -0600424 //Fetch user and class data
425 return dtpsLMS.fetchUser();
426 }).then(data => {
427 //Prevent resetting the user if the user is already set (for parent accounts)
428 dtps.user = data;
429
430 //If this is a parent account, show the parent UI
431 if (dtps.user.children && dtps.user.children.length) {
432 dtps.user.parent = true;
433
434 //Fetch classes for all students
435 return new Promise((resolve, reject) => {
436 var allClasses = [];
437 var promises = [];
438
439 dtps.user.children.forEach(child => {
440 promises.push(new Promise(function (resolve, reject) {
441 dtpsLMS.fetchClasses(child.id).then((data) => {
442 //Prepend child ID to class ID
443 data.forEach(course => {
444 course.id = child.id + "-" + course.id;
445 course.group = child.name;
446 });
447
448 allClasses = allClasses.concat(data);
449 resolve();
450 }).catch(reject);
451 }));
452 });
453
454 Promise.all(promises).then(() => {
455 resolve(allClasses);
456 });
457 });
458 } else {
459 return dtpsLMS.fetchClasses(dtps.user.id);
460 }
j7940eec2020-12-28 14:00:41 -0600461 }).then(classData => {
462 //Store classData to dtps.classes
463 dtps.classes = classData;
464
465 //Add course num props
466 dtps.classes.forEach((course, index) => course.num = index);
467
jb39e6d92021-01-30 20:34:04 -0800468 //Define DTPS class color pallete
469 var nearestCourseColor = nearestColor.from({
470 //Primary color shades
471 red: "#cc4747",
472 brown: "#9a4429",
473 orange: "#ce734e",
474 pumpkin: "#c58535",
475 yellow: "#b58f38",
476 yellowGreen: "#7c9630",
477 green: "#439a47",
478 oceanGreen: "#339a70",
479 keppel: "#40b5c3",
480 skyBlue: "#40a4d6",
481 blue: "#2d72a0",
482 purple: "#985cab",
483 magenta: "#bd3e69",
484 pink: "#ec7ca5",
485 gray: "#888888",
486 //Dark color shades
487 gold: "#94652a",
488 darkRed: "#943f3f",
489 darkBlue: "#485182",
490 darkPurple: "#6f4882",
491 darkGreen: "#3d7358",
492 //Light color shades
493 lightOrange: "#ea7a44",
494 lightRed: "#e07f7f",
495 lightBlue: "#76c1e6",
496 lightPurple: "#978fd6",
497 lightGreen: "#7ebb95",
498 lightBrown: "#928871"
499 });
j7940eec2020-12-28 14:00:41 -0600500
j0f3d7db2026-10-13 04:56:55 +0000501 //Loop over each class to update the color
jb39e6d92021-01-30 20:34:04 -0800502 dtps.classes.forEach(course => {
503 course.color = course.color ? nearestCourseColor(course.color).value : "gray";
jb39e6d92021-01-30 20:34:04 -0800504 });
505
506 //Fluid UI screens
507 fluid.defaultScreen = "dashboard";
508 fluid.screens.dashboard = dtps.baseURL + "/scripts/assignments.js";
509 fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
510 fluid.screens.moduleStream = dtps.baseURL + "/scripts/assignments.js";
511 fluid.screens.people = dtps.baseURL + "/scripts/people.js";
512 fluid.screens.search = dtps.baseURL + "/scripts/search.js";
513 fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
514 fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
jdc6ea0e2022-04-26 16:03:27 -0700515 fluid.screens.gradebook = dtps.baseURL + "/scripts/assignments.js";
jb39e6d92021-01-30 20:34:04 -0800516
517 //Begin fetching class assignments
518 var fetchedAnnouncements = [];
519 dtps.classes.forEach((course, courseIndex) => {
j0f3d7db2026-10-13 04:56:55 +0000520 dtpsLMS.fetchAssignments(course.userID, course.lmsID).then(assignments => {
j29812c42022-04-27 15:41:40 -0700521 //Map due date array
522 const dueDates = assignments.map(a => dtps.dayTimeMinutes(a.dueAt)).filter(d => d !== null).sort((a, b) => a - b);
523
524 if (dueDates && dueDates.length >= 10) {
525 //Get due date IQR
526 var q1 = dueDates[Math.floor((dueDates.length / 5))];
527 var q3 = dueDates[Math.ceil((dueDates.length * (4 / 5)))];
528 var iqr = q3 - q1;
529
530 //Find min and max within reasonable range
531 course.usualDueRange = [(q1 - (iqr * 1.5)) - 120, (q3 + (iqr * 1.5)) + 120];
532 }
533
jb39e6d92021-01-30 20:34:04 -0800534 //Store assignments in the class
535 course.assignments = assignments;
536
537 //Add class props to assignments and add recent assignments to updates array
538 course.assignments.forEach(assignment => {
539 assignment.class = courseIndex;
540
541 if (assignment.gradedAt && assignment.grade) {
542 //Add class number and type to object
543 dtps.updates.push({
544 class: course.num,
545 type: "assignment",
546 ...assignment
547 })
548 }
549 });
550
551 //Sort updates array from newest -> oldest
552 dtps.updates.sort(function (a, b) {
553 //Sort by postedAt (announcements) or gradedAt (assignments)
554 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
555 });
556
557 //Keep only the 15 most recent updates
558 if (dtps.updates.length > 15) dtps.updates.length = 15;
559
jb39e6d92021-01-30 20:34:04 -0800560 //Grade history and gradebook
561 if ((course.letter || course.grade) && (course.letter !== "...")) {
562 //Enable gradebook for this class
563 course.hasGradebook = true;
564
jb39e6d92021-01-30 20:34:04 -0800565 //If the class is selected, call dtps.presentClass again to show the grades tab
566 if (courseIndex == dtps.selectedClass) {
567 dtps.presentClass(courseIndex);
568
569 //If the gradebook is selected, reload the gradebook
570 if (dtps.selectedContent == "grades") {
571 fluid.screen('gradebook', dtps.classes[courseIndex].id);
572 }
573 }
574 } else {
575 //This class doesn't have a gradebook, exit gradebook if selected
576 if ((courseIndex == dtps.selectedClass) && (dtps.selectedContent == "grades")) {
577 fluid.screen('stream', dtps.classes[courseIndex].id);
578 }
579 }
580
jb39e6d92021-01-30 20:34:04 -0800581 //Re-render screen if the dashboard or stream is selected
582 if ((dtps.selectedClass == "dash") || ((dtps.selectedContent == "stream") && (dtps.selectedClass == course.num))) {
583 fluid.screen();
j7940eec2020-12-28 14:00:41 -0600584 }
585 });
586
jb39e6d92021-01-30 20:34:04 -0800587 if (!fetchedAnnouncements.includes(course.lmsID)) {
588 //Add lmsID to list of fetched announcements to prevent duplicates
589 fetchedAnnouncements.push(course.lmsID);
j7940eec2020-12-28 14:00:41 -0600590
jb39e6d92021-01-30 20:34:04 -0800591 dtpsLMS.fetchAnnouncements(course.lmsID).then(announcements => {
592 //Add announcements to updates array
593 announcements.forEach(announcement => {
594 //Add class number and type to object
595 dtps.updates.push({
596 class: course.num,
597 type: "announcement",
598 ...announcement
599 });
j7940eec2020-12-28 14:00:41 -0600600 });
601
602 //Sort updates array from newest -> oldest
603 dtps.updates.sort(function (a, b) {
604 //Sort by postedAt (announcements) or gradedAt (assignments)
605 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
606 });
607
608 //Keep only the 15 most recent updates
609 if (dtps.updates.length > 15) dtps.updates.length = 15;
610
jb39e6d92021-01-30 20:34:04 -0800611 if (dtps.selectedClass == "dash") {
j7940eec2020-12-28 14:00:41 -0600612 fluid.screen();
613 }
614 });
j7940eec2020-12-28 14:00:41 -0600615 }
616 });
jb39e6d92021-01-30 20:34:04 -0800617
618 //Render remaining HTML
619 dtps.renderLite();
620
621 //Render initial screen
622 fluid.screen();
623
624 //Load popup if needed
625 if (dtps.popup == "firstrun") {
626 dtps.firstrun();
jb39e6d92021-01-30 20:34:04 -0800627 }
j5e67d8e2022-11-08 22:55:04 -0800628
j450fbd42022-09-01 11:13:11 -0700629 //Render inbox
630 if (dtpsLMS.fetchUnreadMessageCount) {
631 dtpsLMS.fetchUnreadMessageCount().then(count => {
632 jQuery("#dtpsUnreadCount span").text(count);
633
634 if (Number(count) > 0) {
635 jQuery("#dtpsUnreadCount").addClass("active");
636 }
637
638 jQuery("#dtpsUnreadCount").show();
639 });
640 }
j7940eec2020-12-28 14:00:41 -0600641 }).catch(function (err) {
642 //Web request error
643 console.error("[DTPS] Error fetching user and classes at dtps.init", err);
644
645 //Check for login redirect
646 if ((err.action == "login") && err.redirectURL) {
647 //Redirect to login page
j6ca9c7e2026-10-13 20:39:55 +0000648 window.location.href = dtps.safeURL(err.redirectURL);
j7940eec2020-12-28 14:00:41 -0600649 } else {
j6ca9c7e2026-10-13 20:39:55 +0000650 dtps.unsafeError("Failed to get user and/or course data", "Exception in promise @ dtps.init");
j7940eec2020-12-28 14:00:41 -0600651 }
652 });
653
654 //Load dashboard prefrences
655 dtps.loadDashboardPrefs();
656}
657
658/**
659 * Formats a date to a readable date string
660 *
661 * @param {Date} date The date to format
662 * @return {string} Formatted date and time string
663 */
664dtps.formatDate = function (date) {
665 if (date) {
666 return new Date(date).toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric', hour: "numeric", minute: "numeric" });
667 } else {
668 return "";
669 }
670}
671
672/**
673 * Adjusts the height of an iFrame to match its content
674 *
675 * @param {string} iframeID The ID of the iFrame element to adjust
676 */
677dtps.iframeLoad = function (iframeID) {
678 var iFrame = document.getElementById(iframeID);
679 if (iFrame) {
680 iFrame.height = "";
681 iFrame.height = iFrame.contentWindow.document.body.scrollHeight + "px";
682 }
683}
684
685/**
686 * Clears all DTPS data
687 */
688dtps.clearData = function () {
689 if (window.confirm("Clearing Power+ data will clear all local user data stored by Power+. This should be done if it is a new semester / school year or if you are having issues with Power+. Are you sure you want to clear all your Power+ data?")) {
690 window.localStorage.clear()
691 window.alert("Power+ data cleared")
692 }
693}
694
695/**
696 * Renders the class list in the sidebar
697 *
698 * @param {boolean} [override] True if the sidebar should be forcefully re-rendered
699 */
700dtps.showClasses = function (override) {
701 //Array of class HTML for the sidebar
702 dtps.classlist = [];
703
704 var previousClassGroup = null;
705 for (var i = 0; i < dtps.classes.length; i++) {
706 //Determine letter grade HTML
707 var letterGradeHTML = "";
j6ca9c7e2026-10-13 20:39:55 +0000708 if (dtps.classes[i].letter) letterGradeHTML = DOMPurify.sanitize(dtps.classes[i].letter);
j7940eec2020-12-28 14:00:41 -0600709 if (dtps.classes[i].letter == null) letterGradeHTML = "--";
jb39e6d92021-01-30 20:34:04 -0800710 if (dtps.classes[i].letter == "...") letterGradeHTML = `<div class="shimmer" style="vertical-align:middle;display: inline-block;width: 22px;height: 22px;border-radius: 8px;"></div>`; //Show loading indicator for ...
j2566c4e2021-10-01 15:25:49 -0700711 if (dtps.classes[i].letter == "ERROR") letterGradeHTML = `<i class="fluid-icon">error</i>`;
j7940eec2020-12-28 14:00:41 -0600712
713 if (dtps.classes[i].group && (dtps.classes[i].group !== previousClassGroup)) {
714 if (previousClassGroup) dtps.classlist.push(`</div></div>`);
715 dtps.classlist.push(/*html*/`
j6ca9c7e2026-10-13 20:39:55 +0000716 <div id="dtpsClassListGroup-${dtps.escapeAttr(dtps.classes[i].group)}" class="group open">
j7940eec2020-12-28 14:00:41 -0600717 <div class="name item">
j6ca9c7e2026-10-13 20:39:55 +0000718 <i class="fluid-icon"></i> <span class="label">${DOMPurify.sanitize(dtps.classes[i].group)}</span>
j7940eec2020-12-28 14:00:41 -0600719 </div>
720
721 <div class="items">
722 `);
723 } else if (!dtps.classes[i].group && previousClassGroup) {
724 dtps.classlist.push(`</div></div>`);
725 }
726
727 //Add class HTML to array
728 dtps.classlist.push(/*html*/`
729 <div
730 onclick="${'dtps.selectedClass = ' + i}"
731 class="${'class item ' + i + ' ' + (dtps.selectedClass == i ? " active" : "")}"
j6ca9c7e2026-10-13 20:39:55 +0000732 style="${'--classColor: ' + dtps.escapeAttr(dtps.classes[i].color)}"
j7940eec2020-12-28 14:00:41 -0600733 >
jb39e6d92021-01-30 20:34:04 -0800734 ${dtps.classes[i].grade && dtps.classes[i].letter ? /*html*/`
735 <i class="fluid-icon grade">
736 <span class="letter">${letterGradeHTML}</span>
737 <span class="percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span></span>
738 </i>
739 ` : dtps.classes[i].grade ? /*html*/`
740 <i class="fluid-icon grade percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">
741 ${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span>
742 </i>
743 ` : /*html*/`
744 <i class="fluid-icon grade letter">
745 ${letterGradeHTML}
746 </i>
747 `}
748
j6ca9c7e2026-10-13 20:39:55 +0000749 <span class="label">${DOMPurify.sanitize(dtps.classes[i].subject)}</span>
j7940eec2020-12-28 14:00:41 -0600750 </div>
751 `);
752
753 previousClassGroup = dtps.classes[i].group;
754 }
755
756 if (previousClassGroup) dtps.classlist.push(`</div></div>`);
757
758 //Only render HTML if the sidebar doesn't already have the classes rendered, or if override is true
759 if (!jQuery(".sidebar .class.dash")[0] || override) {
760 jQuery(".sidebar").html(/*html*/`
761 <div class="title">
762 <img src="${dtps.baseURL + "/icon.svg"}" />
763 <h4>Power+</h4>
764 </div>
765
766 <div class="items">
767 <div onclick="dtps.selectedClass = 'dash';" class="class item main dash ${dtps.selectedClass == "dash" ? "active" : ""}">
768 <i class="fluid-icon">dashboard</i>
769 <span class="label">Dashboard</span>
770 </div>
771
772 <div class="divider"></div>
773
774 ${dtps.classlist.join("")}
775 </div>
776
777 <div class="collapse">
778 <i class="fluid-icon"></i>
779 </div>
780 `);
781 fluid.init();
782
783 //Change view to stream if coming from pages or discussions, since those tabs change the sidebar
784 if ((dtps.selectedContent == "pages") || (dtps.selectedContent == "discuss")) {
785 //Show stream
786 if (dtps.classes[dtps.selectedClass]) fluid.screen('stream', dtps.classes[dtps.selectedClass].id);
787 }
788
789 //Class onclick listener
jb39e6d92021-01-30 20:34:04 -0800790 $(".class").click(function (event) {
j7940eec2020-12-28 14:00:41 -0600791 //Load class content based on what's selected
792 if (((dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) && dtps.classes[dtps.selectedClass]) {
793 if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem("courseworkPref-" + dtps.classes[dtps.selectedClass].id) == "moduleStream")) {
794 fluid.screen("moduleStream", dtps.classes[dtps.selectedClass].id);
795 } else {
796 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
797 }
798 }
799
800 if ((dtps.selectedContent == "people") && dtps.classes[dtps.selectedClass]) {
801 fluid.screen("people", dtps.classes[dtps.selectedClass].id);
802 }
803
804 if ((dtps.selectedContent == "grades") && dtps.classes[dtps.selectedClass]) {
805 if (dtps.classes[dtps.selectedClass].hasGradebook) {
806 fluid.screen("gradebook", dtps.classes[dtps.selectedClass].id);
807 } else {
808 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
809 }
810 }
811
812 if (dtps.selectedClass == "dash") {
813 fluid.screen("dashboard");
814 }
815 });
816 }
817}
818
819/**
820 * Renders the class header (color, name, tabs, etc.) and sets the class as the selected class
821 *
822 * @param {number|string} classNum The class number to load or "dash" if loading the dashboard
823 */
824dtps.presentClass = function (classNum) {
825 //Set classNum as selected class
826 dtps.selectedClass = classNum;
827
828 //Update document title with class name
829 if (dtps.classes[classNum]) {
830 document.title = dtps.classes[classNum].subject + " | Power+";
831 } else {
832 document.title = "Power+";
833 }
834
835 //Set the class image
j4d933ce2022-04-08 21:49:55 +0000836 if ((fluid.get("pref-hideClassImages") != "true") && dtps.classes[classNum] && dtps.classes[classNum].image) {
j7940eec2020-12-28 14:00:41 -0600837 $(".headerArea").addClass("classImage");
838 $(".headerArea img").attr("src", dtps.classes[classNum].image);
839 $(".headerArea img").show();
840 } else {
841 $(".headerArea").removeClass("classImage");
842 $(".headerArea img").hide();
843 }
844
845 //Remove active class from other classes in the sidebar, add the active class to the selected class
846 $(".sidebar .class").removeClass("active");
847 $(".class." + classNum).addClass("active");
848
849 //Update title to show class name
850 //If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
851 $("#headText span").text(classNum == "dash" ? "Dashboard" : classNum == "search" ? "Search Results" : dtps.classes[classNum] && dtps.classes[classNum].subject);
j0f3d7db2026-10-13 04:56:55 +0000852 var icon = classNum == "dash" ? "dashboard" : classNum == "search" ? "search" : dtps.classes[classNum] && dtps.classes[classNum].icon;
j7940eec2020-12-28 14:00:41 -0600853 if (icon) {
854 $("#headText i").text(icon);
855 $("#headText i").show();
856 } else {
857 $("#headText i").hide();
858 }
859 $("#headText").css("color", (classNum == "dash") || (classNum == "search") ? "var(--text)" : dtps.classes[classNum] && dtps.classes[classNum].color);
860
861 //If the class doesn't exist, hide the tabs
862 //Otherwise, show the tabs
863 if (!dtps.classes[classNum]) {
864 $("#dtpsTabBar").hide();
865 $("#classInfo p").hide();
866 } else {
867 $("#dtpsTabBar").show();
868 }
869
870 //Hide dashboard start date
871 if (classNum !== "search") $(".headerArea .contentLabel").hide();
872
873 //Clear search box if not on the search tab
874 if ((classNum !== "search") && !$("#dtpsMainSearchBox").is(":focus")) {
875 $("#dtpsMainSearchBox").val("");
876 }
877
878 //Set search box content
jd4fc5d82020-12-28 19:38:41 -0600879 dtps.setSearchBox();
j7940eec2020-12-28 14:00:41 -0600880
881 if (dtps.classes[classNum]) {
882 //Show pages tab if the class supports it, otherwise, hide it
883 if (dtps.classes[classNum].pages) {
884 $(".btns .btn.pages").show();
885 } else {
886 $(".btns .btn.pages").hide();
887 }
888
889 //Show people tab if the LMS supports it, otherwise, hide it
890 if (dtps.classes[classNum].people) {
891 $(".btns .btn.people").show();
892 } else {
893 $(".btns .btn.people").hide();
894 }
895
896 //Show pages tab if the class supports it, otherwise, hide it
897 if (dtps.classes[classNum].discussions) {
898 $(".btns .btn.discuss").show();
899 } else {
900 $(".btns .btn.discuss").hide();
901 }
902
903 //Show gradebook if the LMS and the class supports it, otherwise, hide it
j0f3d7db2026-10-13 04:56:55 +0000904 if (dtps.classes[classNum].hasGradebook) {
j7940eec2020-12-28 14:00:41 -0600905 $(".btns .btn.grades").show();
906 } else {
907 $(".btns .btn.grades").hide();
908 }
909
910 //Hide tabs if only one tab is visible
911 if ($("#dtpsTabBar .btn:visible").length < 2) {
912 $("#dtpsTabBar").hide();
913 }
914
915 //Show teacher
916 if (dtps.classes[classNum].teacher) {
917 $("#classInfo .teacher .teacherName").text(dtps.classes[classNum].teacher.name);
918 $("#classInfo .teacher .teacherImage").css("background-image", "url('" + dtps.classes[classNum].teacher.photoURL + "')");
919 $("#classInfo .teacher").show();
920 } else {
921 $("#classInfo .teacher").hide();
922 }
923
924 if (dtps.classes[classNum].homepage) {
925 $("#classInfo .homepage").show();
926 } else {
927 $("#classInfo .homepage").hide();
928 }
j7940eec2020-12-28 14:00:41 -0600929 }
930
j7940eec2020-12-28 14:00:41 -0600931 if (dtps.selectedContent !== "grades") $(".classContent").removeClass("fixedGradeSummary");
932}
933
934/**
935 * Displays the class homepage
936 *
937 * @param {number} num Class number to show the homepage for
938 */
939dtps.classHome = function (num) {
940 //Render loading screen
941 $(".card.details").html(/*html*/`
942 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
j6ca9c7e2026-10-13 20:39:55 +0000943 <h3 style="font-weight: bold;">${DOMPurify.sanitize(dtps.classes[num].subject)} Homepage</h3>
j7940eec2020-12-28 14:00:41 -0600944
945 <br />
946 <p>Loading...</p>
947 `);
948
949 //Fetch homepage from the LMS
950 dtpsLMS.fetchHomepage(dtps.classes[num].lmsID).then(homepage => {
951 if (homepage) {
j6ca9c7e2026-10-13 20:39:55 +0000952 homepage = dtps.sanitizeContent(homepage);
953
j7940eec2020-12-28 14:00:41 -0600954 //Get computed background and text color to style the iFrame with
955 var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
956 var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
957
958 if ($("body").hasClass("dark")) {
959 homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
960 }
961
jb39e6d92021-01-30 20:34:04 -0800962 //Generate a blob with the assignment body and get its data URL
963 var blob = new Blob([`
j7940eec2020-12-28 14:00:41 -0600964 <base target="_blank" />
965 <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
966 <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
967 ${homepage}
968 `], { type: 'text/html' });
jb39e6d92021-01-30 20:34:04 -0800969 var homepageURL = window.URL.createObjectURL(blob);
j7940eec2020-12-28 14:00:41 -0600970
jb39e6d92021-01-30 20:34:04 -0800971 $(".card.details").html(/*html*/`
972 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
j7940eec2020-12-28 14:00:41 -0600973
j6ca9c7e2026-10-13 20:39:55 +0000974 <h4 style="font-weight: bold;">${DOMPurify.sanitize(dtps.classes[num].subject)} Homepage</h4>
j7940eec2020-12-28 14:00:41 -0600975
jb39e6d92021-01-30 20:34:04 -0800976 <br />
977 <div style="margin-top: 20px;" class="homepageBody">
j6ca9c7e2026-10-13 20:39:55 +0000978 <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}"></iframe>
jb39e6d92021-01-30 20:34:04 -0800979 </div>
980 `);
j7940eec2020-12-28 14:00:41 -0600981
982 fluid.cards(".card.details");
983 } else {
984 fluid.cards.close('.card.details');
985 dtps.error("Homepage unavailable", "homepage is either empty or undefined @ dtps.classHome");
986 }
987 }).catch(e => {
988 dtps.error("Couldn't load homepage", "Caught a promise rejection @ dtps.classHome", e);
989 })
990}
991
992/**
j7940eec2020-12-28 14:00:41 -0600993 * Shows a URL in the iFrame card
994 *
995 * @param {string} url The URL to load
996 */
997dtps.showIFrameCard = function (url) {
998 //Remove any previous URLs
999 $('#CardIFrame').attr('src', '');
1000
1001 //Show iFrame card
1002 fluid.cards('.card.iFrameCard');
1003
1004 //Load new URL
j6ca9c7e2026-10-13 20:39:55 +00001005 $('#CardIFrame').attr('src', dtps.safeURL(url));
j7940eec2020-12-28 14:00:41 -06001006}
1007
1008/**
1009 * Brightens text in an HTML string for dark mode
1010 *
1011 * @param {string} html The HTML to brighten text for
1012 * @param {string} [bg] The background color that the HTML will be displayed on
1013 * @returns {string} HTML string with brightened colors
1014 */
1015dtps.brightenTextForDarkMode = function (html, bg) {
1016 //Use dark mode algorithm
1017 if (!bg) bg = "black";
1018 var fakeRoot = $('<div></div>').append(html);
jd80b6e02021-04-19 20:16:38 -07001019
1020 //Reset text color to black if there is a background color set and no other color set
1021 fakeRoot.find("*").filter(function () {
1022 return ($(this).css("background-color") || $(this).css("background")) && !$(this).css("color") && !$(this).parents().filter(function () {
1023 return $(this).css("color");
1024 }).length;
1025 }).toArray().forEach(element => {
1026 //Reset to black
1027 $(element).css("color", "#2D3B45");
1028 });
1029
1030 //Brighten text colors
j7940eec2020-12-28 14:00:41 -06001031 fakeRoot.find("span").filter(function () {
1032 return $(this).css("color") && !($(this).css("background-color") || $(this).css("background")) && !$(this).parents().filter(function () {
1033 return $(this).css("background-color") || $(this).css("background");
1034 }).length;
1035 }).toArray().forEach(element => {
1036 //Brighten color
1037 var brightness = tinycolor($(element).css("color")).getBrightness() / 255 * 100;
1038 var targetBrightness = (100 - (tinycolor(bg).getBrightness() / 255 * 100)) - brightness;
1039 var brightnessDiff = targetBrightness - brightness;
1040
1041 if (brightnessDiff > 0) {
1042 $(element).css("color", "#" + tinycolor($(element).css("color")).brighten(Math.abs(brightnessDiff)).toHex());
1043 } else {
1044 $(element).css("color", "#" + tinycolor($(element).css("color")).darken(Math.abs(brightnessDiff)).toHex());
1045 }
1046 });
jd80b6e02021-04-19 20:16:38 -07001047
j7940eec2020-12-28 14:00:41 -06001048 return fakeRoot.html();
1049}
1050
1051/**
j7940eec2020-12-28 14:00:41 -06001052 * Opens the settings page
1053 *
1054 * @param {boolean} [forceRerenderDashboard] If this is true, the dashboard settings will be re-rendered
1055 */
1056dtps.settings = function (forceRerenderDashboard) {
1057 //Render dashboard HTML if not already loaded
1058 if (forceRerenderDashboard || ($("#leftDashboardColumn").attr("loaded") !== "true")) {
1059 //Returns dashboard item HTML from a dashboard item array
1060 function dashboardHTML(dashboardArray) {
1061 return dashboardArray.map(dashboardItem => {
1062 return /*html*/`
1063 <div dashboardItem-id="${dashboardItem.id}" style="height: ${dashboardItem.size * 1.7 + 50}px" class="dashboardItem">
1064 <h5>
1065 <i class="fluid-icon">${dashboardItem.icon}</i>
1066 <span>${dashboardItem.name}</span>
1067 </h5>
1068 </div>
1069 `;
1070 }).join("");
1071 }
1072
1073 //Render dashboard items
1074 $("#leftDashboardColumn").html(dashboardHTML(dtps.leftDashboard));
1075 $("#rightDashboardColumn").html(dashboardHTML(dtps.rightDashboard));
1076
1077 //Make dashboard items sortable
1078 $(".dashboardColumn").sortable({
1079 connectWith: ".dashboardColumn",
1080 update: function (e, ui) {
1081 dtps.saveDashboardPrefs();
1082 }
1083 });
1084
1085 //Store loaded state to prevent reloading dashboard items
1086 $("#leftDashboardColumn").attr("loaded", "true");
1087 }
1088
j7940eec2020-12-28 14:00:41 -06001089 fluid.cards('.settingsCard');
1090}
1091
1092/**
jdc6ea0e2022-04-26 16:03:27 -07001093 * Enables the reload warning when the user exists settings
j7940eec2020-12-28 14:00:41 -06001094 */
1095dtps.settingsReloadWarning = function () {
jdc6ea0e2022-04-26 16:03:27 -07001096 dtps.reloadPending = true;
j7940eec2020-12-28 14:00:41 -06001097}
1098
1099/**
j7940eec2020-12-28 14:00:41 -06001100 * Saves dashboard prefrences
1101 */
1102dtps.saveDashboardPrefs = function () {
1103 var dashboardPrefs = [];
1104
1105 //Add dashboard items
1106 for (var i = 0; i < $(".dashboardColumn").children().length; i++) {
1107 //Get HTML item
1108 var child = $($(".dashboardColumn").children()[i]);
1109
1110 //Add item to dashboardPrefs array
1111 dashboardPrefs.push({
1112 id: child.attr("dashboardItem-id"),
1113 side: child.parent().attr("id").includes("left") ? "left" : "right"
1114 });
1115 }
1116
1117 //Save to local storage
1118 window.localStorage.setItem("dtpsDashboardItems", JSON.stringify(dashboardPrefs));
1119
1120 //Reload dashboard items
1121 dtps.loadDashboardPrefs();
1122}
1123
1124/**
1125 * Resets dashboard prefrences
1126 */
1127dtps.resetDashboardPrefs = function () {
1128 //Remove dashboard pref from localStorage
1129 window.localStorage.removeItem("dtpsDashboardItems");
1130
1131 //Reload dashboard items
1132 dtps.loadDashboardPrefs();
1133
1134 //Re-render dashboard
1135 dtps.settings(true);
1136}
1137
1138/**
j7940eec2020-12-28 14:00:41 -06001139 * Loads dashboard prefrences
1140 */
1141dtps.loadDashboardPrefs = function () {
1142 //Define left and right dashboard columns
1143 dtps.leftDashboard = [];
1144 dtps.rightDashboard = [];
1145
1146 //Add items to dashboard columns
1147 if (window.localStorage.dtpsDashboardItems) {
1148 //Add from user prefs
1149
1150 //Parse JSON
1151 var dashboardPref = JSON.parse(window.localStorage.dtpsDashboardItems);
1152
1153 //Generate arrays of dashboard item IDs
1154 var dashboardIDs = dtps.dashboardItems.map(item => item.id);
1155
1156 //Add items to dashboard according to prefs
1157 dashboardPref.forEach(dashboardItemPref => {
1158 if (dashboardIDs.includes(dashboardItemPref.id)) {
1159 //Get item index based on dashboardIDs array
1160 var itemIndex = dashboardIDs.indexOf(dashboardItemPref.id);
1161
1162 //Get item from dtps.dashboardItems array
1163 var dashboardItem = dtps.dashboardItems[itemIndex];
1164
1165 //Add item to dashboard
1166 if (dashboardItemPref.side == "left") {
1167 dtps.leftDashboard.push(dashboardItem);
1168 } else if (dashboardItemPref.side == "right") {
1169 dtps.rightDashboard.push(dashboardItem);
1170 }
1171 }
1172 });
1173 } else {
1174 //Add from defaults
1175 dtps.dashboardItems.forEach(dashboardItem => {
1176 if (dashboardItem.defaultSide == "left") {
1177 dtps.leftDashboard.push(dashboardItem);
1178 } else if (dashboardItem.defaultSide == "right") {
1179 dtps.rightDashboard.push(dashboardItem);
1180 }
1181 })
1182 }
1183}
1184
1185/**
1186 * Renders initial static DTPS HTML
1187 */
1188dtps.render = function () {
1189 //Remove all existing link tags and LMS head content
j2fcf4e52021-03-11 14:37:26 -08001190 if (!dtpsLMS.isDemoLMS) {
1191 $("link:not(.dtpsHeadItem)").remove();
1192 $("head *:not(.dtpsHeadItem)").remove();
1193 }
j7940eec2020-12-28 14:00:41 -06001194
1195 //Set default body classes
1196 $("body").attr("class", "dark showThemeWindows hasSidebar hasNavbar dashboard");
1197
1198 //Set document title and favicon
1199 document.title = "Power+";
1200 jQuery("<link/>", {
1201 rel: "shortcut icon",
1202 type: "image/png",
1203 href: dtps.baseURL + "/favicon.png"
1204 }).appendTo("head");
1205
1206 //Remove existing LMS HTML (excluding DTPS loading screen HTML)
1207 jQuery("body *:not(#dtpsNativeOverlay):not(#dtpsNativeOverlay *)").remove();
1208
1209 //Render HTML
1210 jQuery("body").append(/*html*/`
1211 <div class="sidebar"></div>
1212
1213 <div class="navbar">
1214 <div class="logo">
1215 <img src="${dtps.baseURL + "/icon.svg"}" />
j0f3d7db2026-10-13 04:56:55 +00001216 <h4>Power+</h4>
j7940eec2020-12-28 14:00:41 -06001217 </div>
1218
j2fcf4e52021-03-11 14:37:26 -08001219 ${dtps.unstable && !dtpsLMS.isDemoLMS ? `
j7940eec2020-12-28 14:00:41 -06001220 <div id="dtpsUnstable" class="navitem">
1221 <i style="font-size: 16px;" class="fluid-icon">warning</i>
j0f3d7db2026-10-13 04:56:55 +00001222 <span style="font-weight: bold; font-size: 10px;">THIS IS AN UNOFFICIAL VERSION OF POWER+. USE AT YOUR OWN RISK.</span>
j7940eec2020-12-28 14:00:41 -06001223 </div>
1224 ` : ""}
1225
1226 <div class="items" id="dtpsFixedSearch">
1227 <i class="inputIcon fluid-icon">search</i>
1228 <input id="dtpsMainSearchBox" style="margin: 0px; width: 500px;" type="search" class="inputIcon filled" placeholder="Search" />
1229 </div>
1230
jb39e6d92021-01-30 20:34:04 -08001231 <div class="items" style="float: right;">
j450fbd42022-09-01 11:13:11 -07001232 <a style="display: none;" id="dtpsUnreadCount" target="_blank" href="/conversations" class="navitem">
1233 <i class="fluid-icon">inbox</i>
1234 <span></span>
1235 </a>
jb39e6d92021-01-30 20:34:04 -08001236 <div class="navitem" onclick="dtps.settings();">
1237 <i class="fluid-icon">settings</i>
1238 <span>Settings</span>
j7940eec2020-12-28 14:00:41 -06001239 </div>
1240 </div>
j7940eec2020-12-28 14:00:41 -06001241 </div>
1242
1243 <div id="dtpsSearchResults" class="card acrylicMaterial" style="display: none;">
1244 <h5 id="dtpsSearchStatus"><i class="fluid-icon">search</i> <span>Search</span></h5>
1245 <div id="dtpsSearchData" style="display: none;"></div>
1246 <div id="dtpsSearchInfo">
1247 <p>By defualt, Power+ will search based on the page you're on. You can use the keywords below for more advanced searches:</p>
1248 <div class="grid samesize">
1249 <div class="item">
1250 <p><i class="fluid-icon">library_books</i> type:coursework</p>
1251 <p><i class="fluid-icon">view_module</i> type:module</p>
1252 <p><i class="fluid-icon">assignment</i> type:assignment</p>
1253 <p><i class="fluid-icon">assessment</i> type:grade</p>
1254 <p><i class="fluid-icon">announcement</i> type:announcement</p>
1255 </div>
1256 <div class="item">
1257 <p><i class="fluid-icon">home</i> type:homepage</p>
1258 <p><i class="fluid-icon">insert_drive_file</i> type:page</p>
1259 <p><i class="fluid-icon">forum</i> type:discussion</p>
1260 <p><i class="fluid-icon">people</i> type:person</p>
1261 <div class="divider"></div>
1262 <p><i class="fluid-icon">class</i> class:English</p>
1263 </div>
1264 </div>
1265 </div>
1266 </div>
1267
1268 <div class="headerArea classImage">
1269 <img style="display: none;" />
1270 <div class="content">
1271 <h1 id="headText"><i class="fluid-icon">dashboard</i> <span>Dashboard</span></h1>
1272 <div id="classInfo" style="min-height: 18px;">
1273 <p class="teacher" style="display: none;">
1274 <span class="teacherImage"></span> <span class="teacherName"></span>
1275 </p>
1276 <p onclick="dtps.classHome(dtps.selectedClass);" class="homepage" style="cursor: pointer; display: none;">
1277 <i class="fluid-icon">home</i> <span>Homepage</span>
1278 </p>
j7940eec2020-12-28 14:00:41 -06001279 <p class="contentLabel" style="display: none;">
1280 <i class="fluid-icon"></i> <span></span>
1281 </p>
1282 </div>
1283 <div style="display: none;" id="dtpsTabBar" class="btns">
1284 <button init="true" onclick="if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem('courseworkPref-' + dtps.classes[dtps.selectedClass].id) == 'moduleStream')) { fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id); } else { fluid.screen('stream', dtps.classes[dtps.selectedClass].id); }" class="btn stream">
1285 <i class="fluid-icon">library_books</i>
1286 Coursework
1287 </button>
1288 <button init="true" onclick="fluid.screen('people', dtps.classes[dtps.selectedClass].id);" class="btn people">
1289 <i class="fluid-icon">people</i>
1290 People
1291 </button>
1292 <button init="true" onclick="fluid.screen('discussions', dtps.classes[dtps.selectedClass].id);" class="btn discuss">
1293 <i class="fluid-icon">forum</i>
1294 Discussions
1295 </button>
1296 <button init="true" onclick="fluid.screen('pages', dtps.classes[dtps.selectedClass].id);" class="btn pages">
1297 <i class="fluid-icon">insert_drive_file</i>
1298 Pages
1299 </button>
1300 <button init="true" onclick="fluid.screen('gradebook', dtps.classes[dtps.selectedClass].id);" class="btn grades">
1301 <i class="fluid-icon">assessment</i>
jdc6ea0e2022-04-26 16:03:27 -07001302 Gradebook
j7940eec2020-12-28 14:00:41 -06001303 </button>
1304 </div>
1305 </div>
1306 </div>
1307
1308 <!-- Class content area -->
1309 <div class="classContent">
1310 <div class="spinner"></div>
1311 </div>
1312
1313 <!-- Settings card (its inner HTML is added later) -->
1314 <div style="height: 100%; overflow: auto !important;" class="card withnav focus close container settingsCard"></div>
1315
j0f3d7db2026-10-13 04:56:55 +00001316 <!-- Changelog card (The changelog is removed, but this is also used for the firstrun dialog) -->
j7940eec2020-12-28 14:00:41 -06001317 <div style="border-radius: 30px;" class="card focus changelog close container">
1318 <i onclick="fluid.cards.close('.card.changelog')" class="fluid-icon close">close</i>
1319 <h3>What's new in Power+</h3>
1320 <h5>Loading...</h5>
1321 </div>
1322
1323 <!-- General details card for assignments, outcomes, class info, etc. -->
1324 <div style="border-radius: 30px;" class="card focus details close container">
1325 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
1326 <p>An error occured</p>
1327 </div>
1328
1329 <!-- General iFrame card (with white background) -->
1330 <div style="border-radius: 30px; top: 50px; background-color: white; color: black;" class="card focus close iFrameCard container">
1331 <i style="color: black !important;" onclick="fluid.cards.close('.card.iFrameCard'); $('#CardIFrame').attr('src', '');" class="fluid-icon close">close</i>
1332 <br /><br />
1333 <iframe style="width: 100%; height: calc(100vh - 175px); border: none;" id="CardIFrame"></iframe>
1334 </div>
1335 `);
1336
1337 $("#dtpsMainSearchBox").on("focus", function () {
1338 $("#dtpsSearchResults").show();
1339 });
1340
1341 $("#dtpsMainSearchBox").on("blur", function () {
1342 $("#dtpsSearchResults").hide();
1343 });
1344
1345 $("#dtpsMainSearchBox").on("input", function () {
1346 dtps.setSearchBox();
1347 });
1348
1349 $(document).on("keydown", "#dtpsMainSearchBox", function (e) {
1350 if (e.key == "Enter") {
1351 //Validate input and tags
1352 var term = $("#dtpsMainSearchBox").val().replace(/(type|class):[a-z]*/gi, "").trim();
1353 if ($("#dtpsMainSearchBox").attr("data-search-type") && $("#dtpsMainSearchBox").attr("data-dtps-course")) {
jd4fc5d82020-12-28 19:38:41 -06001354 fluid.screen("search", {
1355 term: term,
1356 type: $("#dtpsMainSearchBox").attr("data-search-type"),
1357 course: $("#dtpsMainSearchBox").attr("data-dtps-course"),
1358 ctxType: $("#dtpsMainSearchBox").attr("data-ctx-type"),
1359 ctxCourse: $("#dtpsMainSearchBox").attr("data-ctx-course")
1360 });
j7940eec2020-12-28 14:00:41 -06001361 $("#dtpsMainSearchBox").blur();
1362 }
1363 }
1364 });
1365}
1366
1367/**
1368 * Sets the search box text based on the current page or keywords
1369 */
1370dtps.setSearchBox = function () {
1371 var value = $("#dtpsMainSearchBox").val() || "";
1372
1373 var type = null;
1374 var course = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
1375 var icon = null;
1376 var error = false;
1377 var autoType = null;
1378 var autoCourse = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
1379
1380 //Get automatic type from selected content
1381 if (dtps.selectedContent == "people") type = "people";
1382 if (dtps.selectedContent == "discuss") type = "discussions";
1383 if (dtps.selectedContent == "pages") type = "pages";
1384 if (dtps.selectedContent == "grades") type = "grades";
1385 if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) type = "coursework";
jb39e6d92021-01-30 20:34:04 -08001386 autoType = type;
1387
j7940eec2020-12-28 14:00:41 -06001388 //Reuse auto type if on search
1389 if (dtps.selectedClass == "search") {
1390 type = $("#dtpsMainSearchBox").attr("data-ctx-type");
1391 course = $("#dtpsMainSearchBox").attr("data-ctx-course");
1392 if (!isNaN(Number(course))) course = dtps.classes[course];
1393 }
1394
1395 //Check for type override from search box
1396 if (value.split(" ").includes("type:coursework")) type = "coursework";
1397 if (value.split(" ").includes("type:homepage")) type = "homepages";
1398 if (value.split(" ").includes("type:page")) type = "pages";
1399 if (value.split(" ").includes("type:discussion")) type = "discussions";
1400 if (value.split(" ").includes("type:grade")) type = "grades";
1401 if (value.split(" ").includes("type:person")) type = "people";
1402 if (value.split(" ").includes("type:assignment")) type = "assignments";
1403 if (value.split(" ").includes("type:module")) type = "modules";
1404 if (value.split(" ").includes("type:announcement")) type = "announcements";
1405 if (value.split(" ").includes("type:all")) type = "everything";
1406
1407 //Get icon from final type
1408 if (type == "coursework") icon = "library_books";
1409 if (type == "people") icon = "people";
1410 if (type == "discussions") icon = "forum";
1411 if (type == "pages") icon = "insert_drive_file";
1412 if (type == "grades") icon = "assessment";
1413 if (type == "assignments") icon = "assignment";
1414 if (type == "modules") icon = "view_module";
1415 if (type == "homepages") icon = "home";
1416 if (type == "announcements") icon = "announcement";
1417 if (type == "everything") icon = "warning";
1418
1419 //Check for course override from search box
1420 if (value.includes("class:")) {
1421 var partialSubject = value.split("class:")[1].split(" ")[0].toLowerCase();
1422 if (partialSubject == "all") {
1423 course = "all";
1424 } else if (partialSubject) {
1425 dtps.classes.forEach(c => {
1426 if (c.subject.toLowerCase().includes(partialSubject)) {
1427 course = c;
1428 }
1429 });
1430 }
1431 }
1432
1433 //Check if the course supports the type
1434 if ((course !== "dash") && (course !== "all")) {
1435 if ((type == "pages") && !course.pages) error = true;
1436 if ((type == "discussions") && !course.discussions) error = true;
1437 if ((type == "modules") && !course.modules) error = true;
1438 if ((type == "homepages") && !course.homepage) error = true;
1439 if ((type == "people") && !course.people) error = true;
1440 }
1441
1442 if ((course == "dash") || (course == "all")) {
1443 $("#dtpsSearchStatus i").text(icon);
1444 $("#dtpsSearchStatus span").text("Search " + (type == "everything" ? type : "all " + type));
1445 $("#dtpsMainSearchBox").attr("placeholder", "Search " + (type == "everything" ? type : "all " + type));
1446 $("#dtpsMainSearchBox").attr("data-dtps-course", "all");
1447 $("#dtpsMainSearchBox").attr("data-search-type", type);
1448 } else if (error) {
1449 $("#dtpsSearchStatus i").text("error");
j6ca9c7e2026-10-13 20:39:55 +00001450 $("#dtpsSearchStatus span").html(`Cannot search for ${DOMPurify.sanitize(type)} in <b style="color: ${dtps.escapeAttr(course.color)};">${DOMPurify.sanitize(course.subject)}</b>`);
j7940eec2020-12-28 14:00:41 -06001451 $("#dtpsMainSearchBox").attr("placeholder", "Cannot search for " + type + " in " + course.subject);
1452 $("#dtpsMainSearchBox").attr("data-dtps-course", "");
1453 $("#dtpsMainSearchBox").attr("data-search-type", "");
1454 } else if (course || true) {
1455 $("#dtpsSearchStatus i").text(icon);
j6ca9c7e2026-10-13 20:39:55 +00001456 $("#dtpsSearchStatus span").html(`Search ${DOMPurify.sanitize(type)} in <b style="color: ${dtps.escapeAttr(course.color)};">${DOMPurify.sanitize(course.subject)}</b>`);
j7940eec2020-12-28 14:00:41 -06001457 $("#dtpsMainSearchBox").attr("placeholder", "Search " + type + " in " + course.subject);
1458 $("#dtpsMainSearchBox").attr("data-dtps-course", course.num);
1459 $("#dtpsMainSearchBox").attr("data-search-type", type);
1460 }
1461
1462 //Set auto type
1463 if (dtps.selectedClass !== "search") {
1464 $("#dtpsMainSearchBox").attr("data-ctx-type", autoType);
1465 $("#dtpsMainSearchBox").attr("data-ctx-course", autoCourse == "dash" ? "dash" : autoCourse.num);
1466 }
1467}
1468
1469/**
1470 * Renders basic content after the user has been loaded
1471 */
1472dtps.renderLite = function () {
1473 //Add hideGrades body class if enabled and preference listener
1474 if (fluid.get("pref-hideGrades") == "true") { jQuery('body').addClass('hidegrades'); }
1475 document.addEventListener("pref-hideGrades", function (e) {
1476 if ((e.detail == "true") || (e.detail == true)) {
1477 //hideGrades has been enabled, add class to body to hide grades via CSS
1478 jQuery('body').addClass('hidegrades');
1479 } else {
1480 //hideGrades has been disabled, remove class from body to show grades
1481 jQuery('body').removeClass('hidegrades');
1482 }
1483 });
1484
j5bcb1122021-05-25 12:53:21 -07001485 //Add alternateFont body class if enabled and preference listener
1486 if (fluid.get("pref-alternateFont") == "true") { jQuery('body').addClass('alternateFont'); }
1487 document.addEventListener("pref-alternateFont", function (e) {
1488 if ((e.detail == "true") || (e.detail == true)) {
1489 //alternateFont has been enabled, add class to body to change font
1490 jQuery('body').addClass('alternateFont');
1491 } else {
1492 //alternateFont has been disabled, remove class from body to revert font change
1493 jQuery('body').removeClass('alternateFont');
1494 }
1495 });
1496
jdc6ea0e2022-04-26 16:03:27 -07001497 /**
1498 * A callback for blocking Fluid UI card closes
1499 */
1500 dtps.closeScreen = function () {
1501 if (dtps.reloadPending) {
1502 jQuery("body").addClass("requiredModal");
1503 fluid.alert("Reload required", "Some of the settings you've changed require a reload to take effect.", "refresh", [
1504 { name: "Reload Power+", icon: "refresh", action: () => window.location.reload() }
1505 ], "var(--theme)");
1506 return true;
1507 }
1508
1509 return false;
1510 }
1511
j7940eec2020-12-28 14:00:41 -06001512 //Render settings card
1513 var baseHost = new URL(dtps.baseURL).hostname;
1514 jQuery(".card.settingsCard").html(/*html*/`
1515 <i onclick="fluid.cards.close('.card.settingsCard')" class="fluid-icon close">close</i>
1516
1517 <div style="position: fixed; height: calc(100% - 100px);" class="sidenav">
1518 <div class="title">
1519 <img src="${dtps.baseURL + "/icon.svg"}" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
1520 <div style="vertical-align: middle; display: inline-block;">
1521 <h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+</h5>
j5e67d8e2022-11-08 22:55:04 -08001522 <p>
1523 <span style="vertical-align: middle;">${dtps.readableVer}</span>
j5e67d8e2022-11-08 22:55:04 -08001524 </p>
1525 ${(dtps.unstable ? `<p style="font-size: 12px; color: red; margin-top: 6px;">UNSTABLE</p>` : "")}
j7940eec2020-12-28 14:00:41 -06001526 </div>
1527 </div>
1528
j423ed602021-06-01 21:36:17 -07001529 <div onclick="$('.abtpage').hide();$('.abtpage.settings').show();" class="item active">
j7940eec2020-12-28 14:00:41 -06001530 <i class="fluid-icon">settings</i> Settings
1531 </div>
j423ed602021-06-01 21:36:17 -07001532 <div onclick="$('.abtpage').hide();$('.abtpage.theme').show();" class="item">
jb39e6d92021-01-30 20:34:04 -08001533 <i class="fluid-icon">format_paint</i> Theme
1534 </div>
j423ed602021-06-01 21:36:17 -07001535 <div onclick="$('.abtpage').hide();$('.abtpage.dashboard').show();" class="item">
j7940eec2020-12-28 14:00:41 -06001536 <i class="fluid-icon">dashboard</i> Dashboard
1537 </div>
1538 ${dtps.env == "dev" ? /*html*/`
j423ed602021-06-01 21:36:17 -07001539 <div onclick="$('.abtpage').hide();$('.abtpage.debugging').show();" class="item">
j7940eec2020-12-28 14:00:41 -06001540 <i class="fluid-icon">bug_report</i> Debugging
1541 </div>
j7940eec2020-12-28 14:00:41 -06001542 ` : ``}
j423ed602021-06-01 21:36:17 -07001543 <div onclick="$('.abtpage').hide();$('.abtpage.about').show();" class="item abt">
j7940eec2020-12-28 14:00:41 -06001544 <i class="fluid-icon">info</i> About
1545 </div>
1546 </div>
1547
1548 <div style="min-height: 100%" class="content">
1549 <div class="abtpage settings">
1550 <h5><b>Settings</b></h5>
j0f3d7db2026-10-13 04:56:55 +00001551
1552 ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of October 2026, all d.tech-specific features, including CBL grade calculation, have been removed from Power+.</b></p>` : ``}
j7adec892020-12-31 10:56:28 -06001553
j7940eec2020-12-28 14:00:41 -06001554 <br />
1555 <p>Sidebar</p>
1556
1557 <div onclick="fluid.set('pref-hideGrades');" class="switch pref-hideGrades"><span class="head"></span></div>
1558 <div class="label"><i class="fluid-icon">visibility_off</i> Hide class grades</div>
1559
j7940eec2020-12-28 14:00:41 -06001560 <br /><br />
1561 <p>Classes</p>
1562
1563 <div onclick="fluid.set('pref-fullNames'); dtps.settingsReloadWarning();" class="switch pref-fullNames"><span class="head"></span></div>
1564 <div class="label"><i class="fluid-icon">title</i> Show full class names</div>
1565
1566 <br /><br />
j29812c42022-04-27 15:41:40 -07001567 <div onclick="fluid.set('pref-hideClassImages'); fluid.screen();" class="switch pref-hideClassImages"><span class="head"></span></div>
j7940eec2020-12-28 14:00:41 -06001568 <div class="label"><i class="fluid-icon">image</i> Hide class images</div>
1569
j608526f2022-04-26 20:32:47 -07001570 ${dtpsLMS.shortName === "Canvas" ? /*html*/`
1571 <br /><br />
1572 <div onclick="fluid.set('pref-showAllClasses'); dtps.settingsReloadWarning();" class="switch pref-showAllClasses"><span class="head"></span></div>
jd88b8432022-06-12 15:37:35 -07001573 <div class="label"><i class="fluid-icon">visibility</i> Show all published classes, including those which may have ended</div>
j608526f2022-04-26 20:32:47 -07001574 ` : ""}
1575
1576 <br /><br />
1577 <p>Assignments</p>
1578
j29812c42022-04-27 15:41:40 -07001579 <div onclick="fluid.set('pref-unusualDueDates'); fluid.screen();" class="switch pref-unusualDueDates active"><span class="head"></span></div>
j608526f2022-04-26 20:32:47 -07001580 <div class="label"><i class="fluid-icon">highlight</i> Highlight outlying due dates</div>
1581
j0f3d7db2026-10-13 04:56:55 +00001582 <div id="dtpsPrereleaseTesting" style="${window.localStorage.prereleaseEnabled || (dtps.env == "dev") ? "" : "display: none;"}">
j7940eec2020-12-28 14:00:41 -06001583 <br /><br />
j0f3d7db2026-10-13 04:56:55 +00001584 <p>Release mode</p>
j7940eec2020-12-28 14:00:41 -06001585
1586 <div>
1587 <div class="btns row small">
1588 <button
1589 onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
j0f3d7db2026-10-13 04:56:55 +00001590 class="btn ${window.localStorage.dtpsLoaderPref !== "local" ? "active" : ""}">
j7940eec2020-12-28 14:00:41 -06001591 <i class="fluid-icon">label</i> Production
1592 </button>
j7940eec2020-12-28 14:00:41 -06001593 <button
1594 onclick="window.localStorage.setItem('dtpsLoaderPref', 'local')"
1595 class="btn ${window.localStorage.dtpsLoaderPref == "local" ? "active" : ""}">
1596 <i class="fluid-icon">developer_board</i> Local
1597 </button>
1598 </div>
1599 </div>
1600 </div>
1601
1602 </div>
1603
jb39e6d92021-01-30 20:34:04 -08001604 <div style="display: none;" class="abtpage theme">
1605 <h5><b>Theme</b></h5>
1606 <br />
1607 <div class="themeSelectionUI flat"></div>
1608 </div>
j7940eec2020-12-28 14:00:41 -06001609
j7940eec2020-12-28 14:00:41 -06001610 <div style="display: none;" class="abtpage dashboard">
1611 <h5><b>Dashboard</b></h5>
1612 <p>You can rearrange the items shown on the dashboard by dragging them below. You might have to reload Power+ for changes to take effect.</p>
1613
1614 <button onclick="dtps.resetDashboardPrefs();" class="btn small"><i class="fluid-icon">refresh</i> Reset dashboard layout</button>
1615
1616 <br />
1617
1618 <div id="leftDashboardColumn" class="dashboardColumn"></div>
1619
1620 <div id="rightDashboardColumn" class="dashboardColumn"></div>
1621 </div>
1622
1623 ${dtps.env == "dev" ? /*html*/`
1624 <div style="display: none;" class="abtpage debugging">
1625 <h5><b>Debugging</b></h5>
jd88b8432022-06-12 15:37:35 -07001626 <p>These settings are for development purposes only and might break Power+. Use at your own risk.</p>
j7940eec2020-12-28 14:00:41 -06001627
1628 <div>
1629 <button onclick="dtps.firstrun()" class="btn small"><i class="fluid-icon">web_asset</i> Show firstrun screen</button>
1630 </div>
1631
1632 <br /><br />
1633
1634 <h5>Release configuration</h5>
1635
j0f3d7db2026-10-13 04:56:55 +00001636 <button onclick="['dtpsLoaderPref', 'prereleaseEnabled', 'dtpsLMSOverride'].forEach(k => window.localStorage.removeItem(k)); window.location.reload();" class="btn small"><i class="fluid-icon">cancel</i> Clear release configurations</button>
j7940eec2020-12-28 14:00:41 -06001637 <br /><br />
1638
1639 <div>
j6ca9c7e2026-10-13 20:39:55 +00001640 <input id="dtpsLMSOverride" value="${dtps.escapeAttr(window.localStorage.dtpsLMSOverride || "")}" placeholder="LMS override" />
j7940eec2020-12-28 14:00:41 -06001641 <button class="btn small" onclick="window.localStorage.setItem('dtpsLMSOverride', $('#dtpsLMSOverride').val())"><i class="fluid-icon">save</i> Save</button>
1642 </div>
j7940eec2020-12-28 14:00:41 -06001643 </div>
1644 ` : ``}
1645
1646 <div style="display: none;" class="abtpage about">
1647 <h5><b>About</b></h5>
1648
1649 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1650 <img src="${dtps.baseURL + "/icon.svg"}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px;" />
1651
1652 <div style="display: inline-block; vertical-align: middle;">
j0f3d7db2026-10-13 04:56:55 +00001653 <h4 id="dtpsAboutName" style="font-weight: bold; font-size: 32px; margin-bottom: 0px; user-select: none;">Power+</h4>
j7940eec2020-12-28 14:00:41 -06001654 <div style="font-size: 16px; margin-top: 5px;">
1655 ${dtps.readableVer}
1656 <div style="display: inline-block;margin: 0px 5px;font-size: 12px;">${baseHost !== "powerplus.app" ? `(from ${baseHost})` : ""}</div>
1657 </div>
1658 </div>
1659
j0f3d7db2026-10-13 04:56:55 +00001660 <div style="margin-top: 15px; margin-bottom: 7px;">
1661 <a style="color: var(--lightText); margin: 0px 5px;" href="https://jottocraft.com/contact"><i class="fluid-icon" style="vertical-align: middle">email</i> Contact me</a>
j7940eec2020-12-28 14:00:41 -06001662 </div>
1663 </div>
1664
1665 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1666 <div style="margin-top: 12px;">
j6ca9c7e2026-10-13 20:39:55 +00001667 <img src="${dtps.escapeAttr(dtps.user.photoURL)}" style="height: 50px; margin-right: 10px; vertical-align: middle; border-radius: 50%;" />
j7940eec2020-12-28 14:00:41 -06001668
1669 <div style="display: inline-block; vertical-align: middle;">
j6ca9c7e2026-10-13 20:39:55 +00001670 <h4 style="font-weight: bold; font-size: 32px; margin: 0px;">${DOMPurify.sanitize(dtps.user.name)} <span style="font-size: 12px; line-height: 0px;">${DOMPurify.sanitize(dtps.user.id)}</span></h4>
j7940eec2020-12-28 14:00:41 -06001671 </div>
1672 </div>
1673
1674 <div style="margin-top: 15px; margin-bottom: 7px;">
1675 <a style="color: var(--lightText); margin: 0px 5px;" href="/logout"><i class="fluid-icon" style="vertical-align: middle">exit_to_app</i> Logout</a>
1676 </div>
1677 </div>
1678
1679 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
j6ca9c7e2026-10-13 20:39:55 +00001680 <img src="${dtps.escapeAttr(dtpsLMS.logo)}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%;" />
j7940eec2020-12-28 14:00:41 -06001681
1682 <div style="display: inline-block; vertical-align: middle;">
j6ca9c7e2026-10-13 20:39:55 +00001683 <h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${DOMPurify.sanitize(dtpsLMS.name)}</h4>
j7940eec2020-12-28 14:00:41 -06001684 ${dtpsLMS.description ? `
j6ca9c7e2026-10-13 20:39:55 +00001685 <div style="font-size: 16px; margin-top: 5px;">${DOMPurify.sanitize(dtpsLMS.description)}</div>
j7940eec2020-12-28 14:00:41 -06001686 ` : ``}
1687 </div>
1688
1689 <div style="margin-top: 15px; margin-bottom: 7px;">
j6ca9c7e2026-10-13 20:39:55 +00001690 <a style="color: var(--lightText); margin: 0px 5px;" href="${dtps.escapeAttr(dtpsLMS.source)}"><i class="fluid-icon" style="vertical-align: middle">code</i> LMS integration source code</a>
j7940eec2020-12-28 14:00:41 -06001691 </div>
1692 </div>
1693
1694 <div class="card advancedOptions" style="padding: 8px 16px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px; ${dtps.env == "dev" ? `` : `display: none;`}">
1695 <div style="display: inline-block; vertical-align: middle;">
1696 <h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options</h4>
1697 </div>
1698
j5bcb1122021-05-25 12:53:21 -07001699 <br /><br />
1700 <div onclick="fluid.set('pref-alternateFont')" class="switch pref-alternateFont"><span class="head"></span></div>
1701 <div class="label"><i class="fluid-icon">font_download</i> Use Alternate Font</div>
1702 <br /><br />
1703
j7940eec2020-12-28 14:00:41 -06001704 <div style="margin-top: 15px; margin-bottom: 7px;">
1705 <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="dtps.clearData();"><i class="fluid-icon" style="vertical-align: middle">refresh</i> Reset Power+</a>
j0f3d7db2026-10-13 04:56:55 +00001706 <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="if (confirm('Only enable Local Development Mode if you are modifying the Power+ source code on your device. Proceeding could allow unauthorized scripts to load, which can cause security issues. Are you sure you want to continue?')) {window.localStorage.prereleaseEnabled = 'true'; $('#dtpsPrereleaseTesting').show(); alert('Local Development Mode can be enabled by going to Settings -> Release mode');}"><i class="fluid-icon" style="vertical-align: middle">code</i> Allow Local Development Mode</a>
j7940eec2020-12-28 14:00:41 -06001707 </div>
1708 </div>
1709
1710 <br />
1711 ${dtps.env == "dev" ? `` : `<p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options</p>`}
1712
1713 <div style="text-align: center; padding: 50px 0px;">
jdc6ea0e2022-04-26 16:03:27 -07001714 <a href="https://jottocraft.com">
1715 <img style="height: 38px; margin-right: 10px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
1716 <h5 style="display: inline-block; vertical-align: middle; color: var(--text);">jottocraft</h5>
1717 </a>
j0f3d7db2026-10-13 04:56:55 +00001718 <p>Copyright (c) jottocraft 2018-2026. Power+ is <a href="https://jottocraft.com/oss">open source</a>.
j7940eec2020-12-28 14:00:41 -06001719 </div>
1720 </div>
1721 </div>
1722 `);
1723
j7940eec2020-12-28 14:00:41 -06001724 //Load Fluid UI
1725 fluid.onLoad();
1726
1727 //Render sidebar
1728 dtps.showClasses();
1729
1730 //Remove loading screen styles
1731 jQuery("#dtpsNativeOverlay style").remove();
1732
1733 //Fade out loading screen
1734 jQuery("#dtpsNativeOverlay").css("opacity", "0");
1735
1736 //Remove loading screen after the animation is complete
1737 setTimeout(() => jQuery("#dtpsNativeOverlay").remove(), 200);
1738}
1739
1740//Start loading DTPS
1741dtps.init();
1742
1743//LMS Integration documentation -------------------------------------------------------------------------------------
1744
1745/**
1746 * @namespace dtpsLMS
1747 * @description Global DTPS LMS integration object. All LMS-related tasks, such as fetching data, are handled by this object. This is always loaded first.
1748 * @global
1749 * @property {string} name Full LMS name
1750 * @property {string} [shortName] Short LMS name
1751 * @property {string} legalName Legal name (or names) to show in the "Welcome to Power+" disclaimer
1752 * @property {string} [description] A short description of the LMS integration provided
1753 * @property {string} logo LMS logo image URL
1754 * @property {string} url URL to the LMS' website
1755 * @property {string} source URL to the LMS integration's source code
j450fbd42022-09-01 11:13:11 -07001756 * @property {string} [inboxURL] URL to the LMS inbox. Required only if dtpsLMS.fetchUnreadMessageCount count is implemented
j7940eec2020-12-28 14:00:41 -06001757 * @property {boolean} [dtech] True if this LMS is d.tech
j7940eec2020-12-28 14:00:41 -06001758 */
1759
1760/**
1761 * @name dtpsLMS.fetchUser
1762 * @description [REQUIRED] Fetches data for the current user from the LMS. If the user is not signed in, reject with an object that looks like {action: "login", redirectURL: "..."} to login the user.
1763 * @kind function
1764 * @return {Promise<User>} A promise which resolves to a User object
1765 */
1766
1767/**
j450fbd42022-09-01 11:13:11 -07001768 * @name dtpsLMS.fetchUnreadMessageCount
1769 * @description [OPTIONAL] Fetches the unread message count for the current user
1770 * @kind function
1771 * @return {Promise<string>} A promise which resolves to a string depicting the count of unread messages
1772 */
1773
1774/**
j7940eec2020-12-28 14:00:41 -06001775* @name dtpsLMS.fetchClasses
1776* @description [REQUIRED] Fetches class data from the LMS
1777* @kind function
1778* @param {string} userID The user ID to fetch classes for
1779* @return {Promise<Class[]>} A promise which resolves to an array of Class objects
1780*/
1781
1782/**
1783* @name dtpsLMS.fetchAssignments
1784* @description [REQUIRED] Fetches assignment data for a course from the LMS
1785* @kind function
1786* @param {string} userID The user ID to fetch assignments for
1787* @param {string} classID The class ID to fetch assignments for
1788* @return {Promise<Assignment[]>} A promise which resolves to an array of Assignment objects
1789*/
1790
1791/**
1792* @name dtpsLMS.fetchModules
1793* @description [OPTIONAL] Fetches module data for a course from the LMS
1794* @kind function
1795* @param {string} userID The user ID to fetch modules for
1796* @param {string} classID The class ID to fetch modules for
1797* @return {Promise<Module[]>} A promise which resolves to an array of Module objects
1798*/
1799
1800/**
1801* @name dtpsLMS.collapseModule
1802* @description [OPTIONAL] Collapses a module in the LMS
1803* @kind function
1804* @param {string} classID The ID of the class
1805* @param {string} moduleID The ID of the module to collapse
1806* @param {boolean} collapsed True if the module is collapsed, false otherwise
1807* @return {Promise} A promise which resolves when the operation is completed
1808*/
1809
1810/**
1811* @name dtpsLMS.collapseAllModules
1812* @description [OPTIONAL] Collapses all modules in the LMS
1813* @kind function
1814* @param {string} classID The ID of the class
1815* @param {boolean} collapsed True if all modules should be collapsed, false otherwise
1816* @return {Promise} A promise which resolves when the operation is completed
1817*/
1818
1819/**
1820* @name dtpsLMS.fetchAnnouncements
1821* @description [OPTIONAL] Fetches recent announcements for a course from the LMS
1822* @kind function
1823* @param {string} classID The class ID to fetch announcements for
1824* @return {Promise<Announcement[]>} A promise which resolves to an array of Announcement objects
1825*/
1826
1827/**
j7940eec2020-12-28 14:00:41 -06001828* @name dtpsLMS.fetchHomepage
1829* @description [OPTIONAL] Fetches homepage HTML for a course from the LMS
1830* @kind function
1831* @param {string} classID The class ID to get the homepage for
1832* @return {Promise<string>} A promise which resolves to the HTML for the class homepage
1833*/
1834
1835/**
1836* @name dtpsLMS.fetchUsers
1837* @description [OPTIONAL] Fetches the users for a course from the LMS
1838* @kind function
1839* @param {string} classID The class ID to fetch users for
1840* @return {Promise<ClassSection[]>} A promise which resolves to an array of sections in this class
1841*/
1842
1843/**
1844* @name dtpsLMS.fetchDiscussionThreads
1845* @description [OPTIONAL] Fetches discussion threads for a course from the LMS
1846* @kind function
1847* @param {string} classID The class ID to fetch discussion threads for
1848* @return {Promise<PartialDiscussionThread[]>} A promise which resolves to an array of partial Discussion Thread objects
1849*/
1850
1851/**
1852* @name dtpsLMS.fetchDiscussionPosts
1853* @description [REQUIRED IF dtpsLMS.fetchDiscussionThreads IS IMPLEMENTED] Fetches discussion posts in a thread from the LMS
1854* @kind function
1855* @param {string} classID The class ID to fetch discussion posts for
1856* @param {string} threadID The discussion thread ID to fetch discussion posts for
1857* @return {Promise<DiscussionThread>} A promise which resolves to a full discussion thread object
1858*/
1859
1860/**
1861* @name dtpsLMS.fetchPages
1862* @description [OPTIONAL] Fetches pages for a course from the LMS
1863* @kind function
1864* @param {string} classID The class ID to fetch pages for
1865* @return {Promise<PartialPage[]>} A promise which resolves to an array of partial page objects
1866*/
1867
1868/**
1869* @name dtpsLMS.fetchPageContent
1870* @description [REQUIRED IF dtpsLMS.fetchPages IS IMPLEMENTED] Fetches content for a page from the LMS
1871* @kind function
1872* @param {string} classID The class ID to fetch page content for
1873* @param {string} pageID The page ID to fetch page content for
1874* @return {Promise<Page>} A promise which resolves to a full DTPS page object
1875*/
1876
1877/**
j7940eec2020-12-28 14:00:41 -06001878* @name dtpsLMS.isUsualDueDate
1879* @description [OPTIONAL, INSTITUTION ONLY] This function returns true if the due date provided is usual/expected and false if the due date is unusual/expected. If the due date is unusual, it is shown in bold in the UI. For institutions where there is a pattern/standard for due dates between classes.
1880* @kind function
1881* @param {Date} date The due date to check
1882* @return {boolean} True if the due date is usual, false if the due date is unusual/unexpected.
1883*/
1884
1885/**
1886* @name dtpsLMS.updateAssignments
1887* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override assignment data returned by the LMS.
1888* @kind function
1889* @param {Assignment[]} assignments Original assignments array
jdc6ea0e2022-04-26 16:03:27 -07001890* @param {Class} course The class that the assignment is in
j7940eec2020-12-28 14:00:41 -06001891* @return {Promise<Assignment[]>} A promise that resolves to the updated assignments array
1892*/
1893
1894/**
1895* @name dtpsLMS.updateClasses
1896* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override class data returned by the LMS.
1897* @kind function
1898* @param {Class[]} classes Original classes array
1899* @return {Promise<Class[]>} A promise that resolves to the updated classes array
1900*/
1901
1902//Type definitions -------------------------------------------------------------------------------------
1903
1904/**
1905 * @typedef {string|Date} Date
1906 * @description A date string recognized by {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse|Date.parse} or an actual {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date} object
1907 */
1908
1909/**
1910 * @typedef {Object} User
1911 * @description Defines user objects in DTPS
1912 * @property {string} name User name
1913 * @property {string} id User ID
1914 * @property {string} photoURL User photo URL
1915 * @property {string} url [ONLY FOR DTPSLMS.FETCHUSERS] The URL to this user's profile. Only used when displaying users in the people tab.
1916 * @property {User[]} [children] [ONLY FOR DTPS.USER] Array of child users. If this is defined, the user is treated as a parent account. Sub-children are not allowed.
1917 * @property {boolean} parent [ONLY FOR DTPS.USER] Automatically managed by DTPS. True if the user is a parent account.
1918 */
1919
1920/**
1921* @typedef {Object} Class
1922* @description Defines class objects in DTPS
1923* @property {string} name Name of the class
1924* @property {string} id Class ID used by Power+
1925* @property {string} lmsID Class ID used for LMS API calls
1926* @property {string} userID The ID of the user this class is associated with (from the parameter of dtpsLMS.fetchClasses)
1927* @property {number} num Index of the class in the dtps.classes array
1928* @property {string} subject Class subject
j29812c42022-04-27 15:41:40 -07001929* @property {number[]} usualDueRange The range of usual due dates for this course [min,max]. Anything outside this range is considered unusual and highlighted if enabled.
j7940eec2020-12-28 14:00:41 -06001930* @property {ClassSection[]|boolean} [people] Users in this class. True if the class supports the "People" tab, but not yet loaded. If this is true dtpsLMS.fetchUsers must be implemented.
1931* @property {string} [icon] The icon to show with this class
1932* @property {string} [group] The name of the group that this class is in
1933* @property {number|string} [period] The period or section the user has this class at
j2566c4e2021-10-01 15:25:49 -07001934* @property {Date} [startDate] The start date for this course. Only used internally for filtering out stale courses.
1935* @property {Date} [endDate] The end date for this course. Only used internally for filtering out stale courses.
1936* @property {Date} [termStartDate] The start date for the term this course is in. Only used internally for filtering out stale courses.
1937* @property {Date} [termEndDate] The end date for the term this course is in. Only used internally for filtering out stale courses.
j7940eec2020-12-28 14:00:41 -06001938* @property {Assignment[]} assignments Class assignments. Assume assignments are still loading if this is undefined. The class has no assignments if this is an empty array. Loaded in dtps.init.
1939* @property {Module[]|boolean} [modules] Class modules. Assume this class supports the modules feature, but is not yet loaded, if this is true and that the class has no modules if this is an empty array. For LMSs that do not support modules, either keep it undefined or set it to false.
1940* @property {DiscussionThread[]|boolean} [discussions] Class discussion threads. Assume this class supports discussions, but not yet loaded, if this is true and that the class has no threads if this is an empty array. For LMSs that do not support discussions, either keep it undefined or set it to false.
1941* @property {Page[]|boolean} [pages] Class pages. Assume this class supports the pages feature, but not yet loaded, if true and that the class has no pages if this is an empty array. For LMSs that do not support pages, either keep it undefined or set it to false.
1942* @property {string} [newDiscussionThreadURL] A URL the user can visit to create a new discussion thread in this class
1943* @property {boolean} [homepage] True if the class has a homepage. If a class has a homepage, dtpsLMS.fetchHomepage must be implemented.
1944* @property {string} [term] Class term
1945* @property {string} [color] Class color
jb39e6d92021-01-30 20:34:04 -08001946* @property {number} [grade] Current percentage grade in the class (a number from 0 to 100)
j7940eec2020-12-28 14:00:41 -06001947* @property {string} [letter] Current letter grade in the class
j7940eec2020-12-28 14:00:41 -06001948* @property {string} [image] URL to the class background image
1949* @property {User} [teacher] Class teacher. If the class has multiple teachers, this is the primary teacher.
1950* @property {boolean} [hasGradebook] Automatically managed by DTPS. True if the class should show the gradebook tab.
j7940eec2020-12-28 14:00:41 -06001951*/