This patch is changing confirmation of actions according to ticket #3035, see the ticket description.

It does following changes:
 * Confirmation of update action was removed.
* Action lists resets to first action (which is usually a NOP: '-- select action --') on change of displayed entry. * New confirmation dialog was implemented. It is used for action confirmation. It is used in IPA.action to replace the call of window.confirm(message). The old call is a modal window which blocks all JS functionality and has different style than other dialogs in Web UI. The new one has same design and doesn't block background operations.

 https://fedorahosted.org/freeipa/ticket/3035
--
Petr Vobornik
From 6e520c00ac173a7a5fc823d953bcc7829b89e178 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Mon, 3 Sep 2012 16:43:13 +0200
Subject: [PATCH] Update of confirmation of actions

This patch is changing confirmation of actions according to ticket #3035, see the ticket description.

It does following changes:
 * Confirmation of update action was removed.
 * Action lists resets to first action (which is usually a NOP: '-- select action --') on change of displayed entry.
 * New confirmation dialog was implemented. It is used for action confirmation. It is used in IPA.action to replace the call of window.confirm(message). The old call is a modal window which blocks all JS functionality and has different style than other dialogs in Web UI. The new one has same design and doesn't block background operations.

 https://fedorahosted.org/freeipa/ticket/3035
---
 install/ui/details.js              | 11 +++---
 install/ui/dialog.js               | 78 +++++++++++++++++++++++++++++++++++++-
 install/ui/facet.js                | 20 ++++++++--
 install/ui/search.js               |  2 +
 install/ui/test/data/ipa_init.json |  2 +
 ipalib/plugins/internal.py         |  2 +
 6 files changed, 105 insertions(+), 10 deletions(-)

diff --git a/install/ui/details.js b/install/ui/details.js
index 883bb06bfd56ffd800f1ce60e229bc0c1f4ec1bb..c16a556d5176d24d07e9f97b0594a68f7914a216 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -908,7 +908,7 @@ IPA.update_action = function(spec) {
     spec = spec || {};
     spec.name = spec.name || 'update';
     spec.label = spec.label || IPA.messages.buttons.update;
-    spec.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : true;
+    spec.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : false;
     spec.enable_cond = spec.enable_cond || ['dirty'];
 
     var that = IPA.action(spec);
@@ -1110,8 +1110,6 @@ IPA.object_action = function(spec) {
         var entity_name = facet.entity.name;
         var pkey = IPA.nav.get_state(entity_name+'-pkey');
 
-        if (that.needs_confirm && !that.confirm_object(pkey)) return;
-
         IPA.command({
             entity: entity_name,
             method: that.method,
@@ -1145,9 +1143,10 @@ IPA.object_action = function(spec) {
         };
     };
 
-    that.confirm_object = function(obj_name) {
-        var msg = that.confirm_msg.replace('${object}', obj_name);
-        return IPA.confirm(msg);
+    that.get_confirm_message = function(facet) {
+        var pkey = IPA.nav.get_state(facet.entity.name+'-pkey');
+        var msg = that.confirm_msg.replace('${object}', pkey);
+        return msg;
     };
 
     return that;
diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index 878218419a5b75789c59e42029aa662cc09867b0..e3d3395f9123ff135212a72fbbb52ee280c24493 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -671,7 +671,7 @@ IPA.message_dialog = function(spec) {
         label: IPA.messages.buttons.ok,
         click: function() {
             that.close();
-            if(that.on_ok) {
+            if (that.on_ok) {
                 that.on_ok();
             }
         }
@@ -681,3 +681,79 @@ IPA.message_dialog = function(spec) {
 
     return that;
 };
+
+IPA.confirm_dialog = function(spec) {
+
+    spec = spec || {};
+    spec.message = spec.message || IPA.messages.actions.confirm;
+    spec.title = spec.title || IPA.messages.dialogs.confirmation;
+
+    var that = IPA.message_dialog(spec);
+    that.on_cancel = spec.on_cancel;
+    that.ok_label = spec.ok_label || IPA.messages.buttons.ok;
+    that.cancel_label = spec.cancel_label || IPA.messages.buttons.cancel;
+    that.confirmed = false;
+    that.confirm_on_enter = spec.confirm_on_enter !== undefined ? spec.confirm_on_enter : true;
+
+    that.close = function() {
+
+        that.dialog_close();
+        $(document).unbind('keyup', that.on_key_up);
+
+        if (that.confirmed) {
+            if (that.on_ok) {
+                that.on_ok();
+            }
+        } else {
+            if (that.on_cancel) {
+                that.on_cancel();
+            }
+        }
+    };
+
+    that.open = function(container) {
+
+        that.confirmed = false;
+        that.dialog_open(container);
+        $(document).bind('keyup', that.on_key_up);
+    };
+
+    that.on_key_up = function(event) {
+
+        if (event.keyCode === $.ui.keyCode.ENTER) {
+            event.preventDefault();
+            that.confirmed = true;
+            that.close();
+        }
+    };
+
+    that.create_buttons = function() {
+
+        that.buttons.empty();
+
+        that.create_button({
+            name: 'ok',
+            label: that.ok_label,
+            click: function() {
+                that.confirmed = true;
+                that.close();
+            }
+        });
+
+        that.create_button({
+            name: 'cancel',
+            label: that.cancel_label,
+            click: function() {
+                that.confirmed = false;
+                that.close();
+            }
+        });
+    };
+
+    that.create_buttons();
+
+    that.confirm_dialog_close = that.close;
+    that.confirm_dialog_open = that.open;
+
+    return that;
+};
diff --git a/install/ui/facet.js b/install/ui/facet.js
index 0de08d3f7a031a3ccce326a88e1b3fbe6d8ddb65..372022dbea6ab9a61b840c62c7e7ea08037cd1c9 100644
--- a/install/ui/facet.js
+++ b/install/ui/facet.js
@@ -655,6 +655,7 @@ IPA.facet_header = function(spec) {
 
     that.clear = function() {
         that.load();
+        if (that.action_list) that.action_list.clear();
     };
 
     return that;
@@ -1300,6 +1301,10 @@ IPA.action = function(spec) {
     that.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : false;
     that.confirm_msg = spec.confirm_msg || IPA.messages.actions.confirm;
 
+    that.confirm_dialog = spec.confirm_dialog !== undefined ? spec.confirm_dialog :
+                                                              IPA.confirm_dialog;
+
+
 
     that.execute_action = function(facet, on_success, on_error) {
 
@@ -1319,9 +1324,13 @@ IPA.action = function(spec) {
             if (that.confirm_dialog) {
 
                 var dialog = IPA.build(that.confirm_dialog);
-                confirmed = dialog.confirm(that.facet);
+                dialog.message = that.get_confirm_message(facet);
+                dialog.on_ok = function () {
+                    that.execute_action(facet, on_success, on_error);
+                };
+                dialog.open();
             } else {
-                var msg = that.get_confirm_message();
+                var msg = that.get_confirm_message(facet);
                 confirmed = IPA.confirm(msg);
             }
 
@@ -1331,7 +1340,7 @@ IPA.action = function(spec) {
         that.execute_action(facet, on_success, on_error);
     };
 
-    that.get_confirm_message = function() {
+    that.get_confirm_message = function(facet) {
         return that.confirm_msg;
     };
 
@@ -2022,5 +2031,10 @@ IPA.action_list_widget = function(spec) {
         that.action_select.update([first]);
     };
 
+    that.clear = function() {
+
+        that.select_first_enabled();
+    };
+
     return that;
 };
\ No newline at end of file
diff --git a/install/ui/search.js b/install/ui/search.js
index 154d7ffaff926b125deaf86dfa8be2f5b9abf148..7c4939bbbd52f882df048f3a78a22294e1d838ea 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -473,6 +473,7 @@ IPA.batch_disable_action = function(spec) {
     spec.needs_confirm = spec.needs_confirm === undefined ? true : spec.needs_confirm;
     spec.enable_cond = spec.enable_cond || ['item-selected'];
     spec.success_msg = spec.success_msg || IPA.messages.search.disabled;
+    spec.confirm_msg = spec.confirm_msg || IPA.messages.search.disable_confirm;
 
     return IPA.batch_items_action(spec);
 };
@@ -486,6 +487,7 @@ IPA.batch_enable_action = function(spec) {
     spec.needs_confirm = spec.needs_confirm === undefined ? true : spec.needs_confirm;
     spec.enable_cond = spec.enable_cond || ['item-selected'];
     spec.success_msg = spec.success_msg || IPA.messages.search.enabled;
+    spec.confirm_msg = spec.confirm_msg || IPA.messages.search.enable_confirm;
 
     return IPA.batch_items_action(spec);
 };
\ No newline at end of file
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index ff4c7489d235d0be7a2f1c98371921023a75cfa2..1006535c26df98ae3d417ad27cd9a6cf4769efff 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -482,7 +482,9 @@
                     "search": {
                         "delete_confirm": "Are you sure you want to delete selected entries?",
                         "deleted": "Selected entries were deleted.",
+                        "disable_confirm": "Are you sure you want to disable selected entries?",
                         "disabled": "${count} items were disabled",
+                        "enable_confirm": "Are you sure you want to enable selected entries?",
                         "enabled": "${count} items were enabled",
                         "partial_delete": "Some entries were not deleted",
                         "quick_links": "Quick Links",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 890ebb4523a45bb85767f033c51866683d36a699..5c95951489422e82e022108d6882f0e696a062c3 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -621,7 +621,9 @@ class i18n_messages(Command):
         "search": {
             "delete_confirm": _("Are you sure you want to delete selected entries?"),
             "deleted": _("Selected entries were deleted."),
+            "disable_confirm": _("Are you sure you want to disable selected entries?"),
             "disabled": _("${count} items were disabled"),
+            "enable_confirm": _("Are you sure you want to enable selected entries?"),
             "enabled": _("${count} items were enabled"),
             "partial_delete": _("Some entries were not deleted"),
             "quick_links": _("Quick Links"),
-- 
1.7.11.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to