From 6fc488e12fdf45ae67439dc9883e78eb07cc4113 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 4 Mar 2011 14:32:50 -0600 Subject: Fixed memory leak caused by reset password dialog. Ticket 1054 --- install/ui/user.js | 117 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 42 deletions(-) diff --git a/install/ui/user.js b/install/ui/user.js index e098ad1f..8e1cb3f9 100644 --- a/install/ui/user.js +++ b/install/ui/user.js @@ -171,68 +171,101 @@ IPA.user_password_widget = function(spec) { var that = IPA.widget(spec); that.create = function(container) { + $('', { href: 'jslink', title: 'userpassword', text: IPA.messages.objects.user.reset_password, - click: resetpwd_on_click + click: function() { + that.show_dialog(); + return false; + } }).appendTo(container); }; - function resetpwd_on_click() { + that.show_dialog = function() { - function reset_password(new_password) { + var dialog = IPA.dialog({ + title: IPA.messages.objects.user.reset_password, + width: 400 + }); - var user_pkey = $.bbq.getState('user-pkey'); - var pw_pkey; - if (user_pkey === IPA.whoami.uid[0]){ - pw_pkey = []; - }else{ - pw_pkey = [user_pkey]; - } + dialog.create = function() { - IPA.cmd('passwd', - pw_pkey, {"password":new_password}, - function(){ - alert(IPA.messages.objects.user.password_change_complete); - dialog.dialog("close"); - }, - function(){}); - } + var dl = $('
', { + 'class': 'modal' + }).appendTo(dialog.container); + + $('
', { + html: IPA.messages.objects.user.new_password + }).appendTo(dl); + + var dd = $('
', { + 'class': 'first' + }).appendTo(dl); + + dialog.password1 = $('', { + type: 'password' + }).appendTo(dd); + + $('
', { + html: IPA.messages.objects.user.repeat_password + }).appendTo(dl); + + dd = $('
', { + 'class': 'first' + }).appendTo(dl); - var dialog = - $('
'); + dialog.password2 = $('', { + type: 'password' + }).appendTo(dd); + }; + + dialog.add_button(IPA.messages.objects.user.reset_password, function() { - var buttons = {}; + var new_password = dialog.password1.val(); + var repeat_password = dialog.password2.val(); - buttons[IPA.messages.objects.user.reset_password] = function() { - var p1 = $("#password_1").val(); - var p2 = $("#password_2").val(); - if (p1 != p2) { + if (new_password != repeat_password) { alert(IPA.messages.objects.user.password_must_match); return; } - reset_password(p1); - }; - buttons[IPA.messages.buttons.cancel] = function() { - dialog.dialog('close'); - }; + var user_pkey = $.bbq.getState('user-pkey'); - dialog.dialog({ - modal: true, - title: IPA.messages.objects.user.reset_password, - minWidth: 400, - buttons: buttons + var args; + if (user_pkey === IPA.whoami.uid[0]) { + args = []; + } else { + args = [user_pkey]; + } + + var command = IPA.command({ + method: 'passwd', + args: args, + options: { + password: new_password + }, + on_success: function(data, text_status, xhr) { + alert(IPA.messages.objects.user.password_change_complete); + dialog.close(); + }, + on_error: function(xhr, text_status, error_thrown) { + dialog.close(); + } + }); + + command.execute(); + }); + + dialog.add_button(IPA.messages.buttons.cancel, function() { + dialog.close(); }); - return false; - } + dialog.init(); + + dialog.open(that.container); + }; return that; }; -- cgit