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.

157 lines
4.4 KiB

14 years ago
  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, resync: false },
  15. directFn: MumbleUserAdmin.users,
  16. fields: userRecord,
  17. paramOrder: ['server', 'resync'],
  18. autoLoad: true,
  19. remoteSort: false
  20. });
  21. adminColumn = new Ext.grid.CheckColumn({
  22. header: gettext("Admin on root channel"),
  23. dataIndex: 'admin',
  24. width: 50
  25. });
  26. deleteColumn = new Ext.grid.CheckColumn({
  27. header: gettext("Delete"),
  28. dataIndex: 'delete',
  29. width: 50
  30. });
  31. ownerCombo = new Ext.form.ComboBox({
  32. name: 'owner',
  33. hiddenName: 'owner_id',
  34. forceSelection: true,
  35. triggerAction: 'all',
  36. valueField: 'uid',
  37. displayField: 'uname',
  38. store: new Ext.data.DirectStore({
  39. directFn: MumbleUserAdmin.djangousers,
  40. fields: [ 'uid', 'uname' ],
  41. autoLoad: true
  42. })
  43. });
  44. Ext.applyIf( this, {
  45. title: gettext("User List"),
  46. store: userAdminStore,
  47. viewConfig: { forceFit: true },
  48. cm: new Ext.grid.ColumnModel( [ {
  49. header: gettext("name"),
  50. dataIndex: 'name',
  51. sortable: true,
  52. editor: new Ext.form.TextField({
  53. allowBlank: false
  54. })
  55. }, {
  56. header: gettext("Account owner"),
  57. dataIndex: 'owner',
  58. editor: ownerCombo,
  59. sortable: true,
  60. renderer: function( value ){
  61. if( value == '' ) return '';
  62. items = ownerCombo.store.data.items;
  63. for( i = 0; i < items.length; i++ )
  64. if( items[i].data.uid == value )
  65. return items[i].data.uname;
  66. }
  67. }, adminColumn, {
  68. header: gettext("Change password"),
  69. dataIndex: 'password',
  70. editor: new Ext.form.TextField({
  71. inputType: 'password'
  72. }),
  73. renderer: function( value ){
  74. ret = '';
  75. for( i = 0; i < value.length; i++ )
  76. ret += '*';
  77. return ret;
  78. }
  79. }, deleteColumn ] ),
  80. buttons: [{
  81. text: gettext("Add"),
  82. handler : function(){
  83. userAdminStore.add( new userRecord( {
  84. id: -1,
  85. name: gettext('New User'),
  86. admin: false,
  87. owner: '',
  88. password: '',
  89. 'delete': false
  90. } ) );
  91. }
  92. }, {
  93. text: gettext("Save"),
  94. scope: this,
  95. handler : function(){
  96. var data = [];
  97. for( i = 0; i < userAdminStore.data.items.length; i++ ){
  98. var rec = userAdminStore.data.items[i];
  99. if( rec.dirty ){
  100. data.push(rec.data);
  101. }
  102. }
  103. MumbleUserAdmin.update( this.server, data, function(provider, response){
  104. if( response.result.success ){
  105. for( i = 0; i < userAdminStore.data.items.length; i++ ){
  106. rec = userAdminStore.data.items[i];
  107. if( rec.data['delete'] == true )
  108. userAdminStore.remove( rec );
  109. else if( rec.dirty ){
  110. rec.commit();
  111. }
  112. }
  113. }
  114. else{
  115. Ext.Msg.show({
  116. title: gettext("Submit error"),
  117. msg: gettext("Unable to save."),
  118. icon: Ext.MessageBox.ERROR,
  119. buttons: Ext.MessageBox.OK
  120. });
  121. }
  122. });
  123. }
  124. }, {
  125. text: gettext("Refresh"),
  126. handler: function(){
  127. userAdminStore.reload({
  128. params: { 'resync': false }
  129. });
  130. }
  131. }, {
  132. text: gettext("Resync with Murmur"),
  133. handler: function(){
  134. userAdminStore.reload({
  135. params: { 'resync': true }
  136. });
  137. }
  138. }],
  139. plugins: [ adminColumn, deleteColumn ]
  140. });
  141. Ext.ux.UserEditorPanel.superclass.constructor.call( this );
  142. };
  143. Ext.extend( Ext.ux.UserEditorPanel, Ext.grid.EditorGridPanel, {
  144. } );
  145. Ext.reg( 'userEditorPanel', Ext.ux.UserEditorPanel );