| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1 | /**
|
| 2 | * @file DTPS pages & discussion functions
|
| 3 | * @author jottocraft
|
| 4 | *
|
| j | 6e1a7bf | 2026-10-13 03:37:04 +0000 | [diff] [blame] | 5 | * @copyright Copyright (c) jottocraft 2020
|
| j | 40db027 | 2022-01-14 15:18:29 -0800 | [diff] [blame] | 6 | * @license MIT
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 7 | */
|
| 8 |
|
| 9 |
|
| 10 | /**
|
| 11 | * Renders the discussions list for a class
|
| 12 | *
|
| 13 | * @param {string} courseID The course ID to render discussion threads for
|
| 14 | * @param {string} [defaultThread] The thread to load by default
|
| 15 | * @param {boolean} [fromModules] True if this page is being loaded from the moduleStream
|
| 16 | * @param {string} [defaultPost] The post to load by default
|
| 17 | */
|
| 18 | dtps.loadThreadsList = function (courseID, defaultThread, fromModules, defaultPost) {
|
| 19 | //Get class index and set as selected class
|
| 20 | var classNum = dtps.classes.map(course => course.id).indexOf(courseID);
|
| 21 | dtps.selectedClass = classNum;
|
| 22 |
|
| 23 | //Set discussions as the selected content
|
| 24 | if (!fromModules) {
|
| 25 | dtps.selectedContent = "discuss";
|
| 26 | $("#dtpsTabBar .btn").removeClass("active");
|
| 27 | $("#dtpsTabBar .btn.discuss").addClass("active");
|
| 28 | jQuery("body").removeClass("collapsedSidebar");
|
| 29 | }
|
| 30 |
|
| 31 | if (classNum == -1) {
|
| 32 | //Class does not exist
|
| 33 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.loadThreadsList");
|
| 34 | }
|
| 35 |
|
| 36 | //Load class color and things
|
| 37 | dtps.presentClass(classNum);
|
| 38 |
|
| 39 | //Load module thread
|
| 40 | if (fromModules) {
|
| 41 | dtps.loadThreadPosts(classNum, defaultThread, fromModules, defaultPost);
|
| 42 | return;
|
| 43 | }
|
| 44 |
|
| 45 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "discuss")) {
|
| 46 | //Render sidebar
|
| 47 | jQuery(".sidebar").html(/*html*/`
|
| 48 | <div class="title">
|
| 49 | <i style="font-size: 28px; margin-right: 7px; vertical-align: middle;" class="fluid-icon">forum</i>
|
| 50 | <h4>Discussions</h4>
|
| 51 | </div>
|
| 52 |
|
| 53 | <div class="items">
|
| 54 | <div onclick="fluid.screen('stream', '${dtps.classes[classNum].id}');" class="item main back">
|
| 55 | <i class="fluid-icon">keyboard_arrow_left</i> <span class="label">Classes</span>
|
| 56 | </div>
|
| 57 |
|
| 58 | <div class="divider"></div>
|
| 59 |
|
| 60 | <div class="item shimmerParent">
|
| 61 | <i class="fluid-icon">star</i>
|
| 62 | <span class="label">Discussion thread Title</span>
|
| 63 | </div>
|
| 64 | <div class="item shimmerParent">
|
| 65 | <i class="fluid-icon">star</i>
|
| 66 | <span class="label">Discussion thread Title</span>
|
| 67 | </div>
|
| 68 | <div class="item shimmerParent">
|
| 69 | <i class="fluid-icon">star</i>
|
| 70 | <span class="label">Discussion thread Title</span>
|
| 71 | </div>
|
| 72 | </div>
|
| 73 | `);
|
| 74 |
|
| 75 | //Delete existing class content HTML
|
| 76 | jQuery(".classContent").html("");
|
| 77 | }
|
| 78 |
|
| 79 | //Fetch discussion thread data
|
| 80 | dtpsLMS.fetchDiscussionThreads(dtps.classes[classNum].lmsID).then(function (threadData) {
|
| 81 | //Store fetched data to the selected class
|
| 82 | dtps.classes[classNum].discussions = threadData;
|
| 83 |
|
| 84 | if (dtps.classes[classNum].discussions.length == 0) {
|
| 85 | //No discussion topics in this class
|
| 86 | jQuery(".sidebar .items").html(/*html*/`
|
| 87 | <div onclick="fluid.screen('stream', '${dtps.classes[classNum].id}');" class="item main back">
|
| 88 | <i class="fluid-icon">keyboard_arrow_left</i> <span class="label">Classes</span>
|
| 89 | </div>
|
| 90 |
|
| 91 | <p style="text-align: center; font-weight: bold; margin-top: 60px; margin-bottom: 10px;">No discussions found</p>
|
| 92 | <p style="text-align: center; font-size: 14px; margin: 0px;">This class doesn't have any discussions</p>
|
| 93 | `);
|
| 94 | } else {
|
| 95 | //Loop over discusson threads array to create discussion thread HTML for the sidebar
|
| 96 | var discussionHTML = dtps.classes[classNum].discussions.map(discussionThread => {
|
| 97 | return /*html*/`
|
| 98 | <div data-threadID="${discussionThread.id}" class="item">
|
| 99 | <i class="fluid-icon">${discussionThread.locked ? "lock_outline" : "chat_bubble_outline"}</i>
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 100 | <span class="label">${DOMPurify.sanitize(discussionThread.title)}</span>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 101 | </div>
|
| 102 | `;
|
| 103 | }).join("");
|
| 104 |
|
| 105 | //Render discussion threads in the sidebar
|
| 106 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "discuss")) {
|
| 107 | jQuery(".sidebar .items").html(/*html*/`
|
| 108 | <div onclick="fluid.screen('stream', '${dtps.classes[classNum].id}');" class="item main back">
|
| 109 | <i class="fluid-icon">keyboard_arrow_left</i> <span class="label">Classes</span>
|
| 110 | </div>
|
| 111 |
|
| 112 | ${
|
| 113 | dtps.classes[classNum].newDiscussionThreadURL ? (/*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 114 | <div onclick="window.open(${dtps.escapeAttr(JSON.stringify(dtps.safeURL(dtps.classes[classNum].newDiscussionThreadURL)))})" class="item back">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 115 | <i class="fluid-icon">add</i>
|
| 116 | <span class="label">New discussion</span>
|
| 117 | </div>
|
| 118 | `) : ""
|
| 119 | }
|
| 120 |
|
| 121 | <div class="divider"></div>
|
| 122 |
|
| 123 | ${discussionHTML}
|
| 124 | `);
|
| 125 |
|
| 126 | //Load default thread if provided
|
| 127 | if (defaultThread) {
|
| 128 | dtps.loadThreadPosts(classNum, defaultThread, fromModules, defaultPost);
|
| 129 | }
|
| 130 |
|
| 131 | //Add click event listeners for discussion threads
|
| 132 | $(".sidebar .item:not(.back)").click(function (event) {
|
| 133 | //Show the selected thread as active
|
| 134 | $(this).siblings().removeClass("active");
|
| 135 | $(this).addClass("active");
|
| 136 |
|
| 137 | //Get thread ID from HTML attribute
|
| 138 | var postID = $(this).attr("data-threadID");
|
| 139 |
|
| 140 | //Load the thread
|
| 141 | dtps.loadThreadPosts(classNum, postID);
|
| 142 | });
|
| 143 | }
|
| 144 | }
|
| 145 |
|
| 146 | }).catch(function (err) {
|
| 147 | dtps.error("Couldn't fetch discussion threads", "Caught promise rejection @ dtps.loadThreadsList", err);
|
| 148 | });
|
| 149 | }
|
| 150 |
|
| 151 | /**
|
| 152 | * Fetches and displays posts in a discussion
|
| 153 | *
|
| 154 | * @param {number} classNum The class number to render
|
| 155 | * @param {string} threadID The discussion thread to render
|
| 156 | * @param {boolean} [fromModules] True if this page is being loaded from the moduleStream
|
| 157 | * @param {string} [defaultPost] The post ID to jump to
|
| 158 | */
|
| 159 | dtps.loadThreadPosts = function (classNum, threadID, fromModules, defaultPost) {
|
| 160 | //Show loading indicator
|
| 161 | if ((dtps.selectedClass == classNum) && ((dtps.selectedContent == "discuss") || fromModules)) {
|
| 162 | jQuery(".classContent").html(/*html*/`
|
| 163 | <div class="card" style="margin-top: 20px;margin-bottom: 75px;">
|
| 164 | <h4><span class="shimmer">[SHIMMER] Thread Title</span></h4>
|
| 165 |
|
| 166 | <div style="margin-bottom: 32px;" class="discussionHeader">
|
| 167 | <h5 ><span class="shimmer">Discussion author name</span></h5>
|
| 168 |
|
| 169 | <i class="fluid-icon shimmer">calendar_today</i>
|
| 170 | <span class="shimmer">Discussion date</span>
|
| 171 | </div>
|
| 172 |
|
| 173 | <div class="shimmer" style="margin: 10px 0px; width: 100%; height: 400px; border: none; outline: none;"></div>
|
| 174 |
|
| 175 | <div style="margin-top: 32px;" class="discussionFooter">
|
| 176 | <button class="btn small shimmer"><i class="fluid-icon">post_add</i> Add Post</button>
|
| 177 | </div>
|
| 178 | </div>
|
| 179 | `);
|
| 180 | }
|
| 181 |
|
| 182 | //Fetch discussion posts from the LMS
|
| 183 | dtpsLMS.fetchDiscussionPosts(dtps.classes[classNum].lmsID, threadID).then(function (thread) {
|
| 184 | //Post HTML array
|
| 185 | var postHTML = [];
|
| 186 |
|
| 187 | thread.posts.forEach((post, index) => {
|
| 188 | //Get background and text color for iFrame content
|
| 189 | var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
|
| 190 | var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
|
| 191 |
|
| 192 | //Create a new blob data URL with the post's content
|
| 193 | var blob = new Blob([`
|
| 194 | <base target="_blank" />
|
| 195 | <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
|
| 196 | <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 197 | ${dtps.sanitizeContent(post.body)}
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 198 | `], { type: 'text/html' });
|
| 199 | var discussionPostContentURL = window.URL.createObjectURL(blob);
|
| 200 |
|
| 201 | //Create HTML for replies
|
| 202 | var replyHTML = [];
|
| 203 | if (post.replies) {
|
| 204 | //Add space above replies
|
| 205 | replyHTML.push(`<br />`);
|
| 206 |
|
| 207 | //Get HTML for each reply and add to array
|
| 208 | post.replies.forEach(reply => {
|
| 209 | replyHTML.push(/*html*/`
|
| 210 | <div data-post-id="${reply.id}" style="margin-left: ${(reply.depth || 0) * 50}px;" class="discussionReply">
|
| 211 | <div class="discussionHeader">
|
| 212 | ${post.author ? /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 213 | <img src="${dtps.escapeAttr(reply.author.photoURL)}" />
|
| 214 | <h5>${DOMPurify.sanitize(reply.author.name)}</h5>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 215 | ` : ``}
|
| 216 |
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 217 | <span style="cursor: pointer;" onclick="window.open(${dtps.escapeAttr(JSON.stringify(dtps.safeURL(reply.replyURL)))});">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 218 | <i class="fluid-icon">reply</i>
|
| 219 | <span>Reply</span>
|
| 220 | </span>
|
| 221 | </div>
|
| 222 |
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 223 | ${dtps.sanitizeContent(reply.body)}
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 224 | </div>
|
| 225 | `)
|
| 226 | });
|
| 227 |
|
| 228 | //Add space below replies
|
| 229 | replyHTML.push(`<br />`);
|
| 230 | }
|
| 231 |
|
| 232 | //Create HTML for this post
|
| 233 | //Note that index == 0 is the initial post
|
| 234 | postHTML.push(/*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 235 | <div class="card" data-post-id="${dtps.escapeAttr(post.id)}" style="margin-top: 20px;${index == 0 ? "margin-bottom: 75px;" : "padding: 20px 30px;"}">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 236 | <!-- Thread title (Initial post) -->
|
| 237 | ${index == 0 ? /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 238 | <h4 style="font-weight: bold">${DOMPurify.sanitize(thread.title)}</h4>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 239 | ` : ''}
|
| 240 |
|
| 241 | <!-- Author header -->
|
| 242 | <div ${index == 0 ? `style="margin-bottom: 32px;"` : ""} class="discussionHeader">
|
| 243 | ${post.author ? /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 244 | <img src="${dtps.escapeAttr(post.author.photoURL)}" />
|
| 245 | <h5>${DOMPurify.sanitize(post.author.name)}</h5>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 246 | ` : ``}
|
| 247 |
|
| 248 | <i class="fluid-icon">calendar_today</i>
|
| 249 | <span>${dtps.formatDate(post.postedAt)}</span>
|
| 250 |
|
| 251 | <!-- Thread info (initial post) -->
|
| 252 | ${index == 0 ? /*html*/`
|
| 253 | ${thread.locked ? `<i class="fluid-icon">lock</i>` : ""}
|
| 254 | ${thread.requireInitialPost ? /*html*/`
|
| 255 | <i class="fluid-icon">visibility</i>
|
| 256 | <span>You must post before you can see other replies</span>
|
| 257 | ` : ""}
|
| 258 | ` : ''}
|
| 259 | </div>
|
| 260 |
|
| 261 | ${index == 0 ? /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 262 | <iframe id="classThreadIframe" onload="dtps.iframeLoad('classThreadIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${discussionPostContentURL}"></iframe>
|
| 263 | ` : dtps.sanitizeContent(post.body)}
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 264 |
|
| 265 | ${replyHTML.join("")}
|
| 266 |
|
| 267 | <!-- Reply / Add post footer -->
|
| 268 | ${post.replyURL ? /*html*/`
|
| 269 | <div ${index == 0 ? `style="margin-top: 32px;"` : ""} class="discussionFooter">
|
| 270 | ${index == 0 ? /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 271 | <button onclick="window.open(${dtps.escapeAttr(JSON.stringify(dtps.safeURL(post.replyURL)))});" class="btn small"><i class="fluid-icon">post_add</i> Add Post</button>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 272 | ` : /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 273 | <button onclick="window.open(${dtps.escapeAttr(JSON.stringify(dtps.safeURL(post.replyURL)))});" class="btn small"><i class="fluid-icon">reply</i> Reply</button>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 274 | `}
|
| 275 | </div>
|
| 276 | ` : ""}
|
| 277 | </div>
|
| 278 | `);
|
| 279 | });
|
| 280 |
|
| 281 | //Render HTML
|
| 282 | if ((dtps.selectedClass == classNum) && ((dtps.selectedContent == "discuss") || fromModules)) {
|
| 283 | jQuery(".classContent").html((fromModules ? /*html*/`
|
| 284 | <button style="margin: 10px 0px 0px 20px;" class="btn" onclick="fluid.screen('moduleStream', '${dtps.classes[classNum].id}')">
|
| 285 | <i class="fluid-icon">keyboard_arrow_left</i> Back
|
| 286 | </button>
|
| 287 | ` : "") + postHTML.join(""));
|
| 288 |
|
| 289 | //Jump to post if specified
|
| 290 | if (defaultPost) {
|
| 291 | $("[data-post-id=" + defaultPost + "]").get(0).scrollIntoView();
|
| 292 | }
|
| 293 | }
|
| 294 | }).catch(function (err) {
|
| 295 | dtps.error("Could not fetch discussion posts", "Caught promise rejection @ dtps.loadThreadPosts", err);
|
| 296 | });
|
| 297 | }
|
| 298 |
|
| 299 | /**
|
| 300 | * Renders the pages list for a class
|
| 301 | *
|
| 302 | * @param {string} courseID The course ID to render pages for
|
| 303 | * @param {string} [defaultPage] If provided, load the pageID by default
|
| 304 | * @param {boolean} fromModules True if this page is being loaded from the moduleStream
|
| 305 | */
|
| 306 | dtps.loadPagesList = function (courseID, defaultPage, fromModules) {
|
| 307 | //Get class index and set as selected class
|
| 308 | var classNum = dtps.classes.map(course => course.id).indexOf(courseID);
|
| 309 | dtps.selectedClass = classNum;
|
| 310 |
|
| 311 | //Set pages as the selected content
|
| 312 | if (!fromModules) {
|
| 313 | dtps.selectedContent = "pages";
|
| 314 | $("#dtpsTabBar .btn").removeClass("active");
|
| 315 | $("#dtpsTabBar .btn.pages").addClass("active");
|
| 316 | jQuery("body").removeClass("collapsedSidebar");
|
| 317 | }
|
| 318 |
|
| 319 | if (classNum == -1) {
|
| 320 | //Class does not exist
|
| 321 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.loadPagesList");
|
| 322 | }
|
| 323 |
|
| 324 | //Load class color and things
|
| 325 | dtps.presentClass(classNum);
|
| 326 |
|
| 327 | //Load module page
|
| 328 | if (fromModules) {
|
| 329 | dtps.loadPage(classNum, defaultPage, fromModules);
|
| 330 | return;
|
| 331 | }
|
| 332 |
|
| 333 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "pages")) {
|
| 334 | //Render sidebar
|
| 335 | jQuery(".sidebar").html(/*html*/`
|
| 336 | <div class="title">
|
| 337 | <i style="font-size: 28px; margin-right: 7px; vertical-align: middle;" class="fluid-icon">insert_drive_file</i>
|
| 338 | <h4>Pages</h4>
|
| 339 | </div>
|
| 340 |
|
| 341 | <div class="items">
|
| 342 | <div onclick="fluid.screen('stream', '${dtps.classes[classNum].id}');" class="item main back">
|
| 343 | <i class="fluid-icon">keyboard_arrow_left</i> <span class="label">Classes</span>
|
| 344 | </div>
|
| 345 |
|
| 346 | <div class="divider"></div>
|
| 347 |
|
| 348 | <div class="item shimmerParent">
|
| 349 | <i class="fluid-icon">star</i>
|
| 350 | <span class="label">Class page title</span>
|
| 351 | </div>
|
| 352 | <div class="item shimmerParent">
|
| 353 | <i class="fluid-icon">star</i>
|
| 354 | <span class="label">Class page title</span>
|
| 355 | </div>
|
| 356 | <div class="item shimmerParent">
|
| 357 | <i class="fluid-icon">star</i>
|
| 358 | <span class="label">Class page title</span>
|
| 359 | </div>
|
| 360 | </div>
|
| 361 | `);
|
| 362 |
|
| 363 | //Delete existing class content HTML
|
| 364 | jQuery(".classContent").html("");
|
| 365 | }
|
| 366 |
|
| 367 | dtpsLMS.fetchPages(dtps.classes[classNum].lmsID).then(function (pagesData) {
|
| 368 | //Store fetched pages data to the class
|
| 369 | dtps.classes[classNum].pages = pagesData;
|
| 370 |
|
| 371 | if (pagesData.length == 0) {
|
| 372 | //No pages in this class
|
| 373 | jQuery(".sidebar .items").html(/*html*/`
|
| 374 | <div onclick="fluid.screen('stream', '${dtps.classes[classNum].id}');" class="item main back">
|
| 375 | <i class="fluid-icon">keyboard_arrow_left</i>
|
| 376 | <span class="label">Classes</span>
|
| 377 | </div>
|
| 378 |
|
| 379 | <p style="text-align: center; font-weight: bold; margin-top: 60px; margin-bottom: 10px;">No pages found</p>
|
| 380 | <p style="text-align: center; font-size: 14px; margin: 0px;">This class doesn't have any pages</p>
|
| 381 | `);
|
| 382 | } else {
|
| 383 | //Loop over discusson threads array to create discussion thread HTML for the sidebar
|
| 384 | var pageHTML = dtps.classes[classNum].pages.map(page => {
|
| 385 | return /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 386 | <div data-pageID="${dtps.escapeAttr(page.id)}" class="item ${(defaultPage && (page.id == defaultPage)) ? "active" : ""}">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 387 | <i class="fluid-icon">insert_drive_file</i>
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 388 | <span class="label">${DOMPurify.sanitize(page.title)}</span>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 389 | </div>
|
| 390 | `;
|
| 391 | }).join("");
|
| 392 |
|
| 393 | //Render discussion threads in the sidebar
|
| 394 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "pages")) {
|
| 395 | jQuery(".sidebar .items").html(/*html*/`
|
| 396 | <div onclick="fluid.screen('stream', '${dtps.classes[classNum].id}');" class="item main back">
|
| 397 | <i class="fluid-icon">keyboard_arrow_left</i>
|
| 398 | <span class="label">Classes</span>
|
| 399 | </div>
|
| 400 |
|
| 401 | <div class="divider"></div>
|
| 402 |
|
| 403 | ${pageHTML}
|
| 404 | `);
|
| 405 | }
|
| 406 |
|
| 407 | //Load default page if provided
|
| 408 | if (defaultPage) {
|
| 409 | dtps.loadPage(classNum, defaultPage);
|
| 410 | }
|
| 411 |
|
| 412 | //Add click event listeners for pages
|
| 413 | $(".sidebar .item:not(.back)").click(function (event) {
|
| 414 | //Show the selected thread as active
|
| 415 | $(this).siblings().removeClass("active");
|
| 416 | $(this).addClass("active");
|
| 417 |
|
| 418 | //Get page ID from HTML attribute
|
| 419 | var pageID = $(this).attr("data-pageID");
|
| 420 |
|
| 421 | //Load the page content
|
| 422 | dtps.loadPage(classNum, pageID);
|
| 423 | });
|
| 424 | }
|
| 425 | }).catch((err) => {
|
| 426 | dtps.error("Couldn't fetch pages", "Caught promise rejection @ dtps.loadPagesList", err);
|
| 427 | });
|
| 428 | }
|
| 429 |
|
| 430 | /**
|
| 431 | * Fetches and renders a page and its contents
|
| 432 | *
|
| 433 | * @param {string} classNum The class number of the page to render
|
| 434 | * @param {string} pageID The page ID to render
|
| 435 | * @param {boolean} fromModules True if this page is being loaded from the moduleStream
|
| 436 | */
|
| 437 | dtps.loadPage = function (classNum, pageID, fromModules) {
|
| 438 | //Show loading indicator
|
| 439 | if ((dtps.selectedClass == classNum) && ((dtps.selectedContent == "pages") || fromModules)) {
|
| 440 | jQuery(".classContent").html(/*html*/`
|
| 441 | <div style="margin: 20px; padding: 20px;">
|
| 442 | <h4><span class="shimmer">[SHIMMER] Class page title</span></h4>
|
| 443 |
|
| 444 | <div style="margin-bottom: 32px;" class="discussionHeader">
|
| 445 | <h5 class="shimmer">Page author name</h5>
|
| 446 |
|
| 447 | <i class="fluid-icon shimmer">calendar_today</i>
|
| 448 | <span class="shimmer">[SHIMMER] Last updated at</span>
|
| 449 | </div>
|
| 450 |
|
| 451 | <!-- Page content -->
|
| 452 | <br />
|
| 453 | <div class="shimmer" style="margin: 10px 0px; width: 100%; height: 600px; border: none; outline: none;"></div>
|
| 454 | </div>
|
| 455 | `);
|
| 456 | }
|
| 457 |
|
| 458 | //Fetch page content
|
| 459 | dtpsLMS.fetchPageContent(dtps.classes[classNum].lmsID, pageID).then(function (page) {
|
| 460 | if ((dtps.selectedClass == classNum) && ((dtps.selectedContent == "pages") || fromModules)) {
|
| 461 | //Get computed background and text color to style the iFrame with
|
| 462 | var computedBackgroundColor = getComputedStyle($(".classContent")[0]).getPropertyValue("--background");
|
| 463 | var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
|
| 464 |
|
| 465 | //Generate a blob with the page content and get its data URL
|
| 466 | var blob = new Blob([`
|
| 467 | <base target="_blank" />
|
| 468 | <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
|
| 469 | <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 470 | ${dtps.sanitizeContent(page.content)}
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 471 | `], { type: 'text/html' });
|
| 472 |
|
| 473 | //Get URL from blob
|
| 474 | var pageContentURL = window.URL.createObjectURL(blob);
|
| 475 |
|
| 476 | //Render page card in the class content
|
| 477 | jQuery(".classContent").html(/*html*/`
|
| 478 | ${fromModules ? /*html*/`
|
| 479 | <button style="margin: 10px 0px 0px 20px;" class="btn" onclick="fluid.screen('moduleStream', '${dtps.classes[classNum].id}')">
|
| 480 | <i class="fluid-icon">keyboard_arrow_left</i> Back
|
| 481 | </button>
|
| 482 | ` : ""}
|
| 483 | <div style="margin: 20px; padding: 20px;">
|
| 484 | <!-- Page title -->
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 485 | <h4 style="font-weight: bold;">${DOMPurify.sanitize(page.title)}</h4>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 486 |
|
| 487 | <!-- Page header -->
|
| 488 | <div style="margin-bottom: 32px;" class="discussionHeader">
|
| 489 | ${page.author ? /*html*/`
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 490 | <img src="${dtps.escapeAttr(page.author.photoURL)}" />
|
| 491 | <h5>${DOMPurify.sanitize(page.author.name)}</h5>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 492 | ` : ``}
|
| 493 |
|
| 494 | <i class="fluid-icon">calendar_today</i>
|
| 495 | <span>${"Last Updated " + dtps.formatDate(page.updatedAt)}</span>
|
| 496 | </div>
|
| 497 |
|
| 498 | <!-- Page content -->
|
| 499 | <br />
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 500 | <iframe id="classPageIframe" onload="dtps.iframeLoad('classPageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${pageContentURL}"></iframe>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 501 | </div>
|
| 502 | `);
|
| 503 | }
|
| 504 | }).catch((err) => {
|
| 505 | dtps.error("Couldn't load page", "Caught promise rejection @ dtps.loadPage", err);
|
| 506 | });
|
| 507 | }
|
| 508 |
|
| 509 | //Fluid UI screen definitions
|
| 510 | fluid.externalScreens.discussions = (param) => {
|
| 511 | //Split parameter string into variables
|
| 512 | var courseID = param.split("|")[0];
|
| 513 | var threadID = param.split("|")[1];
|
| 514 | var fromModules = param.split("|")[2] == "true";
|
| 515 | var postID = param.split("|")[3];
|
| 516 |
|
| 517 | dtps.loadThreadsList(courseID, threadID, fromModules, postID);
|
| 518 | }
|
| 519 |
|
| 520 | fluid.externalScreens.pages = (param) => {
|
| 521 | //Split parameter string into variables
|
| 522 | var courseID = param.split("|")[0];
|
| 523 | var pageID = param.split("|")[1];
|
| 524 | var fromModules = param.split("|")[2] == "true";
|
| 525 |
|
| 526 | dtps.loadPagesList(courseID, pageID, fromModules);
|
| 527 | }
|
| 528 |
|
| 529 | //Type definitions
|
| 530 |
|
| 531 | /**
|
| 532 | * @typedef {Object} PartialDiscussionThread
|
| 533 | * @description Defines partial discussion thread objects in DTPS (for threads list)
|
| 534 | * @property {string} title Title of the discussion thread
|
| 535 | * @property {string} id Discussion thread ID
|
| 536 | * @property {boolean} [locked] True if posting to the discussion thread is locked
|
| 537 | */
|
| 538 |
|
| 539 | /**
|
| 540 | * @typedef {Object} DiscussionThread
|
| 541 | * @description Defines discussion thread objects in DTPS
|
| 542 | * @property {string} title Title of the discussion thread
|
| 543 | * @property {string} id Discussion thread ID
|
| 544 | * @property {DiscussionPost[]} posts Posts in this thread, with the initial one first.
|
| 545 | * @property {boolean} [locked] True if posting to the discussion thread is locked
|
| 546 | * @property {boolean} [requireInitialPost] True if the user must post before viewing others' posts
|
| 547 | */
|
| 548 |
|
| 549 | /**
|
| 550 | * @typedef {Object} DiscussionPost
|
| 551 | * @description Defines discussion post objects in DTPS
|
| 552 | * @property {string} id Discussion post ID
|
| 553 | * @property {string} body Discussion post body HTML
|
| 554 | * @property {Date} postedAt Date for when the post was posted
|
| 555 | * @property {number} [depth] The depth level this post is
|
| 556 | * @property {User} [author] Discussion post author
|
| 557 | * @property {DiscussionPost[]} [replies] Replies to this post. Nested replies (replies to replies) should be after this post in the array with a depth of 1, not in the replies key.
|
| 558 | * @property {string} [replyURL] A URL that the user can visit to reply to this post
|
| 559 | */
|
| 560 |
|
| 561 | /**
|
| 562 | * @typedef {Object} PartialPage
|
| 563 | * @description Defines a partial page object in DTPS (for pages list)
|
| 564 | * @property {string} title Page title
|
| 565 | * @property {string} id Page ID
|
| 566 | */
|
| 567 |
|
| 568 | /**
|
| 569 | * @typedef {Object} Page
|
| 570 | * @description Defines Page objects in DTPS
|
| 571 | * @property {string} title Page title
|
| 572 | * @property {string} id Page ID
|
| 573 | * @property {string} content Page content HTML
|
| 574 | * @property {Date} [updatedAt] When the page was last updated
|
| 575 | * @property {User} [author] Page author
|
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 576 | */ |