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.

194 lines
7.7 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="{imageurl}/{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, {'imageurl': a.imageurl, '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="{imageurl}/{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, {'imageurl': a.imageurl, '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: this.imageurl+'/mumble.16x16.png',
  126. children: [],
  127. imageurl: this.imageurl
  128. };
  129. tree = this;
  130. function populateNode( node, json ){
  131. var subchan_users = 0;
  132. for( var i = 0; i < json.channels.length; i++ ){
  133. var child = {
  134. text: json.channels[i].name,
  135. id: ("channel_" + json.channels[i].id),
  136. leaf: true,
  137. icon: tree.imageurl+'/channel.png',
  138. children: [],
  139. uiProvider: Ext.ux.MumbleChannelNodeUI,
  140. chandata: json.channels[i],
  141. imageurl: tree.imageurl
  142. };
  143. node.leaf = false;
  144. node.children.push( child );
  145. subchan_users += populateNode( child, json.channels[i] );
  146. }
  147. for( var i = 0; i < json.users.length; i++ ){
  148. var child = {
  149. text: json.users[i].name,
  150. id: ("user_" + json.users[i].session),
  151. leaf: true,
  152. uiProvider: Ext.ux.MumbleUserNodeUI,
  153. userdata: json.users[i],
  154. imageurl: tree.imageurl
  155. };
  156. if( json.users[i].idlesecs <= this.idleInterval )
  157. child.icon = tree.imageurl+'/talking_on.png';
  158. else
  159. child.icon = tree.imageurl+'/talking_off.png';
  160. node.leaf = false;
  161. node.children.push( child );
  162. }
  163. if( json.id == 0 || json.users.length > 0 || subchan_users )
  164. node.expanded = true;
  165. return subchan_users + json.users.length;
  166. }
  167. populateNode( root, respdata.root );
  168. this.setRootNode( root );
  169. },
  170. failure: function( resp, opt ){
  171. if( this.refreshInterval > 0 )
  172. this.cbAutoRefresh.setValue(false);
  173. Ext.Msg.show({
  174. title: gettext("Update error"),
  175. msg: gettext("Querying the server failed, so the channel viewer has not been updated."),
  176. icon: Ext.MessageBox.ERROR,
  177. buttons: Ext.MessageBox.OK
  178. });
  179. },
  180. });
  181. },
  182. } );
  183. Ext.reg( 'mumblechannelviewer', Ext.ux.MumbleChannelViewer );