From 98c96f8c805b698a42592bf9509fdeeb837ac2bb Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 13 Nov 2010 11:54:51 +0100 Subject: [PATCH] improve sonia.user --- .../main/webapp/resources/js/sonia.global.js | 6 +- .../main/webapp/resources/js/sonia.user.js | 115 ++++++++++++++++-- 2 files changed, 111 insertions(+), 10 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.global.js b/scm-webapp/src/main/webapp/resources/js/sonia.global.js index 0c1b278393..57140cd755 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.global.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.global.js @@ -33,6 +33,9 @@ var debug = true; var state = null; +// sonia.scm.api.rest.resources.UserResource.DUMMY_PASSWORT +var dummyPassword = '__dummypassword__'; + // functions called after login var loginCallbacks = []; @@ -89,4 +92,5 @@ function logout(){ }); } -Ext.QuickTips.init(); \ No newline at end of file +// enable extjs quicktips +Ext.QuickTips.init(); diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.user.js b/scm-webapp/src/main/webapp/resources/js/sonia.user.js index 5d527454ad..7b1532b691 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.user.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.user.js @@ -70,7 +70,31 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { }, selectItem: function(item){ - console.debug( item ); + if ( debug ){ + console.debug( item.name + ' selected' ); + } + var editPanel = Ext.getCmp('userEditPanel'); + editPanel.removeAll(); + var panel = new Sonia.user.FormPanel({ + item: item, + region: 'south', + title: 'User Form', + padding: 5, + onUpdate: { + fn: this.reload, + scope: this + }, + onCreate: { + fn: this.reload, + scope: this + } + }); + panel.getForm().setValues([ + {id: 'password', value: dummyPassword}, + {id: 'password-confirm', value: dummyPassword} + ]); + editPanel.add(panel); + editPanel.doLayout(); } }); @@ -78,7 +102,7 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { // register xtype Ext.reg('userGrid', Sonia.user.Grid); - +// passord validator Ext.apply(Ext.form.VTypes, { password: function(val, field) { if (field.initialPassField) { @@ -119,7 +143,7 @@ Sonia.user.FormPanel = Ext.extend(Sonia.rest.FormPanel,{ maxLength: 32, minLengthText: 'Password must be at least 6 characters long.' },{ - name: 'password', + name: 'password-confirm', inputType: 'password', minLength: 6, maxLength: 32, @@ -134,8 +158,28 @@ Sonia.user.FormPanel = Ext.extend(Sonia.rest.FormPanel,{ }, update: function(item){ - console.debug('update user'); - console.debug(item); + + item = Ext.apply( this.item, item ); + if ( debug ){ + console.debug( 'update user: ' + item.name ); + } + var url = restUrl + 'users/' + item.name + '.json'; + Ext.Ajax.request({ + url: url, + jsonData: item, + method: 'PUT', + scope: this, + success: function(){ + if ( debug ){ + console.debug('update success'); + } + this.execCallback(this.onUpdate, item); + }, + failure: function(){ + alert( 'failure' ); + } + }); + }, create: function(user){ @@ -182,7 +226,7 @@ Sonia.user.Panel = Ext.extend(Ext.Panel, { autoScroll: true, tbar: [ {xtype: 'tbbutton', text: 'Add', scope: this, handler: this.showAddPanel}, - {xtype: 'tbbutton', text: 'Remove', scope: this, handler: this.remove}, + {xtype: 'tbbutton', text: 'Remove', scope: this, handler: this.removeUser}, '-', {xtype: 'tbbutton', text: 'Reload', scope: this, handler: this.reload}, ], @@ -230,13 +274,66 @@ Sonia.user.Panel = Ext.extend(Ext.Panel, { editPanel.add(panel); editPanel.doLayout(); }, + + resetPanel: function(){ + var editPanel = Ext.getCmp('userEditPanel'); + editPanel.removeAll(); + editPanel.add({ + region: 'south', + title: 'User Form', + padding: 5, + xtype: 'panel', + html: 'Add or select an User' + }); + editPanel.doLayout(); + }, + + removeUser: function(){ + + var grid = Ext.getCmp('userGrid'); + var selected = grid.getSelectionModel().getSelected(); + if ( selected ){ + var item = selected.data; + var url = restUrl + 'users/' + item.name + '.json'; + + Ext.MessageBox.show({ + title: 'Remove User', + msg: 'Remove User "' + item.name + '"?', + buttons: Ext.MessageBox.OKCANCEL, + icon: Ext.MessageBox.QUESTION, + fn: function(result){ + if ( result == 'ok' ){ + + if ( debug ){ + console.debug( 'remove user ' + item.name ); + } + + Ext.Ajax.request({ + url: url, + method: 'DELETE', + scope: this, + success: function(){ + this.reload(); + this.resetPanel(); + }, + failure: function(){ + alert( 'failure' ); + } + }); + } + + }, + scope: this + }); + + } else if ( debug ){ + console.debug( 'no repository selected' ); + } - remove: function(){ - console.debug( 'remove' ); }, reload: function(){ - console.debug( 'reload' ); + Ext.getCmp('userGrid').reload(); } });