diff options
author | Prabhu Ramachandran | 2018-01-15 12:23:52 +0530 |
---|---|---|
committer | GitHub | 2018-01-15 12:23:52 +0530 |
commit | 1445358b4ee548edd16a8d42026b080b7d92a0c4 (patch) | |
tree | 99b437d71f841cb1ac9f26266d7e7de04031f340 /yaksh/static | |
parent | 3abbc557c57eaf2f3d08222034f9a720a1e7a1ed (diff) | |
parent | ef22478a11d518982f38a6a0d4d84f6f8ba5e492 (diff) | |
download | online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.tar.gz online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.tar.bz2 online_test-1445358b4ee548edd16a8d42026b080b7d92a0c4.zip |
Merge pull request #422 from adityacp/show_course_status
Show course status
Diffstat (limited to 'yaksh/static')
-rw-r--r-- | yaksh/static/yaksh/js/course.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/yaksh/static/yaksh/js/course.js b/yaksh/static/yaksh/js/course.js index f0d03e2..1c64a3e 100644 --- a/yaksh/static/yaksh/js/course.js +++ b/yaksh/static/yaksh/js/course.js @@ -66,4 +66,79 @@ $("#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", '').replace("View Units", ""); // escape double quotes
+
+ }
+}
+
+
+$("#export").click(function (event) {
+ var outputFile = $("#course_name").val().replace(" ", "_") + '.csv';
+
+ exportTableToCSV.apply(this, [$('#course_table'), outputFile]);
});
+
+// Table sorter for course details
+$("table").tablesorter({});
+
+});
+
+function view_status(unit){
+ title_list = $(unit).attr("title").split("/");
+ $(unit).attr("title", title_list.join("\n"));
+}
|