From b3c70356b45ed855446b7acfe4ccbb3808cc27eb Mon Sep 17 00:00:00 2001 From: Andy Chong Date: Mon, 19 Mar 2012 11:07:17 +0800 Subject: [PATCH] Add a select all checkbox at table header dynamically * implements wishlist at bug 959017 Change-Id: I22a1fc3007dcf69e5f3f0d9eac48adbe62ad8035 --- horizon/static/horizon/js/horizon.js | 2 +- horizon/static/horizon/js/tables.js | 10 ++++++++++ openstack_dashboard/static/dashboard/css/style.css | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/horizon/static/horizon/js/horizon.js b/horizon/static/horizon/js/horizon.js index 1341db097..255e0d0ba 100644 --- a/horizon/static/horizon/js/horizon.js +++ b/horizon/static/horizon/js/horizon.js @@ -145,7 +145,7 @@ var Horizon = function() { $("form :checkbox").on("click", function (evt) { var $form = $(this).closest("form"); - var any_checked = $form.find(":checkbox").is(":checked"); + var any_checked = $form.find("tbody :checkbox").is(":checked"); // Enable the button if any checkbox is checked, // Disable if all checkbox is cleared diff --git a/horizon/static/horizon/js/tables.js b/horizon/static/horizon/js/tables.js index 19ed11908..30ae1b66e 100644 --- a/horizon/static/horizon/js/tables.js +++ b/horizon/static/horizon/js/tables.js @@ -26,5 +26,15 @@ horizon.addInitFunction(function() { } }); + // Add a select all checkbox at table header + $('table thead .multi_select_column').append(''); + $('table thead .multi_select_column :checkbox').click(function(evt) { + var $this = $(this), + $table = $this.closest('table'), + is_checked = $this.prop('checked'), + checkboxes = $table.find('tbody :checkbox'); + checkboxes.prop('checked', is_checked); + }); + horizon.datatables.update(); }); diff --git a/openstack_dashboard/static/dashboard/css/style.css b/openstack_dashboard/static/dashboard/css/style.css index ef08bf0a5..958725ccc 100644 --- a/openstack_dashboard/static/dashboard/css/style.css +++ b/openstack_dashboard/static/dashboard/css/style.css @@ -738,7 +738,7 @@ th.multi_select_column, td.multi_select_column { width: 25px; } -td.multi_select_column { +th.multi_select_column, td.multi_select_column { text-align: center; }