summaryrefslogtreecommitdiff
path: root/yaksh/static
diff options
context:
space:
mode:
authoradityacp2018-01-12 17:44:01 +0530
committeradityacp2018-01-12 17:44:01 +0530
commitae15c16a7a94e86d6debf3cc385e24fecac889e2 (patch)
tree9dbe649be83559421a3fb1813a32d864fb987131 /yaksh/static
parent943d2c1f6d0a1f99ffc6e48bc0c82249e2d4d08c (diff)
downloadonline_test-ae15c16a7a94e86d6debf3cc385e24fecac889e2.tar.gz
online_test-ae15c16a7a94e86d6debf3cc385e24fecac889e2.tar.bz2
online_test-ae15c16a7a94e86d6debf3cc385e24fecac889e2.zip
Change in js, templates and custom_filters
- Add js function to download csv data for course status - Show course status - Add new custom functions to view student status for a course
Diffstat (limited to 'yaksh/static')
-rw-r--r--yaksh/static/yaksh/js/course.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/yaksh/static/yaksh/js/course.js b/yaksh/static/yaksh/js/course.js
index f0d03e2..162e0b8 100644
--- a/yaksh/static/yaksh/js/course.js
+++ b/yaksh/static/yaksh/js/course.js
@@ -66,4 +66,76 @@ $("#send_mail").click(function(){
return status;
});
+// Download course status as csv
+function exportTableToCSV($table, filename) {
+ var $headers = $table.find('tr:has(th)')
+ ,$rows = $table.find('tr:has(td)')
+
+ // Temporary delimiter characters unlikely to be typed by keyboard
+ // This is to avoid accidentally splitting the actual contents
+ ,tmpColDelim = String.fromCharCode(11) // vertical tab character
+ ,tmpRowDelim = String.fromCharCode(0) // null character
+
+ // actual delimiter characters for CSV format
+ ,colDelim = '","'
+ ,rowDelim = '"\r\n"';
+
+ // Grab text from table into CSV formatted string
+ var csv = '"';
+ csv += formatRows($headers.map(grabRow));
+ csv += rowDelim;
+ csv += formatRows($rows.map(grabRow)) + '"';
+
+ // Data URI
+ var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
+
+ // For IE (tested 10+)
+ if (window.navigator.msSaveOrOpenBlob) {
+ var blob = new Blob([decodeURIComponent(encodeURI(csv))], {
+ type: "text/csv;charset=utf-8;"
+ });
+ navigator.msSaveBlob(blob, filename);
+ } else {
+ $(this)
+ .attr({
+ 'download': filename,'href': csvData
+ });
+ }
+
+ function formatRows(rows){
+ return rows.get().join(tmpRowDelim)
+ .split(tmpRowDelim).join(rowDelim)
+ .split(tmpColDelim).join(colDelim);
+ }
+ // Grab and format a row from the table
+ function grabRow(i,row){
+ var $row = $(row);
+ var $cols = $row.find('td');
+ if(!$cols.length) $cols = $row.find('th');
+
+ return $cols.map(grabCol)
+ .get().join(tmpColDelim);
+ }
+ // Grab and format a column from the table
+ function grabCol(j,col){
+ var $col = $(col),
+ $text = $col.text();
+
+ return $text.replace('"', '""').replace("View Unit Status", ''); // escape double quotes
+
+ }
+}
+
+
+$("#export").click(function (event) {
+ var outputFile = $("#course_name").val().replace(" ", "_") + '.csv';
+
+ exportTableToCSV.apply(this, [$('#course_table'), outputFile]);
+});
+
});
+
+function view_status(unit){
+ title_list = $(unit).attr("title").split("/");
+ $(unit).attr("title", title_list.join("\n"));
+}