add some more detials to user management
This commit is contained in:
@@ -1,77 +1,85 @@
|
||||
|
||||
<h3>Users</h3>
|
||||
{% if groups %}
|
||||
Users from the following groups are available: {% for group in groups %}<a href='{{group.get_absolute_url}}'>{{group}}</a>, {% endfor %} .
|
||||
{% else %}
|
||||
This exam is not associated with any user groups. <a href="{% url exam.app_name|add:':exam_update' exam.pk %}">Edit and add a group</a> to enable user management.
|
||||
{% endif %}
|
||||
<ol>
|
||||
{% for user in current_user_users %}
|
||||
|
||||
<li class="current">{{user.username}} /
|
||||
Email: {{user.email}} <button class="toggle-btn" data-pk="{{user.pk}}" data-user="{{user.username}}">Toggle</button>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
{% for user in available_user_users %}
|
||||
|
||||
<li>{{user.username}} /
|
||||
Email: {{user.email}} <button class="toggle-btn" data-pk="{{user.pk}}" data-user="{{user.username}}">Toggle</button>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
</ol>
|
||||
<h3>Users</h3>
|
||||
{% if groups %}
|
||||
Users from the following groups are available: {% for group in groups %}<a href='{{group.get_absolute_url}}'>{{group}}</a>, {% endfor %} .
|
||||
{% else %}
|
||||
This exam is not associated with any user groups. <a href="{% url exam.app_name|add:':exam_update' exam.pk %}">Edit and add a group</a> to enable user management.
|
||||
{% endif %}
|
||||
<ol>
|
||||
{% for user in current_user_users %}
|
||||
|
||||
<p><button class="toggle-all-btn">Toggle all</button></p>
|
||||
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
$(".toggle-all-btn").click((el) => {
|
||||
$(".toggle-btn").click();
|
||||
});
|
||||
$(".toggle-btn").click((el) => {
|
||||
parent = $(el.target).parent()
|
||||
$.ajax({
|
||||
url: "{% url exam.app_name|add:':exam_json_edit' exam.pk %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{csrf_token}}",
|
||||
edit_user_user: el.target.dataset.pk,
|
||||
add: !parent.hasClass("current"),
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
})
|
||||
<li class="current">{{user.username}} /
|
||||
Email: {{user.email}}
|
||||
{% if user.userprofile.grade %}
|
||||
[{{user.userprofile.grade}}]
|
||||
{% endif %}
|
||||
<button class="toggle-btn" data-pk="{{user.pk}}" data-user="{{user.username}}">Toggle</button>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
{% for user in available_user_users %}
|
||||
|
||||
<li>{{user.username}} /
|
||||
Email: {{user.email}}
|
||||
{% if user.userprofile.grade %}
|
||||
[{{user.userprofile.grade}}]
|
||||
{% endif %}
|
||||
<button class="toggle-btn" data-pk="{{user.pk}}" data-user="{{user.username}}">Toggle</button>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
</ol>
|
||||
|
||||
<p><button class="toggle-all-btn">Toggle all</button></p>
|
||||
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
$(".toggle-all-btn").click((el) => {
|
||||
$(".toggle-btn").click();
|
||||
});
|
||||
$(".toggle-btn").click((el) => {
|
||||
parent = $(el.target).parent()
|
||||
$.ajax({
|
||||
url: "{% url exam.app_name|add:':exam_json_edit' exam.pk %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{csrf_token}}",
|
||||
edit_user_user: el.target.dataset.pk,
|
||||
add: !parent.hasClass("current"),
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
})
|
||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||
.done(function (data) {
|
||||
console.log(data);
|
||||
.done(function (data) {
|
||||
console.log(data);
|
||||
|
||||
if (data.status == "success") {
|
||||
if (data.added) {
|
||||
if (data.status == "success") {
|
||||
if (data.added) {
|
||||
parent.addClass("current");
|
||||
toastr.info(`User ${el.target.dataset.user} added to exam`)
|
||||
} else {
|
||||
} else {
|
||||
parent.removeClass("current");
|
||||
toastr.info(`User ${el.target.dataset.user} removed from exam`)
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
.always(function () {
|
||||
})
|
||||
}
|
||||
})
|
||||
.always(function () {
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
.current {
|
||||
color: lightgray;
|
||||
}
|
||||
.current::after {
|
||||
content: "[ADDED TO EXAM]"
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style>
|
||||
.current {
|
||||
color: lightgray;
|
||||
}
|
||||
.current::after {
|
||||
content: "[ADDED TO EXAM]"
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
button {
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user