From da15e439e64c8314825ad5f28073fbcbd436946f Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Thu, 30 May 2019 13:29:31 +0100 Subject: Initial version of demo This commit introduces the demo functionality. The task assignment has been removed at the moment, as this will be changed in a future commit. --- app/static/js/buttons.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'app/static/js/buttons.js') diff --git a/app/static/js/buttons.js b/app/static/js/buttons.js index d26a15d..75adad2 100644 --- a/app/static/js/buttons.js +++ b/app/static/js/buttons.js @@ -8,7 +8,7 @@ function resetOnClick() { updateTable(); } -function noCPOnClick(task_id) { +function noCPOnClick(identifier) { var changepoints = document.getElementsByClassName("changepoint"); // validation if (changepoints.length > 0) { @@ -16,27 +16,27 @@ function noCPOnClick(task_id) { return; } - var obj = { - task: task_id, - changepoints: null - }; + var obj = {} + obj["identifier"] = identifier; + obj["changepoints"] = null; var xhr = new XMLHttpRequest(); - xhr.open("POST", ""); + xhr.open("POST", "", false); xhr.withCredentials = true; xhr.setRequestHeader("Content-Type", "application/json"); - xhr.send(JSON.stringify(obj)); + /* Flask's return to this POST must be a URL, not a template!*/ xhr.onreadystatechange = function() { - if (xhr.readyState == XMLHttpRequest.DONE) { - if (xhr.status === 200) - window.location.href = xhr.responseText; + if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) { + window.location.href = xhr.responseText; + console.log("XHR Success: " + xhr.responseText); } else { - console.log("Error: " + xhr.status); + console.log("XHR Error: " + xhr.status); } - }; + } + xhr.send(JSON.stringify(obj)); } -function submitOnClick(task_id) { +function submitOnClick(identifier) { var changepoints = document.getElementsByClassName("changepoint"); // validation if (changepoints.length === 0) { @@ -45,7 +45,7 @@ function submitOnClick(task_id) { } var obj = {}; - obj["task"] = task_id; + obj["identifier"] = identifier; obj["changepoints"] = []; var i, cp; for (i=0; i