Commit 3e4edf40 by Tim Krones

Hide results table if no data is available.

parent b9ebeee6
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
.data-export-field-container { .data-export-field-container {
margin-bottom: 1em; margin-bottom: 1em;
} }
.data-export-results {
display: none;
}
.data-export-results table { .data-export-results table {
margin-top: 1em; margin-top: 1em;
border: 2px solid gray; border: 2px solid gray;
......
...@@ -13,6 +13,7 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -13,6 +13,7 @@ function StudentAnswersDashboardBlock(runtime, element) {
var $blockTypes = $element.find("select[name='block_types']"); var $blockTypes = $element.find("select[name='block_types']");
var $rootBlockId = $element.find("input[name='root_block_id']"); var $rootBlockId = $element.find("input[name='root_block_id']");
var $username = $element.find("input[name='username']"); var $username = $element.find("input[name='username']");
var $resultTable = $element.find('.data-export-results');
var status; var status;
function getStatus() { function getStatus() {
...@@ -45,6 +46,20 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -45,6 +46,20 @@ function StudentAnswersDashboardBlock(runtime, element) {
); );
} }
function hideResults() {
$resultTable.hide();
}
function showResults() {
$resultTable.show();
}
function maybeShowResults() {
if (status.last_export_result) {
showResults();
}
}
function handleError(data) { function handleError(data) {
// Shim to make the XBlock JsonHandlerError response work with our format. // Shim to make the XBlock JsonHandlerError response work with our format.
status = {'last_export_result': JSON.parse(data.responseText), 'export_pending': false}; status = {'last_export_result': JSON.parse(data.responseText), 'export_pending': false};
...@@ -87,9 +102,9 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -87,9 +102,9 @@ function StudentAnswersDashboardBlock(runtime, element) {
} }
// Display results // Display results
var $resultTable = $('.data-export-results table tbody'); var $resultTableBody = $resultTable.find('tbody');
$resultTable.empty(); $resultTableBody.empty();
_.each(status.last_export_result.display_data, function(row) { _.each(status.last_export_result.display_data, function(row) {
...@@ -99,9 +114,11 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -99,9 +114,11 @@ function StudentAnswersDashboardBlock(runtime, element) {
tr.append($('<td>').text(cell)); tr.append($('<td>').text(cell));
}); });
$resultTable.append(tr); $resultTableBody.append(tr);
}); });
showResults();
} else { } else {
if (status.export_pending) { if (status.export_pending) {
$statusArea.append($('<p>').text( $statusArea.append($('<p>').text(
...@@ -144,6 +161,10 @@ function StudentAnswersDashboardBlock(runtime, element) { ...@@ -144,6 +161,10 @@ function StudentAnswersDashboardBlock(runtime, element) {
addHandler($cancelButton, 'cancel_export'); addHandler($cancelButton, 'cancel_export');
addHandler($deleteButton, 'delete_export'); addHandler($deleteButton, 'delete_export');
$startButton.on('click', hideResults);
$cancelButton.on('click', maybeShowResults);
$deleteButton.on('click', hideResults);
$downloadButton.on('click', function() { $downloadButton.on('click', function() {
window.location.href = status.download_url; window.location.href = status.download_url;
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment