diff --git a/lms/static/checker.js b/lms/static/checker.js new file mode 100644 index 00000000..fafb25c3 --- /dev/null +++ b/lms/static/checker.js @@ -0,0 +1,27 @@ +function trackFinished(exerciseId, solutionId, element) { + element.addEventListener('click', () => { + const xhr = new XMLHttpRequest(); + xhr.open('POST', `/checked/${exerciseId}/${solutionId}`, true); + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.responseType = 'json'; + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + if (xhr.response.next !== null) { + window.location.href = `/view/${xhr.response.next}`; + } else { + alert("Yay! That's it!"); + } + } else { + console.log(xhr.status); + } + } + }; + + xhr.send(JSON.stringify({})); + }); +} + +window.addEventListener('lines-numbered', () => { + trackFinished(window.exerciseId, window.solutionId, document.getElementById('save-check')); +}); diff --git a/lms/static/comments.js b/lms/static/comments.js index 5813d912..833741fc 100644 --- a/lms/static/comments.js +++ b/lms/static/comments.js @@ -148,6 +148,7 @@ window.addEventListener('load', () => { const codeElementData = document.getElementById('code-view').dataset; window.solutionId = codeElementData.id; window.fileId = codeElementData.file; + window.exerciseId = codeElementData.exercise; sessionStorage.setItem('role', codeElementData.role); sessionStorage.setItem('solver', codeElementData.solver); sessionStorage.setItem('allowedComment', codeElementData.allowedComment); diff --git a/lms/static/grader.js b/lms/static/grader.js index b6421ea7..a5eed320 100644 --- a/lms/static/grader.js +++ b/lms/static/grader.js @@ -1,27 +1,3 @@ -function trackFinished(exerciseId, solutionId, element) { - element.addEventListener('click', () => { - const xhr = new XMLHttpRequest(); - xhr.open('POST', `/checked/${exerciseId}/${solutionId}`, true); - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.responseType = 'json'; - xhr.onreadystatechange = () => { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - if (xhr.response.next !== null) { - window.location.href = `/view/${xhr.response.next}`; - } else { - alert("Yay! That's it!"); - } - } else { - console.log(xhr.status); - } - } - }; - - xhr.send(JSON.stringify({})); - }); -} - function sendComment(kind, fileId, line, commentData) { const xhr = new XMLHttpRequest(); xhr.open('POST', '/comments'); @@ -211,13 +187,11 @@ window.deleteComment = deleteComment; window.sendExistsComment = sendExistsComment; window.addEventListener('lines-numbered', () => { const codeView = document.getElementById('code-view'); - const exerciseId = codeView.dataset.exercise; const lineItems = codeView.getElementsByClassName('line'); addNewCommentButtons(lineItems); const addCommentItems = codeView.querySelectorAll('.grader-add'); trackDragAreas(lineItems, addCommentItems); trackDraggables(document.getElementsByClassName('known-comment')); - trackFinished(exerciseId, window.solutionId, document.getElementById('save-check')); if (!window.isUserGrader()) { sessionStorage.setItem('role', 'grader'); } diff --git a/lms/templates/view.html b/lms/templates/view.html index 2a7a211a..07564d68 100644 --- a/lms/templates/view.html +++ b/lms/templates/view.html @@ -142,6 +142,7 @@