Sonia.user.Panel.prototype.initComponentExt=Sonia.user.Panel.prototype.initComponent;
Ext.override(Sonia.user.Panel,{renameIcon:"resources/plugins/userrename/icons/user_rename.png",renameText:"Rename",newUsernameTitle:"Username",newUsernameText:"Please enter the new username:",renameErrorText:"Could not rename user.",initComponent:function(){this.initComponentExt();this.appendRenameButton()},appendRenameButton:function(){if(debug)console.debug("append rename button");var toolbar=this.getTopToolbar();toolbar.insert(1,{xtype:"tbbutton",text:this.renameText,icon:this.renameIcon,scope:this,
handler:this.rename});toolbar.doLayout()},rename:function(){var grid=this.getGrid();var selected=grid.getSelectionModel().getSelected();if(selected){var oldUsername=selected.get("name");Ext.Msg.prompt(this.newUsernameTitle,this.newUsernameText,function(btn,newUsername){if(btn=="ok")this.renameUser(oldUsername,newUsername)},this)}else if(debug)console.debug("no user selected")},renameUser:function(oldUsername,newUsername){var url=restUrl+"plugis/userrename.json?oldUsername="+oldUsername;url+="&newUsername="+
newUsername;Ext.Ajax.request({url:url,method:"POST",scope:this,success:function(){this.reload();this.resetPanel();var repositoriesPanel=Ext.getCmp("repositories");if(repositoriesPanel)repositoriesPanel.reload()},failure:function(result){main.handleRestFailure(result,this.errorTitleText,this.renameErrorText)}})}});