Skip to content

Commit

Permalink
Better datechecker
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Sadrieh committed Aug 12, 2024
1 parent 709d313 commit c6d4b54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
8 changes: 3 additions & 5 deletions evap/staff/templates/staff_semester_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,9 @@ <h3 class="m-0 me-1">{{ semester.name }}</h3>
</div>
</div>

{% for evaluation in evaluations %}
<form id="exam_creation_form_{{ evaluation.id }}" reload-on-success method="post" action="{% url 'staff:create_exam_evaluation' %}">
{% csrf_token %}
</form>
{% endfor %}
<form id="exam_creation_form" reload-on-success method="post" action="{% url 'staff:create_exam_evaluation' %}">
{% csrf_token %}
</form>

<form id="evaluation-deletion-form" custom-success method="POST" action="{% url 'staff:evaluation_delete' %}">
{% csrf_token %}
Expand Down
29 changes: 6 additions & 23 deletions evap/staff/templates/staff_semester_view_evaluation.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<span class="fas fa-copy"></span>
</a>
{% if not evaluation.has_exam %}
<confirmation-modal type="submit" id="exam_creation_modal" name="evaluation_id" value="{{ evaluation.id }}" confirm-button-class="btn-primary" form="exam_creation_form_{{ evaluation.id }}">
<confirmation-modal type="submit" name="evaluation_id" value="{{ evaluation.id }}" confirm-button-class="btn-primary" form="exam_creation_form">
<span slot="title">{% translate 'Create exam evaluation' %}</span>
<span slot="action-text" id="submit_button">{% translate 'Create exam evaluation' %}</span>
<span slot="question">
Expand All @@ -199,16 +199,18 @@
{% endblocktranslate %}
</span>
<div slot="extra-inputs">
<label for="exam_date">{% translate 'Exam Date:' %}</label>
<input type="date" id="exam_date" name="exam_date" data-must-before="{{ evaluation.vote_start_datetime }}" class="form-control" required form="exam_creation_form_{{ evaluation.id }}"/>
<label>
{% translate 'Exam Date:' %}
<input type="date" name="exam_date" evaluationDate="{{ evaluation.vote_start_datetime }}" class="form-control" required form="exam_creation_form"/>
</label>
</div>

<button slot="show-button" type="button" class="btn btn-sm btn-light" title="{% translate 'Create exam evaluation' %}" data-bs-placement="top" data-bs-toggle="tooltip"><span class="fas fa-file-pen fa-fw"></span></button>

<script type="text/javascript">
document.getElementById('submit_button').addEventListener('click', function(event) {
var inputDate = new Date(document.getElementById('exam_date').value);
var evaluationDate = new Date(document.getElementById('exam_date').dataset.mustBefore);
var evaluationDate = new Date(document.getElementById('exam_date').dataset.evaluationDate);

if (inputDate <= evaluationDate) {
document.getElementById('exam_date').setCustomValidity("{% translate 'The exam date is before the start date of the main evaluation.' %}");
Expand All @@ -218,25 +220,6 @@
});
</script>

<!-- <script type="text/javascript">
var examModal = document.currentScript.closest("confirmation-modal");
examModal.querySelectorAll("[data-evaluation-date]").forEach(element => {
element.addEventListener("click", () => {
var inputDate = new Date(element.value);
var evaluationDate = new Date(element.dataset.evaluationDate);
if (inputDate <= evaluationDate) {
element.setCustomValidity("{% translate 'The exam date is before the start date of the main evaluation.' %}");
} else {
element.setCustomValidity("");
}
element.reportValidity();
});
element.dispatchEvent(new Event("change"));
});
</script> -->

</confirmation-modal>
{% endif %}
{% endif %}
Expand Down

0 comments on commit c6d4b54

Please sign in to comment.