diff options
Diffstat (limited to 'yaksh/static')
-rw-r--r-- | yaksh/static/yaksh/css/ontop.css | 20 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/question.js | 12 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 158 |
3 files changed, 178 insertions, 12 deletions
diff --git a/yaksh/static/yaksh/css/ontop.css b/yaksh/static/yaksh/css/ontop.css new file mode 100644 index 0000000..fb22066 --- /dev/null +++ b/yaksh/static/yaksh/css/ontop.css @@ -0,0 +1,20 @@ +#ontop { + position: fixed; + display: none; + width: 100%; + height: 100%; + top:0; + bottom: 0; + left:0; + right: 0; + background-color: rgba(0,0,0,0.5); + z-index: 1001; /* 1001 coz sidebar is 1000. So will be on top of sidebar*/ +} + +#state { + position: absolute; + top: 50%; + left: 50%; + font-size: 30px; + color: white; +} diff --git a/yaksh/static/yaksh/js/question.js b/yaksh/static/yaksh/js/question.js deleted file mode 100644 index 96ff3de..0000000 --- a/yaksh/static/yaksh/js/question.js +++ /dev/null @@ -1,12 +0,0 @@ -function submitCode() -{ - document.forms["code"].submit(); - var x = document.getElementById("status"); - x.innerHTML = "<strong>Checking answer ...</strong>"; - x = document.getElementById("check"); - x.disabled = true; - x.value = "Checking Answer ..."; - if (document.getElementById("skip")!=null) { - document.getElementById("skip").disabled = true; - } -} diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js new file mode 100644 index 0000000..9890b54 --- /dev/null +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -0,0 +1,158 @@ +request_status = "initial" +count = 0; +checker = null +function submitRequest(){ + document.forms["code"].submit(); +} + +function check_state(state, uid) { + if ((state == "running" || state == "not started") && count < 7) { + count++; + setTimeout(function() {get_result(uid);}, 2000); + } else if (state == "unknown") { + request_status = "initial"; + count = 0; + notify("You are requesting for a wrong data"); + clearInterval(checker); + unlock_screen(); + } else { + request_status = "initial"; + count = 0; + notify("Please try after few minutes"); + clearInterval(checker); + unlock_screen(); + } +} + +function notify(text) { + var $notice = document.getElementById("notification"); + $notice.classList.add("alert"); + $notice.classList.add("alert-success"); + $notice.innerHTML = text; +} + +function lock_screen() { + document.getElementById("ontop").style.display = "block"; +} + +function unlock_screen() { + document.getElementById("ontop").style.display = "none"; +} + +function check_lock_screen() { + var $ontop_div = document.getElementById("ontop"); + if ($ontop_div.style.display == "block") { + $ontop_div.style.display = "none"; + } +} + +function get_result(uid){ + $.ajax({ + method: "GET", + url: "/exam/get_results/"+uid+"/", + dataType: "html", // Your server can response html, json, xml format. + success: function(data, status, xhr) { + content_type = xhr.getResponseHeader("content-type"); + if(content_type.indexOf("text/html") !== -1) { + clearInterval(checker); + unlock_screen(); + document.open(); + document.write(data); + document.close(); + } else if(content_type.indexOf("application/json") !== -1) { + res = JSON.parse(data); + request_status = res.status; + check_state(request_status, uid); + } else { + request_status = "initial"; + count = 0; + clearInterval(checker); + unlock_screen(); + } + }, + error: function(xhr, text_status, error_thrown ) { + request_status = "initial"; + count = 0; + clearInterval(checker); + unlock_screen(); + notify("There is some problem. Try later.") + } + }); +} + +var global_editor = {}; +$(document).ready(function(){ + // Codemirror object, language modes and initial content + // Get the textarea node + var textarea_node = document.querySelector('#answer'); + + var mode_dict = { + 'python': 'python', + 'c': 'text/x-csrc', + 'cpp': 'text/x-c++src', + 'java': 'text/x-java', + 'bash': 'text/x-sh', + 'scilab': 'text/x-csrc' + } + + // Code mirror Options + var options = { + mode: mode_dict[lang], + gutter: true, + lineNumbers: true, + onChange: function (instance, changes) { + render(); + } + }; + + // Initialize the codemirror editor + global_editor.editor = CodeMirror.fromTextArea(textarea_node, options); + + // Setting code editors initial content + global_editor.editor.setValue(init_val); + + function reset_editor() { + global_editor.editor.setValue(init_val); + global_editor.editor.clearHistory(); + } + $('#code').submit(function(e) { + checker = setInterval(check_lock_screen, 30000); + lock_screen(); + $.ajax({ + type: 'POST', + url: $(this).attr("action"), + data: $(this).serializeArray(), + dataType: "html", // Your server can response html, json, xml format. + success: function(data, status, xhr) { + content_type = xhr.getResponseHeader("content-type"); + if(content_type.indexOf("text/html") !== -1) { + request_status = "initial" + count = 0; + clearInterval(checker); + unlock_screen(); + document.open(); + document.write(data); + document.close(); + } else if(content_type.indexOf("application/json") !== -1) { + res = JSON.parse(data); + var uid = res.uid; + request_status = res.state; + check_state(request_status, uid); + } else { + request_status = "initial"; + count = 0; + clearInterval(checker); + unlock_screen(); + } + }, + error: function(xhr, text_status, error_thrown ) { + request_status = "initial"; + count = 0; + clearInterval(checker); + unlock_screen(); + notify("There is some problem. Try later.") + } + }); + e.preventDefault(); // To stop the default form submission. + }); +}); |