From b24fda6970cb844bc80577b7c2a4279610a40abd Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 4 Sep 2022 11:43:36 +0100 Subject: [PATCH] . --- sbas/templates/sbas/exam_take.html | 275 ++++++++++++++++++++--------- 1 file changed, 192 insertions(+), 83 deletions(-) diff --git a/sbas/templates/sbas/exam_take.html b/sbas/templates/sbas/exam_take.html index e2791abc..6d9db8ea 100755 --- a/sbas/templates/sbas/exam_take.html +++ b/sbas/templates/sbas/exam_take.html @@ -1,104 +1,213 @@ {% extends 'base.html' %} {% block content %} -CID: {{cid}} -
-

{{exam.name}}: Question [{{pos|add:1}}/{{exam_length}}]

- {% if exam.publish_results %} - + {% if request.user.is_authenticated %} + User: {{request.user}} + {% else %} + CID: {{cid}} {% endif %} - -
-

{{question.stem|safe}}

+
+ Allocated time over.
-
    -
  • {{question.a_answer|safe}}
  • -
  • {{question.b_answer|safe}}
  • -
  • {{question.c_answer|safe}}
  • -
  • {{question.d_answer|safe}}
  • -
  • {{question.e_answer|safe}}
  • -
- - -
- -
{% csrf_token %} -
- {{form}} +
+ Time remaining: + {% comment %}
+ +
Days
+
{% endcomment %} +
+ + Hours +
+
+ + Minutes +
+
+ + Seconds +
+
+
+

{{exam.name}}: Question [{{pos|add:1}}/{{exam_length}}]

+ {% if exam.publish_results %} + + {% endif %} - {% if previous > -1 %} - - {% endif %} - {% if next %} - - {% else %} - {% if not exam.publish_results %} - - {% endif %} - {% endif %} +
+

{{question.stem|safe}}

+
+
    +
  • {{question.a_answer|safe}}
  • +
  • {{question.b_answer|safe}}
  • +
  • {{question.c_answer|safe}}
  • +
  • {{question.d_answer|safe}}
  • +
  • {{question.e_answer|safe}}
  • +
- {% if exam.publish_results and question.feedback %} -

Feedback

-

{{question.feedback|safe}}

- {% endif %} -
- - - + +
+ +
{% csrf_token %} +
+ {{form}} +
+ + {% if previous > -1 %} + + {% endif %} + {% if next %} + + {% else %} + {% if not exam.publish_results %} + + {% endif %} + {% endif %} + + {% if exam.publish_results and question.feedback %} +

Feedback

+

{{question.feedback|safe}}

+ {% endif %} +
+ + +
+
-
-

Questions

- {% endblock %} {% block js %} - + $("ul.sba-answer-list li").each((n, el) => { + $(el).click((e) => { + $("#id_answer").val(el.dataset.ans); + $("ul.sba-answer-list li").removeClass("selected"); + $(el).addClass("selected") + }) + }) + {% else %} + $("ul.sba-answer-list li[data-ans='{{question.best_answer}}']").addClass("correct"); + {% endif %} + + {% if saved_answer %} + $("ul.sba-answer-list li[data-ans='{{saved_answer}}']").addClass("selected"); {% endif %} + + for (let i = 0; i < {{ exam_length }}; i++) { + $("#menu-list").append($( + ``)); + + } + $("button.question-menu-item").on("click", (e) => { + console.log(e.currentTarget.dataset.qn); + document.getElementById("goto-button").value = e.currentTarget.dataset.qn; + $("#goto-button").click(); + }); + + + function getTimeRemaining(endtime) { + const total = Date.parse(endtime) - Date.parse(new Date()); + const seconds = Math.floor((total / 1000) % 60); + const minutes = Math.floor((total / 1000 / 60) % 60); + const hours = Math.floor((total / (1000 * 60 * 60)) % 24); + //const days = Math.floor(total / (1000 * 60 * 60 * 24)); + + return { + total, + //days, + hours, + minutes, + seconds + }; + } + + function initializeClock(id, endtime) { + console.log("Start clock", endtime) + const clock = document.getElementById(id); + clock.style.display = "block" + const daysSpan = clock.querySelector('.days'); + const hoursSpan = clock.querySelector('.hours'); + const minutesSpan = clock.querySelector('.minutes'); + const secondsSpan = clock.querySelector('.seconds'); + + function updateClock() { + const t = getTimeRemaining(endtime); + + //daysSpan.innerHTML = t.days; + hoursSpan.innerHTML = ('0' + t.hours).slice(-2); + minutesSpan.innerHTML = ('0' + t.minutes).slice(-2); + secondsSpan.innerHTML = ('0' + t.seconds).slice(-2); + + if (t.total <= 0) { + clearInterval(timeinterval); + timeup.style.display = "block" + clock.style.display = "none" + } + } + + const timeinterval = setInterval(updateClock, 1000); + updateClock(); + } + /* beautify ignore:end */ + }) + {% endblock %} {% block css %} - + .selected { + border: 1px solid purple; + } + + #clockdiv{ + font-family: sans-serif; + display: inline-block; + font-weight: 100; + text-align: center; + font-size: 12px; + display: none; + color: darkgray; + } + + #clockdiv > div{ + padding: 1px; + border-radius: 3px; + {% comment %} background: purple; {% endcomment %} + display: inline-block; + } + #clockdiv div > span.num{ + color: white; + padding: 1px; + border-radius: 3px; + display: inline-block; + } + + #timeup { + display: none; + color: red; + font-weight: 100; + text-align: center; + font-size: 12px; + } + {% endblock %} \ No newline at end of file