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.

188 lines
7.4 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. idleInterval: 2,
  47. autoScroll: true,
  48. root: {
  49. text: gettext("Loading..."),
  50. leaf: true
  51. }
  52. });
  53. Ext.applyIf( this, {
  54. // This stuff needs the above applied already
  55. // x-btn x-btn-noicon
  56. bbar: [ gettext("Auto-Refresh")+':', {
  57. xtype: "checkbox",
  58. ref: "../cbAutoRefresh",
  59. scope: this,
  60. handler: this.setAutoRefresh,
  61. checked: (this.refreshInterval > 0),
  62. }, {
  63. xtype: "numberfield",
  64. width: 30,
  65. value: this.refreshInterval / 1000,
  66. ref: "../nfAutoRefreshInterval",
  67. scope: this,
  68. listeners: {
  69. render: function(c) {
  70. Ext.QuickTips.register({
  71. target: c.getEl(),
  72. text: gettext('Enter the interval in seconds in which the channel viewer should refresh and hit Enter.')
  73. });
  74. },
  75. specialkey: function( field, ev ){
  76. if( ev.getKey() == ev.ENTER ){
  77. this.scope.setAutoRefresh(); // lawl
  78. }
  79. }
  80. },
  81. }, gettext("Seconds"), '->', {
  82. xtype: "button",
  83. template: null,
  84. text: gettext("Refresh"),
  85. handler: this.refresh,
  86. scope: this
  87. }]
  88. } );
  89. Ext.ux.MumbleChannelViewer.superclass.constructor.call( this );
  90. this.autoRefreshId = 0;
  91. this.setAutoRefresh();
  92. }
  93. Ext.extend( Ext.ux.MumbleChannelViewer, Ext.tree.TreePanel, {
  94. setAutoRefresh: function(){
  95. if( this.autoRefreshId != 0 ){
  96. clearTimeout( this.autoRefreshId );
  97. }
  98. if( this.cbAutoRefresh.getValue() ){
  99. this.refreshInterval = this.nfAutoRefreshInterval.getValue() * 1000;
  100. this.autoRefresh();
  101. }
  102. else{
  103. this.refreshInterval = 0;
  104. }
  105. },
  106. autoRefresh: function(){
  107. this.refresh();
  108. if( this.refreshInterval > 0 ){
  109. this.autoRefreshId = this.autoRefresh.defer( this.refreshInterval, this );
  110. }
  111. },
  112. refresh: function(){
  113. var conn = new Ext.data.Connection();
  114. conn.request({
  115. url: this.source_url,
  116. scope: this,
  117. success: function( resp, opt ){
  118. var respdata = Ext.decode( resp.responseText );
  119. var root = {
  120. text: respdata.name,
  121. id: "mumbroot",
  122. leaf: false,
  123. icon: '/static/mumble/mumble.16x16.png',
  124. children: [],
  125. };
  126. function populateNode( node, json ){
  127. var subchan_users = 0;
  128. for( var i = 0; i < json.channels.length; i++ ){
  129. var child = {
  130. text: json.channels[i].name,
  131. id: ("channel_" + json.channels[i].id),
  132. leaf: true,
  133. icon: '/static/mumble/channel.png',
  134. children: [],
  135. uiProvider: Ext.ux.MumbleChannelNodeUI,
  136. chandata: json.channels[i]
  137. };
  138. node.leaf = false;
  139. node.children.push( child );
  140. subchan_users += populateNode( child, json.channels[i] );
  141. }
  142. for( var i = 0; i < json.users.length; i++ ){
  143. var child = {
  144. text: json.users[i].name,
  145. id: ("user_" + json.users[i].session),
  146. leaf: true,
  147. uiProvider: Ext.ux.MumbleUserNodeUI,
  148. userdata: json.users[i]
  149. };
  150. if( json.users[i].idlesecs <= this.idleInterval )
  151. child.icon = '/static/mumble/talking_on.png';
  152. else
  153. child.icon = '/static/mumble/talking_off.png';
  154. node.leaf = false;
  155. node.children.push( child );
  156. }
  157. if( json.id == 0 || json.users.length > 0 || subchan_users )
  158. node.expanded = true;
  159. return subchan_users + json.users.length;
  160. }
  161. populateNode( root, respdata.root );
  162. this.setRootNode( root );
  163. },
  164. failure: function( resp, opt ){
  165. if( this.refreshInterval > 0 )
  166. this.cbAutoRefresh.setValue(false);
  167. Ext.Msg.show({
  168. title: gettext("Update error"),
  169. msg: gettext("Querying the server failed, so the channel viewer has not been updated."),
  170. icon: Ext.MessageBox.ERROR,
  171. buttons: Ext.MessageBox.OK
  172. });
  173. },
  174. });
  175. },
  176. } );
  177. Ext.reg( 'mumblechannelviewer', Ext.ux.MumbleChannelViewer );