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.

138 lines
5.5 KiB

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