From: Jiri Tomasek <jtomasek(a)redhat.com>
Multi select table js popups have been unified into one method. The default messages are
defined in
data-none_selected and data-confirm attributes in checkbox_table. This way it can be
translated
classic rails way. These default messages can be overriden by specifiing given data
attibutes at the
desired button (restful_submit_tag). multiActionValidation method is also aware of
possible multiple
checkbox_table tables in one page.
---
src/app/views/layouts/_filter_table.html.haml | 3 +-
src/config/locales/en.yml | 2 +
src/public/javascripts/application.js | 54 +++++-------------------
3 files changed, 15 insertions(+), 44 deletions(-)
diff --git a/src/app/views/layouts/_filter_table.html.haml
b/src/app/views/layouts/_filter_table.html.haml
index 29be530..9240fc5 100644
--- a/src/app/views/layouts/_filter_table.html.haml
+++ b/src/app/views/layouts/_filter_table.html.haml
@@ -8,10 +8,9 @@
- if content_for? form_header
%ul.actions
= yield form_header
-
.clear
- %table.flat.checkbox_table
+ %table.flat.checkbox_table{ 'data-none_selected' =>
t("default_none_selected_message"), 'data-confirm' =>
t("default_confirm_message") }
%thead
%tr
- columns.each do |column|
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index c6129ad..365f2d6 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -167,6 +167,8 @@ en:
catalog_images: Catalog Images
quota: Quota
choose: Choose
+ default_none_selected_message: "Please make a selection first."
+ default_confirm_message: "Are you sure you want to proceed?"
deployments:
deployments: Deployments
deployment: Deployment
diff --git a/src/public/javascripts/application.js
b/src/public/javascripts/application.js
index 7f6f624..f4054fb 100644
--- a/src/public/javascripts/application.js
+++ b/src/public/javascripts/application.js
@@ -117,49 +117,22 @@ $.extend(Conductor, {
$.ajaxSetup({accepts: acceptsSettings, dataType: 'html'})
},
- multiDestroyValidation: function() {
- $('#delete_button').live('click', function(e) {
- if ($(".checkbox_table input[@type=radio]:checked").length == 0) {
- alert('Please make a selection before clicking Delete button.');
- e.preventDefault();
- }
- else if (!confirm("Are you sure you want to proceed with deletion?")) {
- e.preventDefault();
- }
- });
- },
+ multiActionValidation: function() {
+ $('#delete_button, #revoke_button, #stop_button, #stop_selected_instances,
#reboot_selected_instances').live('click', function(e) {
- multiRevokeValidation: function() {
- $('#revoke_button').live('click', function(e) {
- if ($(".checkbox_table input[@type=radio]:checked").length == 0) {
- alert('Please make a selection before clicking Revoke Access button.');
- e.preventDefault();
- }
- else if (!confirm("Are you sure you want to proceed?")) {
- e.preventDefault();
- }
- });
- },
+ var $checkbox_table =
$(this).closest("form.filterable-data").find("table.checkbox_table");
+ var confirm_message = $checkbox_table.data('confirm');
+ var none_selected_message = $checkbox_table.data('none_selected');
- multiStopValidation: function() {
- $('#stop_button, #stop_selected_instances').live('click', function(e)
{
- if ($(".checkbox_table input[@type=radio]:checked").length == 0) {
- alert('Please make a selection before clicking Stop button.');
- e.preventDefault();
- }
- else if (!confirm("Are you sure you want to proceed?")) {
- e.preventDefault();
- }
- });
- },
+ //if needed, override default messages with messages defined explicitly on button
+ if ($(this).data('confirm')){ confirm_message =
$(this).data('confirm'); }
+ if ($(this).data('none_selected')){ none_selected_message =
$(this).data('none_selected'); }
- multiRebootValidation: function() {
- $('#reboot_selected_instances').live('click', function(e) {
- if ($(".checkbox_table input[@type=radio]:checked").length == 0) {
- alert('Please make a selection before clicking Reboot button.');
+ if ($checkbox_table.find("input[@type=radio]:checked").length == 0) {
+ alert(none_selected_message);
e.preventDefault();
}
- else if (!confirm("Are you sure you want to proceed?")) {
+ else if (!confirm(confirm_message)) {
e.preventDefault();
}
});
@@ -398,10 +371,7 @@ $(document).ready(function () {
Conductor.enhanceListView();
Conductor.enhanceDetailsTabs();
Conductor.bind_pretty_toggle();
- Conductor.multiDestroyValidation();
- Conductor.multiRevokeValidation();
- Conductor.multiStopValidation();
- Conductor.multiRebootValidation();
+ Conductor.multiActionValidation();
Conductor.closeNotification();
Conductor.toggleCollapsible();
Conductor.selectAllCheckboxes();
--
1.7.7.6