diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py index 431deb4..a566ce8 100644 --- a/pyweb/mumble/urls.py +++ b/pyweb/mumble/urls.py @@ -18,7 +18,8 @@ from django.conf.urls.defaults import * urlpatterns = patterns( 'mumble.views', - ( r'(?P\d+)/users', 'users' ), + ( r'djangousers', 'djangousers' ), + ( r'(?P\d+)/users', 'users' ), ( r'(?P\d+)/(?P\d+)texture.png', 'showTexture' ), ( r'(?P\d+)/texture.png', 'showTexture' ), ( r'(?P\d+)', 'show' ), diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 326f769..f0e6224 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -188,7 +188,6 @@ def users( request, server ): if request.method == 'POST': data = simplejson.loads( request.POST['data'] ); - print "Json: ", data; for record in data: if record['id'] == -1: if record['delete']: @@ -204,25 +203,22 @@ def users( request, server ): mu.password = record['password']; mu.isAdmin = record['admin']; - if record['owner_id']: - mu.owner = User.objects.get( id=int(record['owner_id']) ); + if record['owner']: + mu.owner = User.objects.get( id=int(record['owner']) ); mu.save(); users = []; for mu in srv.mumbleuser_set.all(): owner = None; - owner_id = None; if mu.owner is not None: - owner = unicode( mu.owner ); - owner_id = mu.owner.id + owner = mu.owner.id users.append( { 'id': mu.id, 'name': mu.name, 'password': None, 'owner': owner, - 'owner_id': owner_id, 'admin': mu.getAdmin(), } ); @@ -232,6 +228,19 @@ def users( request, server ): ); - +@login_required +def djangousers( request ): + "Return a list of all Django users' names and IDs." + users = [ { 'uid': '', 'uname': '------' } ]; + for du in User.objects.all(): + users.append( { + 'uid': du.id, + 'uname': unicode( du ), + } ); + + return HttpResponse( + simplejson.dumps( { 'success': True, 'objects': users } ), + mimetype='text/javascript' + ); diff --git a/template/mumble/mumble.htm b/template/mumble/mumble.htm index f5927ee..2eea754 100644 --- a/template/mumble/mumble.htm +++ b/template/mumble/mumble.htm @@ -149,8 +149,7 @@ { name: 'id', type: 'int' }, { name: 'name', type: 'string' }, { name: 'password', type: 'string' }, - { name: 'owner', type: 'string' }, - { name: 'owner_id', type: 'int' }, + { name: 'owner', type: 'int' }, { name: 'admin', type: 'bool' }, { name: 'delete', type: 'bool' }, ]); @@ -167,11 +166,30 @@ adminColumn = new Ext.grid.CheckColumn({ header: '{% trans "Admin on root channel" %}', dataIndex: 'admin', + width: 50, }); deleteColumn = new Ext.grid.CheckColumn({ header: '{% trans "Delete" %}', dataIndex: 'delete', + width: 50, + }); + + ownerCombo = new Ext.form.ComboBox({ + name: 'owner', + hiddenName: 'owner_id', + forceSelection: true, + triggerAction: 'all', + valueField: 'uid', + displayField: 'uname', + store: new Ext.data.Store({ + url: '/mumble/djangousers', + reader: new Ext.data.JsonReader({ + fields: [ 'uid', 'uname' ], + root: 'objects', + }), + autoLoad: true, + }), }); {% endif %} @@ -210,13 +228,25 @@ }, { header: '{% trans "Account owner" %}', dataIndex: 'owner', - editor: new Ext.form.TextField(), + editor: ownerCombo, + renderer: function( value ){ + if( value == '' ) return ''; + idx = ownerCombo.store.find( 'uid', value ); + rec = ownerCombo.store.getAt( idx ); + return rec.get( 'uname' ); + }, }, adminColumn, { header: '{% trans "Change password" %}', dataIndex: 'password', editor: new Ext.form.TextField({ inputType: 'password', }), + renderer: function( value ){ + ret = ''; + for( i = 0; i < value.length; i++ ) + ret += '*'; + return ret; + }, }, deleteColumn ] ), tbar: [{ text: '{% trans "Add" %}', @@ -225,9 +255,8 @@ id: -1, name: 'New User', admin: false, - owner: null, - owner_id: null, - password: null, + owner: '', + password: '', 'delete': false, } ) ); }