diff --git a/generic/templates/generic/exam_cids_edit.html b/generic/templates/generic/exam_cids_edit.html index 2e2527b4..15d9f35e 100644 --- a/generic/templates/generic/exam_cids_edit.html +++ b/generic/templates/generic/exam_cids_edit.html @@ -94,53 +94,53 @@ type: "POST", dataType: "json", }) - .done(function (data) { - if (data.status == "success") { - if (data.added) { - parentLi.addClass('current'); - toastr.info(`User ${btn.dataset.cid} added to exam`) + .done(function (data) { + if (data.status == "success") { + if (data.added) { + parentLi.addClass('current'); + toastr.info(`User ${btn.dataset.cid} added to exam`) + } else { + parentLi.removeClass('current'); + toastr.info(`User ${btn.dataset.cid} removed from exam`) + } } else { - parentLi.removeClass('current'); - toastr.info(`User ${btn.dataset.cid} removed from exam`) + toastr.error(data.status) } - } else { - toastr.error(data.status) - } - }) - .fail(function (data) { - toastr.error((data && data.responseJSON && data.responseJSON.status) ? data.responseJSON.status : 'Request failed'); - }); + }) + .fail(function (data) { + toastr.error((data && data.responseJSON && data.responseJSON.status) ? data.responseJSON.status : 'Request failed'); + }); }); }); // Sorting - let currentSort = { key: 'cid', dir: 'asc' }; - function updateCarets() { - $('.sort-btn').each(function(){ - const key = $(this).data('key'); - const caret = $(this).find('.sort-caret'); - caret.text(''); - if (currentSort.key === key) caret.text(currentSort.dir === 'asc' ? ' ▲' : ' ▼'); - }); - } - function sortList(key) { - const $ul = $('#cid-users-list'); - const items = $ul.children('li').get(); - const dir = (currentSort.key === key && currentSort.dir === 'asc') ? 'desc' : 'asc'; - items.sort(function(a,b){ - const va = ($(a).data(key) || '').toString().toLowerCase(); - const vb = ($(b).data(key) || '').toString().toLowerCase(); - if (va < vb) return dir === 'asc' ? -1 : 1; - if (va > vb) return dir === 'asc' ? 1 : -1; - return 0; - }); + let currentSort = { key: 'cid', dir: 'asc' }; + function updateCarets() { + $('.sort-btn').each(function(){ + const key = $(this).data('key'); + const caret = $(this).find('.sort-caret'); + caret.text(''); + if (currentSort.key === key) caret.text(currentSort.dir === 'asc' ? ' ▲' : ' ▼'); + }); + } + function sortList(key) { + const $ul = $('#cid-users-list'); + const items = $ul.children('li').get(); + const dir = (currentSort.key === key && currentSort.dir === 'asc') ? 'desc' : 'asc'; + items.sort(function(a,b){ + const va = ($(a).data(key) || '').toString().toLowerCase(); + const vb = ($(b).data(key) || '').toString().toLowerCase(); + if (va < vb) return dir === 'asc' ? -1 : 1; + if (va > vb) return dir === 'asc' ? 1 : -1; + return 0; + }); // re-append - for (let i=0;i