From 3c9fc345c1560c7520cf15621441643f434abd51 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Mon, 8 Nov 2010 12:57:16 -0500 Subject: Disable Enable user UI updated to use the enable and disable methods, and to correctly report them Implementation has a few shortcomings: 1. Status is displayed in Browser alert dialog, not JQueryUI themed 2. Upon completion of RPC, navigate back to the Search page. Still, this is much less broken than before. With whitespace cleanup, using toLowerCase for testing true and removde dual declaration of variables --- install/static/user.js | 124 ++++++++++++++++++------------------------------- 1 file changed, 45 insertions(+), 79 deletions(-) (limited to 'install/static/user.js') diff --git a/install/static/user.js b/install/static/user.js index 1b6054d7..78462399 100644 --- a/install/static/user.js +++ b/install/static/user.js @@ -48,7 +48,8 @@ ipa_entity_set_details_definition('user', [ input({name:'displayname', label:'Dispaly Name'}). input({name:'initials', label:'Initials'}), ipa_stanza({name:'account', label:'Account Details'}). - input({name:'status', label:'Account Status', load:user_status_load}). + input({name:'nsaccountlock', label:'Account Status', + load:user_status_load}). input({name:'uid', label:'Login'}). input({name:'userpassword', label:'Password', @@ -81,96 +82,61 @@ ipa_entity_set_association_definition('user', { 'taskgroup': { associator: 'serial' } }); -/* Account status Toggle button */ - -function toggle_on_click(obj) -{ - var jobj = $(obj); - var val = jobj.attr('title'); - if (val == 'Active') { - ipa_cmd( - 'lock', [qs['pkey']], {}, on_lock_win, on_fail, - IPA.metadata['user']['name'] - ); - } else { - ipa_cmd( - 'unlock', [qs['pkey']], {}, on_lock_win, on_fail, - IPA.metadata['user']['name'] - ); - } - return (false); -} -function on_lock_win(data, textStatus, xhr) -{ - if (data['error']) { - alert(data['error']['message']); - return; - } - var jobj = $('a[title=Active]'); - if (jobj.length) { - if (ipa_details_cache) { - var memberof = ipa_details_cache['memberof']; - if (memberof) { - memberof.push( - 'cn=inactivated,cn=account inactivation' - ); - } else { - memberof = ['cn=inactivated,cn=account inactivation']; - } - ipa_details_cache['memberof'] = memberof; - a_status(jobj.parent().prev(), ipa_details_cache); - jobj.parent().remove() - } - return; - } - var jobj = $('a[title=Inactive]'); - if (jobj.length) { - if (ipa_details_cache) { - var memberof = ipa_details_cache['memberof']; - if (memberof) { - for (var i = 0; i < memberof.length; ++i) { - if (memberof[i].indexOf('cn=inactivated,cn=account inactivation') != -1) { - memberof.splice(i, 1); - break; - } - } - } else { - memberof = []; - } - ipa_details_cache['memberof'] = memberof; - a_status(jobj.parent().prev(), ipa_details_cache); - jobj.parent().remove(); - } - return; - } -} /* ATTRIBUTE CALLBACKS */ -var toggle_temp = 'S Toggle'; + function user_status_load(container, result) { + var lock_field = 'nsaccountlock'; + var dt = $('dt[title='+this.name+']', container); if (!dt.length) return; - var memberof = result['memberof']; - var dd; - - if (memberof) { - for (var i = 0; i < memberof.length; ++i) { - if (memberof[i].indexOf('cn=inactivated,cn=account inactivation') != -1) { - var t = toggle_temp.replace(/S/g, 'Inactive'); - dd = ipa_create_first_dd(this.name, t); - dt.after(dd); - return; - } - } + var locked = result[lock_field] && + result[lock_field][0].toLowerCase() === 'true'; + var title = "Active"; + var text = "Active: Click to Deactivate"; + if (locked) { + title = "Inactive"; + text = "Inactive: Click to Activate"; } - dd = ipa_create_first_dd(this.name, toggle_temp.replace(/S/g, 'Inactive')); - dt.after(dd); + function on_lock_win(data, textStatus, xhr){ + alert(data.result.summary); + $.bbq.pushState('user-facet','search'); + return false; + } + + function on_lock_fail(data, textStatus, xhr){ + $("#userstatuslink").text = "Error changing account status"; + return false; + } + + var status_field = + $('', + { + id: 'userstatuslink', + title: title, + href: "jslink", + text: text, + click: function() { + var jobj = $(this); + var val = jobj.attr('title'); + var pkey = $.bbq.getState('user-pkey'); + var command = 'user_enable'; + if (val == 'Active') { + command = 'user_disable'; + } + ipa_cmd(command, [pkey], {}, on_lock_win,on_lock_fail); + + return (false); + } + }); + + dt.after(ipa_create_first_dd(this.name, status_field)); } -- cgit