Skip to content

Commit

Permalink
reset table to empty look if row becomes empty during updates
Browse files Browse the repository at this point in the history
 * fixes bug 955706

Change-Id: Icb4190ce8cf20e3375c237f6729c64cb17f404e1
  • Loading branch information
andycjw committed Mar 17, 2012
1 parent baf6662 commit 5ab5d28
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
25 changes: 23 additions & 2 deletions horizon/static/horizon/js/horizon.js
Expand Up @@ -75,7 +75,8 @@ var Horizon = function() {
}
// Trigger the update handlers.
$rows_to_update.each(function(index, row) {
var $row = $(this);
var $row = $(this),
$table = $row.closest('table');
$.ajax($row.attr('data-update-url'), {
complete: function (jqXHR, status) {
var $new_row = $(jqXHR.responseText);
Expand All @@ -86,6 +87,26 @@ var Horizon = function() {
// Preserve the checkbox if it's already clicked
$new_row.find(':checkbox').prop('checked', true);
}
if($new_row.length == 0) {
// Update the footer count and reset to default empty row if needed
var $footer = $table.find('tr:last');

// remove one row from existing count
var row_count = $table.find('tbody tr').length -1;
var footer_text = "Displaying " + row_count + " item";

if(row_count > 1) { footer_text += 's'; }
$footer.find('span').text(footer_text);

if(row_count == 0) {
var colspan = $footer.find('td').attr('colspan'),
template = horizon.templates.compiled_templates["#empty_row_template"],
params = {colspan: colspan},
empty_row = $(template.render(params));

$new_row = $(empty_row);
}
}
$row.replaceWith($new_row);
$table.removeAttr('decay_constant');
}
Expand Down Expand Up @@ -168,7 +189,7 @@ var Horizon = function() {

/* Namespace for core functionality related to client-side templating. */
horizon.templates = {
template_ids: ["#modal_template"],
template_ids: ["#modal_template", "#empty_row_template"],
compiled_templates: {}
};

Expand Down
10 changes: 10 additions & 0 deletions horizon/templates/horizon/client_side/_table_row.html
@@ -0,0 +1,10 @@
{% extends "horizon/client_side/template.html" %}
{% load horizon %}

{% block id %}empty_row_template{% endblock %}

{% block template %}
{% jstemplate %}
<tr class="odd empty"><td colspan="[[colspan]]">No items to display.</td></tr>
{% endjstemplate %}
{% endblock %}
1 change: 1 addition & 0 deletions openstack_dashboard/templates/base.html
Expand Up @@ -27,6 +27,7 @@
{% block js %}
{% include "_scripts.html" %}
{% include "horizon/client_side/_modal.html" %}
{% include "horizon/client_side/_table_row.html" %}
{% endblock %}
</body>
</html>

0 comments on commit 5ab5d28

Please sign in to comment.