From c27a6de2a601f6507b872978e508a29baa8c7b52 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 28 Jun 2011 10:59:09 -0500 Subject: Added confirmation dialog for user activation. The IPA.user_status_widget has been modified such that it checks the facet dirty status and asks the admin to either Update or Reset the changes. Then the widget shows a dialog to confirm whether the admin wants to activate/deactivate the user. Ticket #1395 --- install/ui/test/data/ipa_init.json | 10 ++- install/ui/user.js | 158 ++++++++++++++++++++++++++----------- ipalib/plugins/internal.py | 22 +++--- 3 files changed, 131 insertions(+), 59 deletions(-) diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json index c3b47ea94..a7af63841 100644 --- a/install/ui/test/data/ipa_init.json +++ b/install/ui/test/data/ipa_init.json @@ -15592,6 +15592,7 @@ "dialogs": { "add_title": "Add ${entity}", "available": "Available", + "confirmation": "Confirmation", "dirty_message": "This page has unsaved changes. Please save or revert.", "dirty_title": "Dirty", "hide_already_enrolled": "Hide already enrolled.", @@ -15665,9 +15666,7 @@ "view_certificate": "Certificate for ${entity} ${primary_key}" }, "config": { - "cn": "Name", "group": "Group Options", - "ipaserver": "Configuration", "search": "Search Options", "user": "User Options" }, @@ -15816,10 +15815,13 @@ }, "user": { "account": "Account Settings", - "activate": "Click to Activate", + "account_status": "Account status", + "activate": "Activate", + "activation_link": "Click to ${action}", + "activation_confirmation": "Are you sure you want to ${action} the user?
The change will take effect immediately.", "active": "Active", "contact": "Contact Settings", - "deactivate": "Click to Deactivate", + "deactivate": "Deactivate", "employee": "Employee Information", "error_changing_status": "Error changing account status", "inactive": "Inactive", diff --git a/install/ui/user.js b/install/ui/user.js index d72175425..9617dec99 100644 --- a/install/ui/user.js +++ b/install/ui/user.js @@ -62,7 +62,11 @@ IPA.entity_factories.user = function() { { name: 'account', fields: [ - { factory: IPA.user_status_widget, name: 'nsaccountlock' }, + { + factory: IPA.user_status_widget, + name: 'nsaccountlock', + label: IPA.messages.objects.user.account_status + }, 'uid', { factory: IPA.user_password_widget, name: 'userpassword' }, 'uidnumber', @@ -138,62 +142,126 @@ IPA.user_status_widget = function(spec) { var that = IPA.widget(spec); + that.create = function(container) { + + that.widget_create(container); + + that.status_span = $('', { + name: 'status' + }).appendTo(container); + + container.append(': '); + + that.status_link = $('', { + name: 'link', + click: function() { + + var entity = IPA.get_entity(that.entity_name); + var facet_name = IPA.current_facet(entity); + var facet = entity.get_facet(facet_name); + + if (facet.is_dirty()) { + var dialog = IPA.dirty_dialog({ + facet: facet + }); + + dialog.callback = function() { + that.show_activation_dialog(); + }; + + dialog.init(); + dialog.open(container); + + } else { + that.show_activation_dialog(); + } + + return false; + } + }).appendTo(container); + }; + that.update = function() { if (!that.record) return; - that.container.empty(); - var lock_field = 'nsaccountlock'; - var locked = that.record[lock_field] && + var locked = that.record[lock_field] && that.record[lock_field][0].toLowerCase() === 'true'; - var title = IPA.messages.objects.user.active; - var text = title+": "+IPA.messages.objects.user.deactivate; + + var status; + var action; + if (locked) { - title = IPA.messages.objects.user.inactive; - text = title+": "+IPA.messages.objects.user.activate; - } + status = IPA.messages.objects.user.inactive; + action = 'activate'; - function on_lock_win(data, textStatus, xhr){ - var entity = IPA.get_entity(that.entity_name); - var facet = entity.get_facet('details'); - facet.refresh(); - return false; + } else { + status = IPA.messages.objects.user.active; + action = 'deactivate'; } - function on_lock_fail(data, textStatus, xhr){ - $("#userstatuslink").text = IPA.messages.objects.user.error_changing_status; - return false; - } + that.status_span.html(status); + that.status_link.attr('href', action); + + var message = IPA.messages.objects.user.activation_link; + var action_label = IPA.messages.objects.user[action]; + message = message.replace('${action}', action_label); + + that.status_link.html(message); + }; + + that.show_activation_dialog = function() { + + var action = that.status_link.attr('href'); + + var message = IPA.messages.objects.user.activation_confirmation; + var action_label = IPA.messages.objects.user[action]; + message = message.replace('${action}', action_label.toLocaleLowerCase()); + + var dialog = IPA.dialog({ + 'title': IPA.messages.dialogs.confirmation + }); + + dialog.create = function() { + dialog.container.append(message); + }; + + dialog.add_button(action_label, function() { + that.set_status( + action == 'activate', + function(data, textStatus, xhr) { + var entity = IPA.get_entity(that.entity_name); + var facet_name = IPA.current_facet(entity); + var facet = entity.get_facet(facet_name); + facet.refresh(); + dialog.close(); + } + ); + }); + + dialog.add_button(IPA.messages.buttons.cancel, function() { + dialog.close(); + }); + + dialog.init(); + + dialog.open(that.container); + }; + + that.set_status = function(enabled, on_success, on_error) { + + var pkey = IPA.nav.get_state('user-pkey'); + var method = enabled ? 'enable' : 'disable'; - var status_field = - $('', - { - id: 'userstatuslink', - title: title, - href: "jslink", - text: text, - click: function() { - var jobj = $(this); - var val = jobj.attr('title'); - var pkey = IPA.nav.get_state('user-pkey'); - var method = 'enable'; - if (val == IPA.messages.objects.user.active) { - method = 'disable'; - } - IPA.command({ - entity: 'user', - method: method, - args: [pkey], - on_success: on_lock_win, - on_error: on_lock_fail - }).execute(); - - return (false); - } - }); - status_field.appendTo(that.container); + IPA.command({ + entity: 'user', + method: method, + args: [pkey], + on_success: on_success, + on_error: on_error + }).execute(); }; return that; diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py index b7425e350..854ebacef 100644 --- a/ipalib/plugins/internal.py +++ b/ipalib/plugins/internal.py @@ -148,8 +148,6 @@ class i18n_messages(Command): "restore_certificate":_("Restore Certificate for ${entity} ${primary_key}"), }, "config": { - "ipaserver":_("Configuration"), - "cn":_("Name"), "user":_("User Options"), "search":_("Search Options"), "group":_("Group Options"), @@ -302,20 +300,23 @@ class i18n_messages(Command): }, "user": { "account":_("Account Settings"), + "account_status":_("Account Status"), + "activate":_("Activate"), + "activation_link":_("Click to ${action}"), + "activation_confirmation":_("Are you sure you want to ${action} the user?
The change will take effect immediately."), + "active":_("Active"), "contact":_("Contact Settings"), - "mailing":_("Mailing Address"), + "deactivate":_("Deactivate"), "employee":_("Employee Information"), - "misc":_("Misc. Information"), - "active":_("Active"), - "deactivate":_("Click to Deactivate"), - "inactive":_("Inactive"), - "activate":_("Click to Activate"), "error_changing_status":_("Error changing account status"), - "reset_password":_("Reset Password"), + "inactive":_("Inactive"), + "mailing":_("Mailing Address"), + "misc":_("Misc. Information"), "new_password":_("New Password"), - "repeat_password":_("Repeat Password"), "password_change_complete":_("Password change complete"), "password_must_match":_("Passwords must match"), + "repeat_password":_("Repeat Password"), + "reset_password":_("Reset Password"), }, }, "buttons": { @@ -342,6 +343,7 @@ class i18n_messages(Command): "dialogs": { "add_title":_("Add ${entity}"), "available":_("Available"), + "confirmation":_("Confirmation"), "dirty_message":_("This page has unsaved changes. Please save or revert."), "dirty_title":_("Dirty"), "hide_already_enrolled":_("Hide already enrolled."), -- cgit