From 13c86e9cae2e2cd96f62a3d6cdcb0035ea7628e1 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Thu, 12 Aug 2010 12:11:52 +0200 Subject: [PATCH] implement moving channels via drag&drop, don't set leaf:true on channels so they can be drop targets --- pyweb/mumble/MumbleCtlDbus.py | 5 +++++ pyweb/mumble/MumbleCtlIce.py | 7 +++++++ pyweb/mumble/media/js/channelviewer.js | 6 +++--- pyweb/mumble/models.py | 3 +++ pyweb/mumble/templates/mumble/mumble.html | 5 ++++- pyweb/mumble/views.py | 21 ++++++++++++++------- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pyweb/mumble/MumbleCtlDbus.py b/pyweb/mumble/MumbleCtlDbus.py index 8557d96..2118bba 100644 --- a/pyweb/mumble/MumbleCtlDbus.py +++ b/pyweb/mumble/MumbleCtlDbus.py @@ -306,6 +306,11 @@ class MumbleCtlDbus_118(MumbleCtlBase): (session, ismute, isdeaf, suppressed, selfMute, selfDeaf, channel) = srv.getPlayerState(dbus.UInt32(sessionid)) srv.setPlayerState((session, ismute, deaf, suppressed, selfMute, selfDeaf, channel)) + def moveChannel(self, srvid, channelid, parentid): + srv = self._getDbusServerObject(srvid) + (chanid, name, parent, links) = srv.getChannelState(dbus.UInt32(channelid)) + srv.setChannelState((chanid, name, parentid, links)) + @staticmethod def convertDbusTypeToNative(data): #i know dbus.* type is extends python native type. diff --git a/pyweb/mumble/MumbleCtlIce.py b/pyweb/mumble/MumbleCtlIce.py index c7ccf12..21dd20f 100644 --- a/pyweb/mumble/MumbleCtlIce.py +++ b/pyweb/mumble/MumbleCtlIce.py @@ -434,6 +434,13 @@ class MumbleCtlIce_118(MumbleCtlBase): def getLog( self, srvid, first=0, last=100 ): return self._getIceServerObject(srvid).getLog( first, last ) + @protectDjangoErrPage + def moveChannel(self, srvid, channelid, parentid): + srv = self._getIceServerObject(srvid) + state = srv.getChannelState(channelid) + state.parent = parentid + srv.setChannelState(state) + @protectDjangoErrPage def moveUser(self, srvid, sessionid, channelid): srv = self._getIceServerObject(srvid) diff --git a/pyweb/mumble/media/js/channelviewer.js b/pyweb/mumble/media/js/channelviewer.js index 09f6c4d..e2db484 100644 --- a/pyweb/mumble/media/js/channelviewer.js +++ b/pyweb/mumble/media/js/channelviewer.js @@ -77,6 +77,8 @@ Ext.ux.MumbleChannelViewer = function( config ){ dragdrop: function( tree, node, targetdd, ev ){ if( typeof node.attributes.userdata != "undefined" ) tree.fireEvent("moveUser", tree, node.attributes.userdata, targetdd.dragOverData.target.attributes.chandata); + else if( typeof node.attributes.chandata != "undefined" ) + tree.fireEvent("moveChannel", tree, node.attributes.chandata, targetdd.dragOverData.target.attributes.chandata); } }); @@ -121,7 +123,7 @@ Ext.ux.MumbleChannelViewer = function( config ){ this.addEvents({ 'moveUser': true, - 'moveChannel': true //TODO + 'moveChannel': true }); this.autoRefreshId = 0; @@ -174,7 +176,6 @@ Ext.extend( Ext.ux.MumbleChannelViewer, Ext.tree.TreePanel, { text: json.channels[i].name, id: ("channel_" + json.channels[i].id), nodeType: 'async', - leaf: true, allowDrag: true, allowDrop: true, draggable: true, @@ -184,7 +185,6 @@ Ext.extend( Ext.ux.MumbleChannelViewer, Ext.tree.TreePanel, { chandata: json.channels[i], imageurl: tree.imageurl }; - node.leaf = false; node.children.push( child ); subchan_users += populateNode( child, json.channels[i] ); } diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index c79eef2..c02bdce 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -566,6 +566,9 @@ class Mumble( models.Model ): def deafenUser( self, sessionid, deafen=True ): return self.ctl.moveUser( self.srvid, sessionid, deafen ) + def moveChannel( self, channelid, parentid ): + return self.ctl.moveChannel( self.srvid, channelid, parentid ) + def getLog( self, first=0, last=100, filter="" ): """ Return log entries from ``first`` to ``last`` that contain ``filter`` (if any). """ logentries = self.ctl.getLog( self.srvid, first, last ) diff --git a/pyweb/mumble/templates/mumble/mumble.html b/pyweb/mumble/templates/mumble/mumble.html index b10b24e..5f5a90a 100644 --- a/pyweb/mumble/templates/mumble/mumble.html +++ b/pyweb/mumble/templates/mumble/mumble.html @@ -63,7 +63,10 @@ imageurl: '{{MUMBLE_MEDIA_PREFIX}}/img', listeners: { moveUser: function( tree, userdata, chandata ){ - User.move( {{MumbleServer.id}}, userdata.session, chandata.id ) + Mumble.moveUser( {{MumbleServer.id}}, userdata.session, chandata.id ); + }, + moveChannel: function( tree, chandata, targetdata ){ + Mumble.moveChannel( {{MumbleServer.id}}, chandata.id, targetdata.id ); } } }, { diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 0601e3b..154a2eb 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -244,6 +244,20 @@ def log( request, server, start, limit, filter ): for ent in srv.getLog( start, (start + limit), filter ) ], 'success': True } +@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) +def moveUser( request, server, sessionid, channelid ): + srv = get_object_or_404( Mumble, id=int(server) ) + if not srv.isUserAdmin( request.user ): + raise Exception( 'Access denied' ) + srv.moveUser( sessionid, channelid ) + +@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) +def moveChannel( request, server, channelid, parentid ): + srv = get_object_or_404( Mumble, id=int(server) ) + if not srv.isUserAdmin( request.user ): + raise Exception( 'Access denied' ) + srv.moveChannel( channelid, parentid ) + @EXT_DIRECT_PROVIDER.register_method( "MumbleUserAdmin" ) def users( request, server ): @@ -329,13 +343,6 @@ def update_avatar( request, userid ): return HttpResponse( "false", mimetype="text/html" ) -@EXT_DIRECT_PROVIDER.register_method( "User" ) -def move( request, server, sessionid, channelid ): - srv = get_object_or_404( Mumble, id=int(server) ) - if not srv.isUserAdmin( request.user ): - raise Exception( 'Access denied' ) - srv.moveUser( sessionid, channelid ) - def mmng_tree( request, server ): """ Return a JSON representation of the channel tree suitable for Murmur Manager: