reset table to empty look if row becomes empty during updates
* fixes bug 955706 Change-Id: Icb4190ce8cf20e3375c237f6729c64cb17f404e1
This commit is contained in:
parent
baf6662ac4
commit
5ab5d28031
@ -75,7 +75,8 @@ var Horizon = function() {
|
|||||||
}
|
}
|
||||||
// Trigger the update handlers.
|
// Trigger the update handlers.
|
||||||
$rows_to_update.each(function(index, row) {
|
$rows_to_update.each(function(index, row) {
|
||||||
var $row = $(this);
|
var $row = $(this),
|
||||||
|
$table = $row.closest('table');
|
||||||
$.ajax($row.attr('data-update-url'), {
|
$.ajax($row.attr('data-update-url'), {
|
||||||
complete: function (jqXHR, status) {
|
complete: function (jqXHR, status) {
|
||||||
var $new_row = $(jqXHR.responseText);
|
var $new_row = $(jqXHR.responseText);
|
||||||
@ -86,6 +87,26 @@ var Horizon = function() {
|
|||||||
// Preserve the checkbox if it's already clicked
|
// Preserve the checkbox if it's already clicked
|
||||||
$new_row.find(':checkbox').prop('checked', true);
|
$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);
|
$row.replaceWith($new_row);
|
||||||
$table.removeAttr('decay_constant');
|
$table.removeAttr('decay_constant');
|
||||||
}
|
}
|
||||||
@ -168,7 +189,7 @@ var Horizon = function() {
|
|||||||
|
|
||||||
/* Namespace for core functionality related to client-side templating. */
|
/* Namespace for core functionality related to client-side templating. */
|
||||||
horizon.templates = {
|
horizon.templates = {
|
||||||
template_ids: ["#modal_template"],
|
template_ids: ["#modal_template", "#empty_row_template"],
|
||||||
compiled_templates: {}
|
compiled_templates: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
10
horizon/templates/horizon/client_side/_table_row.html
Normal file
10
horizon/templates/horizon/client_side/_table_row.html
Normal file
@ -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 %}
|
@ -27,6 +27,7 @@
|
|||||||
{% block js %}
|
{% block js %}
|
||||||
{% include "_scripts.html" %}
|
{% include "_scripts.html" %}
|
||||||
{% include "horizon/client_side/_modal.html" %}
|
{% include "horizon/client_side/_modal.html" %}
|
||||||
|
{% include "horizon/client_side/_table_row.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user