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
This commit is contained in:
Endi S. Dewata
2011-06-28 10:59:09 -05:00
parent 9d8ddb5d46
commit c27a6de2a6
3 changed files with 131 additions and 59 deletions

View File

@@ -15592,6 +15592,7 @@
"dialogs": { "dialogs": {
"add_title": "Add ${entity}", "add_title": "Add ${entity}",
"available": "Available", "available": "Available",
"confirmation": "Confirmation",
"dirty_message": "This page has unsaved changes. Please save or revert.", "dirty_message": "This page has unsaved changes. Please save or revert.",
"dirty_title": "Dirty", "dirty_title": "Dirty",
"hide_already_enrolled": "Hide already enrolled.", "hide_already_enrolled": "Hide already enrolled.",
@@ -15665,9 +15666,7 @@
"view_certificate": "Certificate for ${entity} ${primary_key}" "view_certificate": "Certificate for ${entity} ${primary_key}"
}, },
"config": { "config": {
"cn": "Name",
"group": "Group Options", "group": "Group Options",
"ipaserver": "Configuration",
"search": "Search Options", "search": "Search Options",
"user": "User Options" "user": "User Options"
}, },
@@ -15816,10 +15815,13 @@
}, },
"user": { "user": {
"account": "Account Settings", "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?<br/>The change will take effect immediately.",
"active": "Active", "active": "Active",
"contact": "Contact Settings", "contact": "Contact Settings",
"deactivate": "Click to Deactivate", "deactivate": "Deactivate",
"employee": "Employee Information", "employee": "Employee Information",
"error_changing_status": "Error changing account status", "error_changing_status": "Error changing account status",
"inactive": "Inactive", "inactive": "Inactive",

View File

@@ -62,7 +62,11 @@ IPA.entity_factories.user = function() {
{ {
name: 'account', name: 'account',
fields: [ fields: [
{ factory: IPA.user_status_widget, name: 'nsaccountlock' }, {
factory: IPA.user_status_widget,
name: 'nsaccountlock',
label: IPA.messages.objects.user.account_status
},
'uid', 'uid',
{ factory: IPA.user_password_widget, name: 'userpassword' }, { factory: IPA.user_password_widget, name: 'userpassword' },
'uidnumber', 'uidnumber',
@@ -138,62 +142,126 @@ IPA.user_status_widget = function(spec) {
var that = IPA.widget(spec); var that = IPA.widget(spec);
that.create = function(container) {
that.widget_create(container);
that.status_span = $('<span/>', {
name: 'status'
}).appendTo(container);
container.append(': ');
that.status_link = $('<a/>', {
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() { that.update = function() {
if (!that.record) return; if (!that.record) return;
that.container.empty();
var lock_field = 'nsaccountlock'; var lock_field = 'nsaccountlock';
var locked = that.record[lock_field] && var locked = that.record[lock_field] &&
that.record[lock_field][0].toLowerCase() === 'true'; 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) { if (locked) {
title = IPA.messages.objects.user.inactive; status = IPA.messages.objects.user.inactive;
text = title+": "+IPA.messages.objects.user.activate; action = 'activate';
} else {
status = IPA.messages.objects.user.active;
action = 'deactivate';
} }
function on_lock_win(data, textStatus, xhr){ that.status_span.html(status);
var entity = IPA.get_entity(that.entity_name); that.status_link.attr('href', action);
var facet = entity.get_facet('details');
facet.refresh();
return false;
}
function on_lock_fail(data, textStatus, xhr){ var message = IPA.messages.objects.user.activation_link;
$("#userstatuslink").text = IPA.messages.objects.user.error_changing_status; var action_label = IPA.messages.objects.user[action];
return false; message = message.replace('${action}', action_label);
}
var status_field = that.status_link.html(message);
$('<a/>', };
{
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); that.show_activation_dialog = function() {
}
}); var action = that.status_link.attr('href');
status_field.appendTo(that.container);
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';
IPA.command({
entity: 'user',
method: method,
args: [pkey],
on_success: on_success,
on_error: on_error
}).execute();
}; };
return that; return that;

View File

@@ -148,8 +148,6 @@ class i18n_messages(Command):
"restore_certificate":_("Restore Certificate for ${entity} ${primary_key}"), "restore_certificate":_("Restore Certificate for ${entity} ${primary_key}"),
}, },
"config": { "config": {
"ipaserver":_("Configuration"),
"cn":_("Name"),
"user":_("User Options"), "user":_("User Options"),
"search":_("Search Options"), "search":_("Search Options"),
"group":_("Group Options"), "group":_("Group Options"),
@@ -302,20 +300,23 @@ class i18n_messages(Command):
}, },
"user": { "user": {
"account":_("Account Settings"), "account":_("Account Settings"),
"contact":_("Contact Settings"), "account_status":_("Account Status"),
"mailing":_("Mailing Address"), "activate":_("Activate"),
"employee":_("Employee Information"), "activation_link":_("Click to ${action}"),
"misc":_("Misc. Information"), "activation_confirmation":_("Are you sure you want to ${action} the user?<br/>The change will take effect immediately."),
"active":_("Active"), "active":_("Active"),
"deactivate":_("Click to Deactivate"), "contact":_("Contact Settings"),
"inactive":_("Inactive"), "deactivate":_("Deactivate"),
"activate":_("Click to Activate"), "employee":_("Employee Information"),
"error_changing_status":_("Error changing account status"), "error_changing_status":_("Error changing account status"),
"reset_password":_("Reset Password"), "inactive":_("Inactive"),
"mailing":_("Mailing Address"),
"misc":_("Misc. Information"),
"new_password":_("New Password"), "new_password":_("New Password"),
"repeat_password":_("Repeat Password"),
"password_change_complete":_("Password change complete"), "password_change_complete":_("Password change complete"),
"password_must_match":_("Passwords must match"), "password_must_match":_("Passwords must match"),
"repeat_password":_("Repeat Password"),
"reset_password":_("Reset Password"),
}, },
}, },
"buttons": { "buttons": {
@@ -342,6 +343,7 @@ class i18n_messages(Command):
"dialogs": { "dialogs": {
"add_title":_("Add ${entity}"), "add_title":_("Add ${entity}"),
"available":_("Available"), "available":_("Available"),
"confirmation":_("Confirmation"),
"dirty_message":_("This page has unsaved changes. Please save or revert."), "dirty_message":_("This page has unsaved changes. Please save or revert."),
"dirty_title":_("Dirty"), "dirty_title":_("Dirty"),
"hide_already_enrolled":_("Hide already enrolled."), "hide_already_enrolled":_("Hide already enrolled."),