This commit is contained in:
Ross
2021-02-26 15:50:49 +00:00
parent 824735a755
commit 69e4cfa354
7 changed files with 91 additions and 64 deletions
+63
View File
@@ -71,6 +71,69 @@ $(document).ready(function () {
$(document).keydown(keyDownHandler);
$(document).keyup(keyUpHandler);
$("#button-select-add-exam").click(function (evt) {
// Find selected objects
var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) {
console.log(data);
data.forEach((obj, n) => {
$("#exam-options").append($(document.createElement('button')).prop({
type: 'button',
innerHTML: obj.name,
class: '',
}).data("exam-id", obj.id).click((evt) => { addToExam(evt) }))
})
})
.done(function () {
//alert( "second success" );
})
.fail(function () {
//alert( "error" );
})
.always(function () {
//alert( "finished" );
});
return;
function addToExam(evt) {
ids = []
$("table input:checked").each((n, el) => {
ids.push(el.value)
})
post_url = document.getElementById("button-select-add-exam").dataset.exam_json_edit_url;
type = document.getElementById("button-select-add-exam").dataset.type;
$.ajax({
url: post_url,
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
add_exam_questions: JSON.stringify(ids),
type: type,
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") {
toastr.info('Questions added to exams.')
}
})
.always(function () {
console.log('[Done]');
$("#exam-options").empty();
})
}
});
});