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.

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