modx.grid.databasetables.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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','Data_size','Data_free','Effective_size','Index_length','Total_size']
  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_datasize')
  30. ,dataIndex: 'Data_size'
  31. ,width: 70
  32. },{
  33. header: _('database_table_overhead')
  34. ,dataIndex: 'Data_free'
  35. ,width: 70
  36. },{
  37. header: _('database_table_effectivesize')
  38. ,dataIndex: 'Effective_size'
  39. ,width: 70
  40. },{
  41. header: _('database_table_indexsize')
  42. ,dataIndex: 'Index_length'
  43. ,width: 70
  44. },{
  45. header: _('database_table_totalsize')
  46. ,dataIndex: 'Total_size'
  47. ,width: 70
  48. }]
  49. ,tbar: [{
  50. text: _('database_optimize')
  51. ,cls:'primary-button'
  52. ,handler: this.optimizeDatabase
  53. ,scope: this
  54. }]
  55. });
  56. MODx.grid.DatabaseTables.superclass.constructor.call(this,config);
  57. };
  58. Ext.extend(MODx.grid.DatabaseTables,MODx.grid.Grid,{
  59. /**
  60. * Truncates the specified SQL table.
  61. * @param {String} table
  62. */
  63. truncate: function(table) {
  64. MODx.Ajax.request({
  65. url: this.config.url
  66. ,params: {
  67. action: 'system/databasetable/truncate'
  68. ,t: table
  69. }
  70. ,listeners: {
  71. 'success': {fn:this.refresh,scope:this}
  72. }
  73. });
  74. return false;
  75. }
  76. /**
  77. * Optimizes the specified SQL table.
  78. * @param {String} table
  79. */
  80. ,optimize: function(table) {
  81. MODx.Ajax.request({
  82. url: this.config.url
  83. ,params: {
  84. action: 'system/databasetable/optimize'
  85. ,t: table
  86. }
  87. ,listeners: {
  88. 'success': {fn:this.refresh,scope:this}
  89. }
  90. });
  91. return false;
  92. }
  93. ,optimizeDatabase: function(table) {
  94. MODx.Ajax.request({
  95. url: this.config.url
  96. ,params: {
  97. action: 'system/databasetable/optimizeDatabase'
  98. }
  99. ,listeners: {
  100. 'success': {fn:this.refresh,scope:this}
  101. }
  102. });
  103. return false;
  104. }
  105. });
  106. Ext.reg('modx-grid-databasetables',MODx.grid.DatabaseTables);
  107. var truncate = function(name) {
  108. Ext.getCmp('modx-grid-dbtable').truncate(name);
  109. };
  110. var optimize = function(name) {
  111. Ext.getCmp('modx-grid-dbtable').optimize(name);
  112. };