From 835c7859c5c31807b9f46cf79462459238571f5e Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 3 Sep 2012 16:43:13 +0200 Subject: 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/dialog.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'install/ui/dialog.js') diff --git a/install/ui/dialog.js b/install/ui/dialog.js index 87821841..e3d3395f 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; +}; -- cgit