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.

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