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.

143 lines
3.9 KiB

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