Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.6 KiB

  1. // kate: space-indent on; indent-width 4; replace-tabs on;
  2. Ext.namespace('Ext.ux');
  3. Ext.ux.MumbleUserNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  4. renderElements : function(n, a, targetNode, bulkRender){
  5. Ext.ux.MumbleUserNodeUI.superclass.renderElements.call( this, n, a, targetNode, bulkRender );
  6. Ext.DomHelper.applyStyles( this.elNode, 'position: relative' );
  7. var tpl = new Ext.DomHelper.createTemplate( '<img style="position: absolute; top: 0px; right: {pos}px;" src="/static/mumble/{icon}.png"/>' );
  8. icons = []
  9. if( a.userdata.userid != 0 ) icons.push( "authenticated" );
  10. if( a.userdata.selfMute ) icons.push( "muted_self" );
  11. if( a.userdata.mute ) icons.push( "muted_server" );
  12. if( a.userdata.suppress ) icons.push( "muted_suppressed" );
  13. if( a.userdata.selfDeaf ) icons.push( "deafened_self" );
  14. if( a.userdata.deaf ) icons.push( "deafened_server" );
  15. if( a.userdata.comment!="" ) icons.push( "comment_seen" );
  16. var pos = 8;
  17. for( var i = 0; i < icons.length; i++ ){
  18. tpl.append( this.elNode, {'icon': icons[i], 'pos': pos} );
  19. pos += 18
  20. }
  21. }
  22. });
  23. Ext.ux.MumbleChannelViewer = function( config ){
  24. Ext.apply( this, config );
  25. Ext.applyIf( this, {
  26. title: gettext("Channel Viewer"),
  27. refreshInterval: 10000,
  28. autoScroll: true,
  29. root: {
  30. text: gettext("Loading..."),
  31. leaf: true
  32. },
  33. buttons: [{
  34. text: gettext("Refresh"),
  35. handler: this.refresh,
  36. scope: this
  37. }],
  38. } );
  39. Ext.ux.MumbleChannelViewer.superclass.constructor.call( this );
  40. this.autoRefresh();
  41. }
  42. Ext.extend( Ext.ux.MumbleChannelViewer, Ext.tree.TreePanel, {
  43. autoRefresh: function(){
  44. this.refresh();
  45. if( this.refreshInterval > 0 ){
  46. //this.autoRefresh.defer( this.refreshInterval, this );
  47. }
  48. },
  49. refresh: function(){
  50. var conn = new Ext.data.Connection();
  51. conn.request({
  52. url: this.source_url,
  53. scope: this,
  54. success: function( resp, opt ){
  55. var respdata = Ext.decode( resp.responseText );
  56. var root = {
  57. text: respdata.name,
  58. id: "mumbroot",
  59. leaf: false,
  60. icon: '/static/mumble/mumble.16x16.png',
  61. children: [],
  62. };
  63. function populateNode( node, json ){
  64. var subchan_users = 0;
  65. for( var i = 0; i < json.channels.length; i++ ){
  66. var child = {
  67. text: json.channels[i].name,
  68. id: ("channel_" + json.channels[i].id),
  69. leaf: true,
  70. icon: '/static/mumble/channel.png',
  71. children: [],
  72. };
  73. node.leaf = false;
  74. node.children.push( child );
  75. subchan_users += populateNode( child, json.channels[i] );
  76. }
  77. for( var i = 0; i < json.users.length; i++ ){
  78. var child = {
  79. text: json.users[i].name,
  80. id: ("user_" + json.users[i].id),
  81. leaf: true,
  82. uiProvider: Ext.ux.MumbleUserNodeUI,
  83. userdata: json.users[i]
  84. };
  85. if( json.users[i].idlesecs == 0 )
  86. child.icon = '/static/mumble/talking_on.png';
  87. else
  88. child.icon = '/static/mumble/talking_off.png';
  89. node.leaf = false;
  90. node.children.push( child );
  91. }
  92. if( json.id == 0 || json.users.length > 0 || subchan_users )
  93. node.expanded = true;
  94. return subchan_users + json.users.length;
  95. }
  96. populateNode( root, respdata.root );
  97. this.setRootNode( root );
  98. },
  99. failure: function( resp, opt ){
  100. if( this.refreshInterval > 0 )
  101. if( this.refreshInterval < 300000 )
  102. this.refreshInterval = 300000;
  103. else
  104. this.refreshInterval = 0;
  105. },
  106. });
  107. },
  108. } );
  109. Ext.reg( 'mumblechannelviewer', Ext.ux.MumbleChannelViewer );