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.

149 lines
4.2 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: MumbleUserAdmin.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: MumbleUserAdmin.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. buttons: [{
  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. scope: this,
  94. handler : function(){
  95. var data = [];
  96. for( i = 0; i < userAdminStore.data.items.length; i++ ){
  97. var rec = userAdminStore.data.items[i];
  98. if( rec.dirty ){
  99. data.push(rec.data);
  100. }
  101. }
  102. MumbleUserAdmin.update( this.server, data, function(provider, response){
  103. if( response.result.success ){
  104. for( i = 0; i < userAdminStore.data.items.length; i++ ){
  105. rec = userAdminStore.data.items[i];
  106. if( rec.data['delete'] == true )
  107. userAdminStore.remove( rec );
  108. else if( rec.dirty ){
  109. rec.commit();
  110. }
  111. }
  112. }
  113. else{
  114. Ext.Msg.show({
  115. title: gettext("Submit error"),
  116. msg: gettext("Unable to save."),
  117. icon: Ext.MessageBox.ERROR,
  118. buttons: Ext.MessageBox.OK
  119. });
  120. }
  121. });
  122. }
  123. }, {
  124. text: gettext("Resync with Murmur"),
  125. handler: function(){
  126. userAdminStore.reload({
  127. params: { 'resync': 'true' }
  128. });
  129. }
  130. }],
  131. plugins: [ adminColumn, deleteColumn ]
  132. });
  133. Ext.ux.UserEditorPanel.superclass.constructor.call( this );
  134. };
  135. Ext.extend( Ext.ux.UserEditorPanel, Ext.grid.EditorGridPanel, {
  136. } );
  137. Ext.reg( 'userEditorPanel', Ext.ux.UserEditorPanel );