.
This commit is contained in:
@@ -480,4 +480,37 @@ function create_popup_window(url, title) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window.create_popup_window = create_popup_window
|
||||
window.create_popup_window = create_popup_window
|
||||
|
||||
window.delete_multiple(url, csrf_token) {
|
||||
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
if (confirm(`Delete ${answer_ids.length} answers?`)) {
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: {
|
||||
csrfmiddlewaretoken: csrf_token,
|
||||
answer_ids: JSON.stringify(answer_ids) // true if checked else false
|
||||
},
|
||||
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") {
|
||||
toastr.info('Deleted.')
|
||||
}
|
||||
// show some message according to the response.
|
||||
// For eg. A message box showing that the status has been changed
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,11 +21,6 @@
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("table thead th input").click((e) => {
|
||||
let status = e.currentTarget.checked; console.log(status, $("table tbody input")); $("table tbody input").prop("checked", status);
|
||||
})
|
||||
//$("thead input:checked").each((n, el) => {
|
||||
|
||||
$("#delete-selected-button").on("click", function () {
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
<div id="view-filter-options">
|
||||
<h3>Filter User Answers</h3>
|
||||
<form action="" method="get">
|
||||
{{ filter.form }}
|
||||
<input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
|
||||
</form>
|
||||
<form action="" method="get">
|
||||
{{ filter.form }}
|
||||
<input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
{% render_table table %}
|
||||
<button id="delete-selected-button">Delete selected answers</button>
|
||||
@@ -21,38 +21,9 @@
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
//$("thead input:checked").each((n, el) => {
|
||||
|
||||
$("#delete-selected-button").on("click", function () {
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
if (confirm(`Delete ${answer_ids.length} answers?`)) {
|
||||
$.ajax({
|
||||
url: "{% url 'longs:user_answer_delete_multiple' %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
answer_ids: JSON.stringify(answer_ids) // true if checked else false
|
||||
},
|
||||
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") {
|
||||
toastr.info('Deleted.')
|
||||
}
|
||||
// show some message according to the response.
|
||||
// For eg. A message box showing that the status has been changed
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
})
|
||||
}
|
||||
})
|
||||
$("#delete-selected-button").on("click", window.delete_multiple(
|
||||
"{% url 'longs:user_answer_delete_multiple' %}", "{{ csrf_token }}"
|
||||
))
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -21,11 +21,6 @@
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("table thead th input").click((e) => {
|
||||
let status = e.currentTarget.checked; console.log(status, $("table tbody input")); $("table tbody input").prop("checked", status);
|
||||
})
|
||||
//$("thead input:checked").each((n, el) => {
|
||||
|
||||
$("#delete-selected-button").on("click", function () {
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
|
||||
@@ -21,11 +21,6 @@
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("table thead th input").click((e) => {
|
||||
let status = e.currentTarget.checked; console.log(status, $("table tbody input")); $("table tbody input").prop("checked", status);
|
||||
})
|
||||
//$("thead input:checked").each((n, el) => {
|
||||
|
||||
$("#delete-selected-button").on("click", function () {
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
|
||||
+34
-1
@@ -480,4 +480,37 @@ function create_popup_window(url, title) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window.create_popup_window = create_popup_window
|
||||
window.create_popup_window = create_popup_window
|
||||
|
||||
window.delete_multiple(url, csrf_token) {
|
||||
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
if (confirm(`Delete ${answer_ids.length} answers?`)) {
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: {
|
||||
csrfmiddlewaretoken: csrf_token,
|
||||
answer_ids: JSON.stringify(answer_ids) // true if checked else false
|
||||
},
|
||||
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") {
|
||||
toastr.info('Deleted.')
|
||||
}
|
||||
// show some message according to the response.
|
||||
// For eg. A message box showing that the status has been changed
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user