diff options
author | 2018-06-13 16:43:42 +0100 | |
---|---|---|
committer | 2018-06-13 16:43:42 +0100 | |
commit | be2bbe35cf49763ad0258c005f3cbdddd7a21d75 (patch) | |
tree | 962d5e52f4bb57c397c068ae6a11b57952cfc459 /js/src/jams.js | |
parent | [DB] Attempt reconnection if current connection was lost (diff) |
Compile as much JS with Gulp as possible
This will concatenate ALL of our JS, and minify it - thus leaving us with a single file to be loaded.
There's a few libraries we can't do this with, unfortunately - these are now added in fouc.js:
* Ace Editor
* Flatpickr
* Font-Awesome
Diffstat (limited to 'js/src/jams.js')
-rw-r--r-- | js/src/jams.js | 147 |
1 files changed, 147 insertions, 0 deletions
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 + ); + } +} |