diff --git a/horizon/static/horizon/js/horizon.tables.js b/horizon/static/horizon/js/horizon.tables.js index 861f915a16..70c3d0a50c 100644 --- a/horizon/static/horizon/js/horizon.tables.js +++ b/horizon/static/horizon/js/horizon.tables.js @@ -138,8 +138,10 @@ horizon.datatables = { var action_buttons = $(this).find(".table_actions button.btn-danger"); // Buttons should be enabled only if there are checked checkboxes - action_buttons.toggleClass("disabled", - !checkboxes.filter(":checked").length); + if (checkboxes.length) { + action_buttons.toggleClass("disabled", + !checkboxes.filter(":checked").length); + } }); }, diff --git a/horizon/tables/base.py b/horizon/tables/base.py index 2f76b79ca8..7e5d1b47b0 100644 --- a/horizon/tables/base.py +++ b/horizon/tables/base.py @@ -982,8 +982,10 @@ class DataTableOptions(object): self.template = getattr(options, 'template', 'horizon/common/_data_table.html') - self.row_actions_template = \ - 'horizon/common/_data_table_row_actions.html' + self.row_actions_dropdown_template = ('horizon/common/_data_table_' + 'row_actions_dropdown.html') + self.row_actions_row_template = ('horizon/common/_data_table_' + 'row_actions_row.html') self.table_actions_template = \ 'horizon/common/_data_table_table_actions.html' self.context_var_name = unicode(getattr(options, @@ -1388,11 +1390,16 @@ class DataTable(object): self.set_multiselect_column_visibility(len(bound_actions) > 0) return table_actions_template.render(context) - def render_row_actions(self, datum, pull_right=True): + def render_row_actions(self, datum, pull_right=True, row=False): """Renders the actions specified in ``Meta.row_actions`` using the - current row data. + current row data. If `row` is True, the actions are rendered in a row + of buttons. Otherwise they are rendered in a dropdown box. """ - template_path = self._meta.row_actions_template + if row: + template_path = self._meta.row_actions_row_template + else: + template_path = self._meta.row_actions_dropdown_template + row_actions_template = template.loader.get_template(template_path) bound_actions = self.get_row_actions(datum) extra_context = {"row_actions": bound_actions, diff --git a/horizon/templates/horizon/common/_data_table_row_action.html b/horizon/templates/horizon/common/_data_table_row_action_dropdown.html similarity index 100% rename from horizon/templates/horizon/common/_data_table_row_action.html rename to horizon/templates/horizon/common/_data_table_row_action_dropdown.html diff --git a/horizon/templates/horizon/common/_data_table_row_action_row.html b/horizon/templates/horizon/common/_data_table_row_action_row.html new file mode 100644 index 0000000000..8602439c22 --- /dev/null +++ b/horizon/templates/horizon/common/_data_table_row_action_row.html @@ -0,0 +1,11 @@ +{% if action.method != "GET" %} + +{% else %} + + {% if action.icon != None %} {% endif %} + {{ action.verbose_name }} + +{% endif %} diff --git a/horizon/templates/horizon/common/_data_table_row_actions.html b/horizon/templates/horizon/common/_data_table_row_actions_dropdown.html similarity index 74% rename from horizon/templates/horizon/common/_data_table_row_actions.html rename to horizon/templates/horizon/common/_data_table_row_actions_dropdown.html index 3f3368b682..781a30e9a6 100644 --- a/horizon/templates/horizon/common/_data_table_row_actions.html +++ b/horizon/templates/horizon/common/_data_table_row_actions_dropdown.html @@ -5,14 +5,14 @@
{% for action in row_actions %} {% if forloop.first %} - {% include "horizon/common/_data_table_row_action.html" %} + {% include "horizon/common/_data_table_row_action_dropdown.html" %}
{% endif %} {% if row_actions|length == 1%} - {% for action in row_actions %} - {% include "horizon/common/_data_table_row_action.html" %} - {% endfor %} + {% include "horizon/common/_data_table_row_action_dropdown.html" with action=row_actions.0%} {% endif %} {% endspaceless %} diff --git a/horizon/templates/horizon/common/_data_table_row_actions_row.html b/horizon/templates/horizon/common/_data_table_row_actions_row.html new file mode 100644 index 0000000000..dd2a5f0ceb --- /dev/null +++ b/horizon/templates/horizon/common/_data_table_row_actions_row.html @@ -0,0 +1,8 @@ +{% load i18n %} +
+{% block table_actions %} + {% for action in row_actions %} + {% include "horizon/common/_data_table_row_action_row.html" %} + {% endfor %} +{% endblock table_actions %} +