server_databases.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * @fileoverview functions used on the server databases list page
  4. * @name Server Databases
  5. *
  6. * @requires jQuery
  7. * @requires jQueryUI
  8. * @required js/functions.js
  9. */
  10. /**
  11. * Unbind all event handlers before tearing down a page
  12. */
  13. AJAX.registerTeardown('server_databases.js', function () {
  14. $("#dbStatsForm").die('submit');
  15. $('#create_database_form.ajax').die('submit');
  16. });
  17. /**
  18. * AJAX scripts for server_databases.php
  19. *
  20. * Actions ajaxified here:
  21. * Drop Databases
  22. *
  23. */
  24. AJAX.registerOnload('server_databases.js', function () {
  25. /**
  26. * Attach Event Handler for 'Drop Databases'
  27. */
  28. $("#dbStatsForm").live('submit', function (event) {
  29. event.preventDefault();
  30. var $form = $(this);
  31. /**
  32. * @var selected_dbs Array containing the names of the checked databases
  33. */
  34. var selected_dbs = [];
  35. // loop over all checked checkboxes, except the .checkall_box checkbox
  36. $form.find('input:checkbox:checked:not(.checkall_box)').each(function () {
  37. $(this).closest('tr').addClass('removeMe');
  38. selected_dbs[selected_dbs.length] = 'DROP DATABASE `' + escapeHtml($(this).val()) + '`;';
  39. });
  40. if (! selected_dbs.length) {
  41. PMA_ajaxShowMessage(
  42. $('<div class="notice" />').text(
  43. PMA_messages.strNoDatabasesSelected
  44. ),
  45. 2000
  46. );
  47. return;
  48. }
  49. /**
  50. * @var question String containing the question to be asked for confirmation
  51. */
  52. var question = PMA_messages.strDropDatabaseStrongWarning + ' ' +
  53. $.sprintf(PMA_messages.strDoYouReally, selected_dbs.join('<br />'));
  54. $(this).PMA_confirm(
  55. question,
  56. $form.prop('action') + '?' + $(this).serialize() +
  57. '&drop_selected_dbs=1&is_js_confirmed=1&ajax_request=true',
  58. function (url) {
  59. PMA_ajaxShowMessage(PMA_messages.strProcessingRequest, false);
  60. $.post(url, function (data) {
  61. if (data.success === true) {
  62. PMA_ajaxShowMessage(data.message);
  63. var $rowsToRemove = $form.find('tr.removeMe');
  64. var $databasesCount = $('#databases_count');
  65. var newCount = parseInt($databasesCount.text(), 10) - $rowsToRemove.length;
  66. $databasesCount.text(newCount);
  67. $rowsToRemove.remove();
  68. $form.find('tbody').PMA_sort_table('.name');
  69. if ($form.find('tbody').find('tr').length == 0) {
  70. // user just dropped the last db on this page
  71. PMA_commonActions.refreshMain();
  72. }
  73. PMA_reloadNavigation();
  74. } else {
  75. $form.find('tr.removeMe').removeClass('removeMe');
  76. PMA_ajaxShowMessage(data.error, false);
  77. }
  78. }); // end $.post()
  79. }
  80. ); // end $.PMA_confirm()
  81. }); //end of Drop Database action
  82. /**
  83. * Attach Ajax event handlers for 'Create Database'.
  84. */
  85. $('#create_database_form.ajax').live('submit', function (event) {
  86. event.preventDefault();
  87. var $form = $(this);
  88. // TODO Remove this section when all browsers support HTML5 "required" property
  89. var newDbNameInput = $form.find('input[name=new_db]');
  90. if (newDbNameInput.val() === '') {
  91. newDbNameInput.focus();
  92. alert(PMA_messages.strFormEmpty);
  93. return;
  94. }
  95. // end remove
  96. PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
  97. PMA_prepareForAjaxRequest($form);
  98. $.post($form.attr('action'), $form.serialize(), function (data) {
  99. if (data.success === true) {
  100. PMA_ajaxShowMessage(data.message);
  101. //Append database's row to table
  102. $("#tabledatabases")
  103. .find('tbody')
  104. .append(data.new_db_string)
  105. .PMA_sort_table('.name');
  106. var $databases_count_object = $('#databases_count');
  107. var databases_count = parseInt($databases_count_object.text(), 10) + 1;
  108. $databases_count_object.text(databases_count);
  109. PMA_reloadNavigation();
  110. } else {
  111. PMA_ajaxShowMessage(data.error, false);
  112. }
  113. }); // end $.post()
  114. }); // end $().live()
  115. }); // end $()