.
This commit is contained in:
@@ -4,15 +4,15 @@
|
||||
<ol>
|
||||
{% for cid in current_cid_users %}
|
||||
|
||||
<li><a href="{% url 'generic:update_cid' cid.pk %}">{{cid.cid}}</a> [{{cid.passcode}}] {{cid.name}} /
|
||||
Email: {{cid.email}} <button class="toggle-btn current" data-pk="{{cid.pk}}">Toggle<button>
|
||||
<li class="current"><a href="{% url 'generic:update_cid' cid.pk %}">{{cid.cid}}</a> [{{cid.passcode}}] {{cid.name}} /
|
||||
Email: {{cid.email}} <button class="toggle-btn" data-pk="{{cid.pk}}" data-cid="{{cid.cid}}">Toggle</button>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
{% for cid in available_cid_users %}
|
||||
|
||||
<li><a href="{% url 'generic:update_cid' cid.pk %}">{{cid.cid}}</a> [{{cid.passcode}}] {{cid.name}} /
|
||||
Email: {{cid.email}} <button class="toggle-btn" data-pk="{{cid.pk}}">Toggle<button>
|
||||
Email: {{cid.email}} <button class="toggle-btn" data-pk="{{cid.pk}}">Toggle</button>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
@@ -24,7 +24,36 @@
|
||||
$(document).ready(() => {
|
||||
$(".toggle-btn").click((el) => {
|
||||
console.log(el);
|
||||
console.log(el.dataset.pk);
|
||||
console.log(el.target.dataset.pk);
|
||||
console.log(!el.target.parent.hasClass("current"));
|
||||
$.ajax({
|
||||
url: "{% url 'generic:generic_exam_json_edit' %}"",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{csrf_token}}",
|
||||
edit_cid_user: JSON.stringify(ids),
|
||||
add: !el.target.parent.hasClass("current"),
|
||||
exam_id: $(evt.target).data("exam-id"),
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
})
|
||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||
.done(function (data) {
|
||||
console.log(data);
|
||||
|
||||
if (data.status == "success") {
|
||||
if (data.added) {
|
||||
el.target.parent.addClass("current");
|
||||
toastr.info(`User ${el.target.dataset.cid} added to exam`)
|
||||
} else {
|
||||
el.target.parent.removedClass("current");
|
||||
toastr.info(`User ${el.target.dataset.cid} removed from exam`)
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
.always(function () {
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
+16
-3
@@ -673,10 +673,23 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
|
||||
exam = get_object_or_404(self.Exam, pk=pk)
|
||||
|
||||
if "edit_cid_users" in request.POST:
|
||||
user_ids = json.loads(request.POST.get("cid_user_ids"))
|
||||
if "toggle_cid_user" in request.POST:
|
||||
user_id = json.loads(request.POST.get("cid_user_id"))
|
||||
|
||||
add = request.POST.get("add")
|
||||
|
||||
data = {"status": "success"}
|
||||
cid_user = CidUser.objects.filter(pk=user_id)
|
||||
|
||||
app_exam_map = {}
|
||||
app_exam_map["rapids"] = cid_user.rapid_exams
|
||||
|
||||
if add:
|
||||
app_exam_map[self.app_name].add(pk)
|
||||
else:
|
||||
app_exam_map[self.app_name].remove(pk)
|
||||
|
||||
|
||||
data = {"status": "success", "added": add}
|
||||
return JsonResponse(data, status=200)
|
||||
|
||||
if "add_exam_questions" in request.POST:
|
||||
|
||||
Reference in New Issue
Block a user