diff options
Diffstat (limited to '')
-rw-r--r-- | js/src/countdown.js (renamed from static/js/countdown.js) | 1 | ||||
-rw-r--r-- | js/src/errors.js (renamed from static/js/500.js) | 6 | ||||
-rw-r--r-- | js/src/fouc.js (renamed from static/js/fouc.js) | 27 | ||||
-rw-r--r-- | js/src/jams.js | 147 | ||||
-rw-r--r-- | js/src/revision_diff.js (renamed from static/js/revision_diff.js) | 9 | ||||
-rw-r--r-- | js/src/wiki.js (renamed from static/js/wiki.js) | 6 |
6 files changed, 180 insertions, 16 deletions
diff --git a/static/js/countdown.js b/js/src/countdown.js index 8ba2e58d..7eaa650c 100644 --- a/static/js/countdown.js +++ b/js/src/countdown.js @@ -1,6 +1,7 @@ "use strict"; (function(){ // Use a closure to avoid polluting global scope + // TODO: This needs to be built into the jams system const startjam = new Date(Date.UTC(2018, 2, 23)); const endjam = new Date(Date.UTC(2018, 2, 26)); diff --git a/static/js/500.js b/js/src/errors.js index 7effe502..492285d4 100644 --- a/static/js/500.js +++ b/js/src/errors.js @@ -1,6 +1,8 @@ "use strict"; -window.onload = function () { +/* exported error_typewriter */ + +function error_typewriter() { const app = document.getElementById("error"); const typewriter = new Typewriter(app, { @@ -44,4 +46,4 @@ window.onload = function () { .typeString("response.text\n") .appendText(`${ window._ErrorMsg }\n>>> `) .start(); -}; +} diff --git a/static/js/fouc.js b/js/src/fouc.js index 01354863..3611ec27 100644 --- a/static/js/fouc.js +++ b/js/src/fouc.js @@ -1,24 +1,31 @@ "use strict"; -function getScript(url, integrity, crossorigin){ +function getScript(url, integrity, cross_origin) { const script = document.createElement("script"); script.type = "text/javascript"; script.src = url; script.defer = true; - script.integrity = integrity; - script.crossOrigin = crossorigin; + + if (integrity !== undefined) { + script.integrity = integrity; + } + + if (cross_origin !== undefined) { + script.crossOrigin = cross_origin; + } + document.getElementsByTagName("head")[0].appendChild(script); } -function setClass(selector, myClass) { +function setClass(selector, my_class) { const element = document.querySelector(selector); // console.log(element); - element.className = myClass; + element.className = my_class; } -function removeClass(selector, myClass) { +function removeClass(selector, my_class) { const element = document.querySelector(selector); - const reg = new RegExp(`(^| )${myClass}($| )`, "g"); + const reg = new RegExp(`(^| )${my_class}($| )`, "g"); element.className = element.className.replace(reg, " "); } @@ -34,5 +41,11 @@ document.onreadystatechange = function () { "sha384-d84LGg2pm9KhR4mCAs3N29GQ4OYNy+K+FBHX8WhimHpPm86c839++MDABegrZ3gn", // Integrity "anonymous" // Cross-origin ); + getScript( + "https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js" + ); + getScript( + "https://cdn.jsdelivr.net/npm/flatpickr" + ); } }; diff --git a/js/src/jams.js b/js/src/jams.js new file mode 100644 index 00000000..ee2ee2ea --- /dev/null +++ b/js/src/jams.js @@ -0,0 +1,147 @@ +"use strict"; + +/* exported JamActions */ + +class JamActions { + constructor(url, csrf_token) { + this.url = url; + this.csrf_token = csrf_token; + } + + send(action, method, data, callback) { + data["action"] = action; + + $.ajax(this.url, { + "data": data, + "dataType": "json", + "headers": {"X-CSRFToken": this.csrf_token}, + "method": method, + }).done(data => { + if ("error_code" in data) { + return callback(false, data); + } + + return callback(true, data); + }).fail(() => callback(false)); + } + + send_json(action, method, data, callback) { + data["action"] = action; + + $.ajax(this.url, { + "data": JSON.stringify(data), + "dataType": "json", + "headers": {"X-CSRFToken": this.csrf_token}, + "method": method + }).done(data => { + if ("error_code" in data) { + return callback(false, data); + } + + return callback(true, data); + }).fail(() => callback(false)); + } + + set_state(jam, state, callback) { + this.send( + "state", + "POST", + { + "jam": jam, + "state": state + }, + callback + ); + } + + get_questions(callback) { + this.send( + "questions", + "GET", + {}, + callback + ); + } + + create_question(data, callback) { + this.send_json( + "questions", + "POST", + data, + callback + ); + } + + delete_question(id, callback) { + this.send( + "question", + "DELETE", + {"id": id}, + callback + ); + } + + associate_question(form, question, callback) { + this.send( + "associate_question", + "POST", + { + "form": form, + "question": question, + }, + callback + ); + } + + disassociate_question(form, question, callback) { + this.send( + "disassociate_question", + "POST", + { + "form": form, + "question": question, + }, + callback + ); + } + + create_infraction(id, reason, number, callback) { + this.send( + "infraction", + "POST", + { + "participant": id, + "reason": reason, + "number": number + }, + callback + ); + } + + delete_infraction(id, callback) { + this.send( + "infraction", + "DELETE", + {"id": id}, + callback + ); + } + + approve_application(id, callback) { + this.send( + "approve_application", + "POST", + {"id": id}, + callback + ); + } + + unapprove_application(id, callback) { + this.send( + "unapprove_application", + "POST", + {"id": id}, + callback + ); + } +} diff --git a/static/js/revision_diff.js b/js/src/revision_diff.js index 0dd17544..f124fbec 100644 --- a/static/js/revision_diff.js +++ b/js/src/revision_diff.js @@ -1,6 +1,8 @@ "use strict"; -(function() { +/* exported revision_diff */ + +function revision_diff(revisions) { const buttons = document.querySelectorAll("td input"); // Fetch all radio buttons const id_reg = /compare-(before|after)-([\w|-]+)/; // Matches compare-after/before-ID @@ -11,8 +13,6 @@ } function getRevision(id) { - /* global revisions */ // TODO: FIXME - const e = revisions.filter((x) => { // Filter through all revisions to find the selected one (revisions in declared in the template) return x.id === id; @@ -21,7 +21,6 @@ } function radioButtonChecked(element) { - // console.log("change detected"); const id = getRevisionId(element); const rev = getRevision(id[1]); if (id[0] === "after"){ @@ -81,4 +80,4 @@ radioButtonChecked(button); }; }); -})(); +} diff --git a/static/js/wiki.js b/js/src/wiki.js index 603eebef..f4bc18e8 100644 --- a/static/js/wiki.js +++ b/js/src/wiki.js @@ -1,6 +1,8 @@ "use strict"; -(function(){ // Use a closure to avoid polluting global scope +/* exported wiki_sidebar */ + +function wiki_sidebar(){ const visible_class = "uk-visible@s"; const sidebar = document.getElementById("wiki-sidebar"); const display_button = document.getElementById("wiki-sidebar-button"); @@ -12,4 +14,4 @@ sidebar.classList.add(visible_class); } }; -})(); +} |