From 5ab5d280312fd85f0cf0c9ce539e1b2b294d52bb Mon Sep 17 00:00:00 2001 From: Andy Chong Date: Thu, 15 Mar 2012 15:28:55 +0800 Subject: [PATCH] reset table to empty look if row becomes empty during updates * fixes bug 955706 Change-Id: Icb4190ce8cf20e3375c237f6729c64cb17f404e1 --- horizon/static/horizon/js/horizon.js | 25 +++++++++++++++++-- .../horizon/client_side/_table_row.html | 10 ++++++++ openstack_dashboard/templates/base.html | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 horizon/templates/horizon/client_side/_table_row.html diff --git a/horizon/static/horizon/js/horizon.js b/horizon/static/horizon/js/horizon.js index e1e7427d5d5..1341db09729 100644 --- a/horizon/static/horizon/js/horizon.js +++ b/horizon/static/horizon/js/horizon.js @@ -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); @@ -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'); } @@ -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: {} }; diff --git a/horizon/templates/horizon/client_side/_table_row.html b/horizon/templates/horizon/client_side/_table_row.html new file mode 100644 index 00000000000..3f22e64438d --- /dev/null +++ b/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 %} +No items to display. +{% endjstemplate %} +{% endblock %} \ No newline at end of file diff --git a/openstack_dashboard/templates/base.html b/openstack_dashboard/templates/base.html index adfc320923c..b0f4630fa55 100644 --- a/openstack_dashboard/templates/base.html +++ b/openstack_dashboard/templates/base.html @@ -27,6 +27,7 @@ {% block js %} {% include "_scripts.html" %} {% include "horizon/client_side/_modal.html" %} + {% include "horizon/client_side/_table_row.html" %} {% endblock %}