This commit is contained in:
Ross
2022-07-31 18:55:06 +01:00
parent 523d50cce4
commit be70054cf7
10 changed files with 142 additions and 72 deletions
+55 -51
View File
@@ -35,6 +35,7 @@
<button id="deactivate-selected-cids">Deactivate selected</button>
<button id="delete-selected-cids">Delete selected</button>
<button id="toggle-internal">Toggle internal</button>
<button id="add-group">Add Group to users</button>
<p>Select exams below to add user(s) to (or edit existing user(s)).</p>
<div class="exam-selectors">
<span>
@@ -103,12 +104,12 @@
{% endfor %}
</select>
<button id="add-group">Add Group to users</button>
</div>
<button id="add-new-cids">Add New (Blank) Users</button>
<h3>Create New Users</h3>
<button id="add-new-cids" title="This will create N new users">Add New (Blank) Users</button>
<input type="number" id="add-number" value="number to add"><br />
<button id="add-new-emails">Add New Users From Email</button>
<textarea id="emails-input" name="emails" rows="4" cols="50">Enter emails here</textarea>
<button id="add-new-emails" title="This will create users from a list of email addresses">Add New Users From Email</button>
<textarea id="emails-input" name="emails" rows="4" cols="50" placeholder="Enter emails here (single email per line)"></textarea>
</details>
{% endblock %}
@@ -116,51 +117,51 @@
{% block js %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.11.3/r-2.2.9/datatables.min.css"/>
{% comment %} <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.11.3/r-2.2.9/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.11.3/r-2.2.9/datatables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.11.3/r-2.2.9/datatables.min.js"></script> {% endcomment %}
<script>
jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) {
var esc = function ( t ) {
return t
.replace( /&/g, '&amp;' )
.replace( /</g, '&lt;' )
.replace( />/g, '&gt;' )
.replace( /"/g, '&quot;' );
};
// jQuery.fn.dataTable.render.ellipsis = function ( cutoff, wordbreak, escapeHtml ) {
//var esc = function ( t ) {
//return t
//.replace( /&/g, '&amp;' )
//.replace( /</g, '&lt;' )
//.replace( />/g, '&gt;' )
//.replace( /"/g, '&quot;' );
//};
return function ( d, type, row ) {
// Order, search and type get the original data
if ( type !== 'display' ) {
return d;
}
//return function ( d, type, row ) {
//// Order, search and type get the original data
//if ( type !== 'display' ) {
//return d;
//}
if ( typeof d !== 'number' && typeof d !== 'string' ) {
return d;
}
//if ( typeof d !== 'number' && typeof d !== 'string' ) {
//return d;
//}
d = d.toString(); // cast numbers
//d = d.toString(); // cast numbers
if ( d.length <= cutoff ) {
return d;
}
//if ( d.length <= cutoff ) {
//return d;
//}
var shortened = d.substr(0, cutoff-1);
//var shortened = d.substr(0, cutoff-1);
// Find the last white space character in the string
if ( wordbreak ) {
shortened = shortened.replace(/\s([^\s]*)$/, '');
}
//// Find the last white space character in the string
//if ( wordbreak ) {
//shortened = shortened.replace(/\s([^\s]*)$/, '');
//}
// Protect against uncontrolled HTML input
if ( escapeHtml ) {
shortened = esc( shortened );
}
//// Protect against uncontrolled HTML input
//if ( escapeHtml ) {
//shortened = esc( shortened );
//}
return '<span class="ellipsis" title="'+esc(d)+'">'+shortened+'&#8230;</span>';
};
};
//return '<span class="ellipsis" title="'+esc(d)+'">'+shortened+'&#8230;</span>';
//};
//};
function postAjax(data) {
@@ -177,6 +178,8 @@
if (data.status == "success") {
toastr.info('Added/Updated');
location.reload();
} else {
toastr.error(data.details)
}
// show some message according to the response.
// For eg. A message box showing that the status has been changed
@@ -215,19 +218,19 @@
$(document).ready(function () {
{% if exams %}
$("table").DataTable({
columnDefs: [ {
targets: [6,7,8,9,10],
render: $.fn.dataTable.render.ellipsis( 17, true )
} ],
"paging": false,
});
{% else %}
$("table").DataTable({
"paging": false,
});
{% endif %}
// {% if exams %}
//$("table").DataTable({
//columnDefs: [ {
//targets: [6,7,8,9,10],
//render: $.fn.dataTable.render.ellipsis( 17, true )
//} ],
//"paging": false,
//});
//{% else %}
//$("table").DataTable({
//"paging": false,
//});
//{% endif %}
$("#toggle-internal").click((evt) => {
data = getGenericData();
@@ -237,6 +240,7 @@
$("#add-new-emails").click((evt) => {
data = getGenericData();
data["emails"] = JSON.stringify($("#emails-input").val());
data["add_new_emails"] = true;
postAjax(data);
});
$("#add-group").click((evt) => {
@@ -39,7 +39,7 @@
})
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
.done(function (data) {
console.log(data);
console.log("done", data);
if (data.status == "success") {
if (data.added) {
@@ -50,7 +50,14 @@
toastr.info(`User ${el.target.dataset.cid} removed from exam`)
}
} else {
toastr.error(data.status)
}
})
.fail(function (data) {
console.log("fail", data);
toastr.error(data.responseJSON.status)
})
.always(function () {
})