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.

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