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.

94 lines
3.3 KiB

  1. // kate: space-indent on; indent-width 4; replace-tabs on;
  2. Ext.namespace('Ext.ux');
  3. Ext.ux.MumbleChannelViewer = function( config ){
  4. Ext.apply( this, config );
  5. Ext.applyIf( this, {
  6. title: gettext("Channel Viewer"),
  7. refreshInterval: 10000,
  8. autoScroll: true,
  9. root: {
  10. text: gettext("Loading..."),
  11. leaf: true
  12. },
  13. buttons: [{
  14. text: gettext("Refresh"),
  15. handler: this.refresh,
  16. scope: this
  17. }],
  18. } );
  19. Ext.ux.MumbleChannelViewer.superclass.constructor.call( this );
  20. this.autoRefresh();
  21. }
  22. Ext.extend( Ext.ux.MumbleChannelViewer, Ext.tree.TreePanel, {
  23. autoRefresh: function(){
  24. this.refresh();
  25. if( this.refreshInterval > 0 ){
  26. this.autoRefresh.defer( this.refreshInterval, this );
  27. }
  28. },
  29. refresh: function(){
  30. var conn = new Ext.data.Connection();
  31. conn.request({
  32. url: this.source_url,
  33. scope: this,
  34. success: function( resp, opt ){
  35. var respdata = Ext.decode( resp.responseText );
  36. var root = {
  37. text: respdata.name,
  38. id: "mumbroot",
  39. leaf: false,
  40. icon: '/static/mumble/mumble.16x16.png',
  41. children: [],
  42. };
  43. function populateNode( node, json ){
  44. var subchan_users = 0;
  45. for( var i = 0; i < json.channels.length; i++ ){
  46. var child = {
  47. text: json.channels[i].name,
  48. id: ("channel_" + json.channels[i].id),
  49. leaf: true,
  50. icon: '/static/mumble/channel.png',
  51. children: [],
  52. };
  53. node.leaf = false;
  54. node.children.push( child );
  55. subchan_users += populateNode( child, json.channels[i] );
  56. }
  57. for( var i = 0; i < json.users.length; i++ ){
  58. var child = {
  59. text: json.users[i].name,
  60. id: ("user_" + json.users[i].id),
  61. leaf: true,
  62. };
  63. if( json.users[i].idlesecs == 0 )
  64. child.icon = '/static/mumble/talking_on.png';
  65. else
  66. child.icon = '/static/mumble/talking_off.png';
  67. node.leaf = false;
  68. node.children.push( child );
  69. }
  70. if( json.id == 0 || json.users.length > 0 || subchan_users )
  71. node.expanded = true;
  72. return subchan_users + json.users.length;
  73. }
  74. populateNode( root, respdata.root );
  75. this.setRootNode( root );
  76. },
  77. failure: function( resp, opt ){
  78. if( this.refreshInterval > 0 )
  79. if( this.refreshInterval < 300000 )
  80. this.refreshInterval = 300000;
  81. else
  82. this.refreshInterval = 0;
  83. },
  84. });
  85. },
  86. } );
  87. Ext.reg( 'mumblechannelviewer', Ext.ux.MumbleChannelViewer );