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.

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