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.

147 lines
4.0 KiB

  1. // {% load mumble_extras %}
  2. // {% load i18n %}
  3. // {% comment %}
  4. // kate: space-indent on; indent-width 2; replace-tabs on;
  5. // {% endcomment %}
  6. Ext.namespace('Ext.ux');
  7. Ext.ux.UserEditorPanel = function( config ){
  8. Ext.apply( this, config );
  9. userRecord = Ext.data.Record.create([
  10. { name: 'id', type: 'int' },
  11. { name: 'name', type: 'string' },
  12. { name: 'password', type: 'string' },
  13. { name: 'owner', type: 'int' },
  14. { name: 'admin', type: 'bool' },
  15. { name: 'delete', type: 'bool' }
  16. ]);
  17. userAdminStore = new Ext.data.DirectStore({
  18. baseParams: { server: 1 },
  19. directFn: Mumble.users,
  20. fields: userRecord,
  21. autoLoad: true,
  22. remoteSort: false
  23. });
  24. adminColumn = new Ext.grid.CheckColumn({
  25. header: gettext("Admin on root channel"),
  26. dataIndex: 'admin',
  27. width: 50
  28. });
  29. deleteColumn = new Ext.grid.CheckColumn({
  30. header: gettext("Delete"),
  31. dataIndex: 'delete',
  32. width: 50
  33. });
  34. ownerCombo = new Ext.form.ComboBox({
  35. name: 'owner',
  36. hiddenName: 'owner_id',
  37. forceSelection: true,
  38. triggerAction: 'all',
  39. valueField: 'uid',
  40. displayField: 'uname',
  41. store: new Ext.data.DirectStore({
  42. directFn: Mumble.djangousers,
  43. fields: [ 'uid', 'uname' ],
  44. autoLoad: true
  45. })
  46. });
  47. Ext.applyIf( this, {
  48. title: gettext("User List"),
  49. store: userAdminStore,
  50. viewConfig: { forceFit: true },
  51. cm: new Ext.grid.ColumnModel( [ {
  52. header: gettext("name"),
  53. dataIndex: 'name',
  54. sortable: true,
  55. editor: new Ext.form.TextField({
  56. allowBlank: false
  57. })
  58. }, {
  59. header: gettext("Account owner"),
  60. dataIndex: 'owner',
  61. editor: ownerCombo,
  62. sortable: true,
  63. renderer: function( value ){
  64. if( value == '' ) return '';
  65. items = ownerCombo.store.data.items;
  66. for( i = 0; i < items.length; i++ )
  67. if( items[i].data.uid == value )
  68. return items[i].data.uname;
  69. }
  70. }, adminColumn, {
  71. header: gettext("Change password"),
  72. dataIndex: 'password',
  73. editor: new Ext.form.TextField({
  74. inputType: 'password'
  75. }),
  76. renderer: function( value ){
  77. ret = '';
  78. for( i = 0; i < value.length; i++ )
  79. ret += '*';
  80. return ret;
  81. }
  82. }, deleteColumn ] ),
  83. tbar: [{
  84. text: gettext("Add"),
  85. handler : function(){
  86. userAdminStore.add( new userRecord( {
  87. id: -1,
  88. name: gettext('New User'),
  89. admin: false,
  90. owner: '',
  91. password: '',
  92. 'delete': false
  93. } ) );
  94. }
  95. }, {
  96. text: gettext("Save"),
  97. handler : function(){
  98. data = [];
  99. for( i = 0; i < userAdminStore.data.items.length; i++ ){
  100. rec = userAdminStore.data.items[i];
  101. if( rec.dirty ){
  102. data.push(rec.data);
  103. }
  104. }
  105. var conn = new Ext.data.Connection();
  106. conn.request( {
  107. url: userAdminStore.url,
  108. params: { data: Ext.encode( data ) },
  109. success: function(){
  110. for( i = 0; i < userAdminStore.data.items.length; i++ ){
  111. rec = userAdminStore.data.items[i];
  112. if( rec.data['delete'] == true )
  113. userAdminStore.remove( rec );
  114. else if( rec.dirty ){
  115. rec.commit();
  116. }
  117. }
  118. }
  119. });
  120. }
  121. }, {
  122. text: gettext("Resync with Murmur"),
  123. handler: function(){
  124. userAdminStore.reload({
  125. params: { 'resync': 'true' }
  126. });
  127. }
  128. }],
  129. plugins: [ adminColumn, deleteColumn ]
  130. });
  131. Ext.ux.UserEditorPanel.superclass.constructor.call( this );
  132. };
  133. Ext.extend( Ext.ux.UserEditorPanel, Ext.grid.EditorGridPanel, {
  134. } );
  135. Ext.reg( 'userEditorPanel', Ext.ux.UserEditorPanel );