modx.grid.databasetables.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Loads a grid of all the database tables in the modx database.
  3. *
  4. * @class MODx.grid.DatabaseTables
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-databasetables
  8. */
  9. MODx.grid.DatabaseTables = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('database_tables')
  13. ,id: 'modx-grid-dbtable'
  14. ,url: MODx.config.connector_url
  15. ,baseParams: {
  16. action: 'system/databasetable/getlist'
  17. }
  18. ,fields: ['Name','Rows','Reserved','Data_size','Index_length','Data_free']
  19. ,paging: false
  20. ,columns: [{
  21. header: _('database_table_tablename')
  22. ,dataIndex: 'Name'
  23. ,width: 250
  24. },{
  25. header: _('database_table_records')
  26. ,dataIndex: 'Rows'
  27. ,width: 70
  28. },{
  29. header: _('database_table_reserved')
  30. ,dataIndex: 'Reserved'
  31. ,width: 70
  32. },{
  33. header: _('database_table_datasize')
  34. ,dataIndex: 'Data_size'
  35. ,width: 70
  36. },{
  37. header: _('database_table_indexsize')
  38. ,dataIndex: 'Index_length'
  39. ,width: 70
  40. },{
  41. header: _('database_table_unused')
  42. ,dataIndex: 'Data_free'
  43. ,width: 70
  44. }]
  45. ,tbar: [{
  46. text: _('database_optimize')
  47. ,cls:'primary-button'
  48. ,handler: this.optimizeDatabase
  49. ,scope: this
  50. }]
  51. });
  52. MODx.grid.DatabaseTables.superclass.constructor.call(this,config);
  53. };
  54. Ext.extend(MODx.grid.DatabaseTables,MODx.grid.Grid,{
  55. /**
  56. * Truncates the specified SQL table.
  57. * @param {String} table
  58. */
  59. truncate: function(table) {
  60. MODx.Ajax.request({
  61. url: this.config.url
  62. ,params: {
  63. action: 'system/databasetable/truncate'
  64. ,t: table
  65. }
  66. ,listeners: {
  67. 'success': {fn:this.refresh,scope:this}
  68. }
  69. });
  70. return false;
  71. }
  72. /**
  73. * Optimizes the specified SQL table.
  74. * @param {String} table
  75. */
  76. ,optimize: function(table) {
  77. MODx.Ajax.request({
  78. url: this.config.url
  79. ,params: {
  80. action: 'system/databasetable/optimize'
  81. ,t: table
  82. }
  83. ,listeners: {
  84. 'success': {fn:this.refresh,scope:this}
  85. }
  86. });
  87. return false;
  88. }
  89. ,optimizeDatabase: function(table) {
  90. MODx.Ajax.request({
  91. url: this.config.url
  92. ,params: {
  93. action: 'system/databasetable/optimizeDatabase'
  94. }
  95. ,listeners: {
  96. 'success': {fn:this.refresh,scope:this}
  97. }
  98. });
  99. return false;
  100. }
  101. });
  102. Ext.reg('modx-grid-databasetables',MODx.grid.DatabaseTables);
  103. var truncate = function(name) {
  104. Ext.getCmp('modx-grid-dbtable').truncate(name);
  105. };
  106. var optimize = function(name) {
  107. Ext.getCmp('modx-grid-dbtable').optimize(name);
  108. };