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.

242 lines
9.4 KiB

  1. // kate: space-indent on; indent-width 4; replace-tabs on;
  2. Ext.namespace('Ext.ux');
  3. if( typeof gettext == "undefined" ){
  4. // Cope with Django's jsi18n not being available by adding dummy gettext
  5. gettext = function( text ){
  6. return text;
  7. };
  8. gettext_noop = gettext;
  9. }
  10. Ext.ux.MumbleChannelNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  11. renderElements : function(n, a, targetNode, bulkRender){
  12. Ext.ux.MumbleUserNodeUI.superclass.renderElements.call( this, n, a, targetNode, bulkRender );
  13. Ext.DomHelper.applyStyles( this.elNode, 'position: relative' );
  14. var tpl = new Ext.DomHelper.createTemplate(
  15. '<img style="position: absolute; top: 0px; right: {pos}px;" src="{imageurl}/{icon}.png"/>'
  16. );
  17. var icons = []
  18. if( a.chandata.description != "" ) icons.push( "comment_seen" );
  19. var pos = 8;
  20. for( var i = 0; i < icons.length; i++ ){
  21. tpl.append( this.elNode, {'imageurl': a.imageurl, 'icon': icons[i], 'pos': pos} );
  22. pos += 18
  23. }
  24. }
  25. });
  26. Ext.ux.MumbleUserNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  27. renderElements : function(n, a, targetNode, bulkRender){
  28. Ext.ux.MumbleUserNodeUI.superclass.renderElements.call( this, n, a, targetNode, bulkRender );
  29. Ext.DomHelper.applyStyles( this.elNode, 'position: relative' );
  30. var tpl = new Ext.DomHelper.createTemplate(
  31. '<img style="position: absolute; top: 0px; right: {pos}px;" src="{imageurl}/{icon}.png"/>'
  32. );
  33. var icons = []
  34. if( a.userdata.userid != -1 ) icons.push( "authenticated" );
  35. if( a.userdata.selfDeaf ) icons.push( "deafened_self" );
  36. if( a.userdata.deaf ) icons.push( "deafened_server" );
  37. if( a.userdata.selfMute ) icons.push( "muted_self" );
  38. if( a.userdata.suppress ) icons.push( "muted_suppressed" );
  39. if( a.userdata.mute ) icons.push( "muted_server" );
  40. if( a.userdata.comment != "" ) icons.push( "comment_seen" );
  41. if( a.userdata.prioritySpeaker ) icons.push( "priority_speaker" );
  42. if( a.userdata.recording ) icons.push( "recording" );
  43. var pos = 8;
  44. for( var i = 0; i < icons.length; i++ ){
  45. tpl.append( this.elNode, {'imageurl': a.imageurl, 'icon': icons[i], 'pos': pos} );
  46. pos += 18
  47. }
  48. }
  49. });
  50. function cmp_channels( left, rite ){
  51. // Compare two channels, first by position, and if that equals, by name.
  52. if( typeof left.position != "undefined" && typeof rite.position != "undefined" ){
  53. byorder = left.position - rite.position;
  54. if( byorder != 0 )
  55. return byorder;
  56. }
  57. return left.name.localeCompare(rite.name);
  58. }
  59. function cmp_names( left, rite ){
  60. return left.name.localeCompare(rite.name);
  61. }
  62. Ext.ux.MumbleChannelViewer = function( config ){
  63. Ext.apply( this, config );
  64. Ext.applyIf( this, {
  65. title: gettext("Channel Viewer"),
  66. refreshInterval: 30000,
  67. idleInterval: 2,
  68. autoScroll: true,
  69. enableDD: false, // Users need to enable this explicitly
  70. root: {
  71. text: gettext("Loading..."),
  72. leaf: true
  73. },
  74. listeners: {}
  75. });
  76. Ext.applyIf( this.listeners, {
  77. dragdrop: function( tree, node, targetdd, ev ){
  78. if( typeof node.attributes.userdata != "undefined" )
  79. tree.fireEvent("moveUser", tree, node.attributes.userdata, targetdd.dragOverData.target.attributes.chandata);
  80. else if( typeof node.attributes.chandata != "undefined" )
  81. tree.fireEvent("moveChannel", tree, node.attributes.chandata, targetdd.dragOverData.target.attributes.chandata);
  82. }
  83. });
  84. Ext.applyIf( this, {
  85. // This stuff needs the above applied already
  86. bbar: [ gettext("Auto-Refresh")+':', {
  87. xtype: "checkbox",
  88. ref: "../cbAutoRefresh",
  89. scope: this,
  90. handler: this.setAutoRefresh,
  91. checked: (this.refreshInterval > 0),
  92. }, {
  93. xtype: "numberfield",
  94. width: 30,
  95. value: this.refreshInterval / 1000,
  96. ref: "../nfAutoRefreshInterval",
  97. scope: this,
  98. selectOnFocus: true,
  99. listeners: {
  100. render: function(c) {
  101. Ext.QuickTips.register({
  102. target: c.getEl(),
  103. text: gettext('Enter the interval in seconds in which the channel viewer should refresh and hit Enter.')
  104. });
  105. },
  106. specialkey: function( field, ev ){
  107. if( ev.getKey() == ev.ENTER ){
  108. this.scope.setAutoRefresh(); // lawl
  109. this.blur();
  110. }
  111. }
  112. },
  113. }, gettext("Seconds"), '->', {
  114. xtype: "button",
  115. text: gettext("Refresh"),
  116. handler: this.refresh,
  117. scope: this
  118. }]
  119. } );
  120. Ext.ux.MumbleChannelViewer.superclass.constructor.call( this );
  121. this.addEvents({
  122. 'moveUser': true,
  123. 'moveChannel': true
  124. });
  125. this.autoRefreshId = 0;
  126. this.setAutoRefresh();
  127. }
  128. Ext.extend( Ext.ux.MumbleChannelViewer, Ext.tree.TreePanel, {
  129. setAutoRefresh: function(){
  130. if( this.autoRefreshId != 0 ){
  131. clearTimeout( this.autoRefreshId );
  132. }
  133. if( this.cbAutoRefresh.getValue() ){
  134. this.refreshInterval = this.nfAutoRefreshInterval.getValue() * 1000;
  135. this.autoRefresh();
  136. }
  137. else{
  138. this.refreshInterval = 0;
  139. }
  140. },
  141. autoRefresh: function(){
  142. this.refresh();
  143. if( this.refreshInterval > 0 ){
  144. this.autoRefreshId = this.autoRefresh.defer( this.refreshInterval, this );
  145. }
  146. },
  147. refresh: function(){
  148. var conn = new Ext.data.Connection();
  149. conn.request({
  150. url: this.source_url,
  151. scope: this,
  152. success: function( resp, opt ){
  153. var respdata = Ext.decode( resp.responseText );
  154. var root = {
  155. text: respdata.name,
  156. nodeType: 'async',
  157. id: "mumbroot",
  158. leaf: false,
  159. icon: this.imageurl+'/mumble.16x16.png',
  160. children: [],
  161. chandata: respdata.root,
  162. imageurl: this.imageurl
  163. };
  164. tree = this;
  165. function populateNode( node, json ){
  166. var subchan_users = 0;
  167. json.channels.sort(cmp_channels);
  168. for( var i = 0; i < json.channels.length; i++ ){
  169. var child = {
  170. text: json.channels[i].name,
  171. id: ("channel_" + json.channels[i].id),
  172. nodeType: 'async',
  173. allowDrag: true,
  174. allowDrop: true,
  175. draggable: true,
  176. icon: tree.imageurl+'/channel.png',
  177. children: [],
  178. uiProvider: Ext.ux.MumbleChannelNodeUI,
  179. chandata: json.channels[i],
  180. imageurl: tree.imageurl
  181. };
  182. node.children.push( child );
  183. subchan_users += populateNode( child, json.channels[i] );
  184. }
  185. json.users.sort(cmp_names);
  186. for( var i = 0; i < json.users.length; i++ ){
  187. var child = {
  188. text: json.users[i].name,
  189. id: ("user_" + json.users[i].session),
  190. nodeType: 'async',
  191. leaf: true,
  192. allowDrag: true,
  193. draggable: true,
  194. uiProvider: Ext.ux.MumbleUserNodeUI,
  195. userdata: json.users[i],
  196. imageurl: tree.imageurl
  197. };
  198. if( json.users[i].idlesecs <= this.idleInterval )
  199. child.icon = tree.imageurl+'/talking_on.png';
  200. else
  201. child.icon = tree.imageurl+'/talking_off.png';
  202. node.leaf = false;
  203. node.children.push( child );
  204. }
  205. if( json.id == 0 || json.users.length > 0 || subchan_users )
  206. node.expanded = true;
  207. return subchan_users + json.users.length;
  208. }
  209. populateNode( root, respdata.root );
  210. this.setRootNode( root );
  211. },
  212. failure: function( resp, opt ){
  213. if( this.refreshInterval > 0 )
  214. this.cbAutoRefresh.setValue(false);
  215. Ext.Msg.show({
  216. title: gettext("Update error"),
  217. msg: gettext("Querying the server failed, so the channel viewer has not been updated."),
  218. icon: Ext.MessageBox.ERROR,
  219. buttons: Ext.MessageBox.OK
  220. });
  221. },
  222. });
  223. },
  224. } );
  225. Ext.reg( 'mumblechannelviewer', Ext.ux.MumbleChannelViewer );