Skip to content
Snippets Groups Projects
Commit dd589406 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Work on Behaviour table

parent af971c6e
No related branches found
No related tags found
No related merge requests found
......@@ -35,81 +35,6 @@
</div>
*/
// Behaviour page script modifications
if (window.location.href.endsWith("/Behaviour")) {
console.log("[RB9] Override function handlers");
// copied from https://vle.bromcomcloud.com/lib/pages/js/behaviour.js
var toCamelCase = (str) => {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
return index == 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}
// copied from https://vle.bromcomcloud.com/lib/pages/js/behaviour.js
var loadBehaviourTable = () => {
$(".wait").show();
$.ajax({
url: "/Behaviour/StudentBehaviour",
type: "Post",
data: null,
contentType: false,
processData: false,
cache: false,
success: function (data) {
console.log(data);
$(".wait").hide();
var content = "";
var headerContent = "";
if (data.behaviourStudentEventHeader.length > 0) {
headerContent += "<tr>"
for (var i = 0; i < data.behaviourStudentEventHeader.length; i++) {
headerContent += "<th>" + data.behaviourStudentEventHeader[i].displayName.replace(/([A-Z])/g, ' $1').trim() + "</th>"
}
headerContent += "</tr>"
}
if (data.studentEvents.length > 0) {
for (var i = 0; i < data.studentEvents.length; i++) {
content += "<tr>"
for (var j = 0; j < data.behaviourStudentEventHeader.length; j++) {
content += '<td>' +
data.studentEvents[i][toCamelCase(data.behaviourStudentEventHeader[j].fieldName = data.behaviourStudentEventHeader[j].fieldName == "" ? data.behaviourStudentEventHeader[j].displayName : data.behaviourStudentEventHeader[j].fieldName)] + '</td>';
}
content += "</tr>"
}
}
$('#Behaviour thead').empty();
$('#Behaviour tbody').empty();
$('#Behaviour thead').html(headerContent);
$('#Behaviour tbody').html(content);
$.fn.dataTable.moment('DD/MM/YYYY HH:mm');
$('#Behaviour').DataTable({
"bPaginate": false,
columnDefs: [{
target: [0],
type: 'datetime-moment'
}],
"order": [[0,'desc']],
"fnDrawCallback": function () {
$('th').each(function () {
if (($(this).hasClass('sorting')) || ($(this).hasClass('sorting_desc'))) {
$(this).attr({ title: 'Sort Ascending' });
} else {
$(this).attr({ title: 'Sort Descending' });
}
});
}
});
},
error: function (msg) {
$(".wait").hide();
}
});
}
}
(function() {
'use strict';
function formatDate(date) {
......@@ -187,4 +112,131 @@ if (window.location.href.endsWith("/Behaviour")) {
});
});
}
// Behaviour page script modifications
if (window.location.href.endsWith("/Behaviour")) {
console.log("[RB9] Behaviour function handlers");
// copied from https://vle.bromcomcloud.com/lib/pages/js/behaviour.js
var toCamelCase = (str) => {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
return index == 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
}
// copied from https://vle.bromcomcloud.com/lib/pages/js/behaviour.js
var loadBehaviourTable = () => {
$(".wait").show();
$.ajax({
url: "/Behaviour/StudentBehaviour",
type: "Post",
data: null,
contentType: false,
processData: false,
cache: false,
success: function (data) {
console.log(data);
$(".wait").hide();
var content = "";
var headerContentArr = [].concat(data.behaviourStudentEventHeader);
var lastPositionFromTop = 1;
if (headerContentArr.length > 0) {
lastPositionFromTop = headerContentArr[headerContentArr - 1].positionFromTop;
}
// Collect list of all field names
var headerContentArrKeys = [];
for(var j = 0; j < headerContentArr.length; j++) {
var cc = toCamelCase(data.behaviourStudentEventHeader[j].fieldName = data.behaviourStudentEventHeader[j].fieldName == "" ? data.behaviourStudentEventHeader[j].displayName : data.behaviourStudentEventHeader[j].fieldName);
headerContentArrKeys.push(cc);
}
console.log("[RB9] Existing field names: ");
console.log(headerContentArrKeys);
// Append any non-existing contents to header
if (data.studentEvents.length > 0) {
var headerFirstObjectKeys = Object.keys(data.studentEvents[0]);
for(var i = 0; i < headerFirstObjectKeys.length; i++) {
var key = headerFirstObjectKeys[i];
if(!headerContentArrKeys.includes(key)) {
var data = {
active: "True",
fieldName: key,
displayName: key,
positionFromTop: lastPositionFromTop
};
headerContentArrKeys.push(data);
console.log("[RB9] " + JSON.stringify(data));
lastPositionFromTop++;
}
}
}
var headerContent = "";
headerContent += "<tr>"
for (var i = 0; i < headerContentArr.length; i++) {
headerContent += "<th>" + headerContentArr[i].displayName.replace(/([A-Z])/g, ' $1').trim() + "</th>"
}
headerContent += "</tr>"
if (data.studentEvents.length > 0) {
for (var i = 0; i < data.studentEvents.length; i++) {
content += "<tr>"
for (var j = 0; j < data.behaviourStudentEventHeader.length; j++) {
content += '<td>' +
data.studentEvents[i][toCamelCase(data.behaviourStudentEventHeader[j].fieldName = data.behaviourStudentEventHeader[j].fieldName == "" ? data.behaviourStudentEventHeader[j].displayName : data.behaviourStudentEventHeader[j].fieldName)] + '</td>';
}
content += "</tr>"
}
}
$('#Behaviour thead').empty();
$('#Behaviour tbody').empty();
$('#Behaviour thead').html(headerContent);
$('#Behaviour tbody').html(content);
$.fn.dataTable.moment('DD/MM/YYYY HH:mm');
$('#Behaviour').DataTable({
"bPaginate": false,
columnDefs: [{
target: [0],
type: 'datetime-moment'
}],
"order": [[0,'desc']],
"fnDrawCallback": function () {
$('th').each(function () {
if (($(this).hasClass('sorting')) || ($(this).hasClass('sorting_desc'))) {
$(this).attr({ title: 'Sort Ascending' });
} else {
$(this).attr({ title: 'Sort Descending' });
}
});
}
});
},
error: function (msg) {
$(".wait").hide();
}
});
}
console.log("[RB9] Destroying existing table.")
$("#Behaviour").empty();
//if($.fn.DataTable.isDataTable("#Behaviour")) {
//}
console.log("[RB9] Creating new table.")
// <table id="Behaviour" class="DataTable table table-theme dataTable"><thead></thead><tbody></tbody></table>
$("#BehaviourDiv").append(
"<table id=\"Behaviour\" class=\"DataTable table table-theme\">" +
"<thead></thead>" +
"<tbody></tbody>" +
"</table>");
loadBehaviourTable();
}
})();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment