1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview function used in server privilege pages
4 * @name Database Operations
8 * @requires js/functions.js
13 * Ajax event handlers here for db_operations.php
15 * Actions Ajaxified here:
23 * Unbind all event handlers before tearing down a page
25 AJAX.registerTeardown('db_operations.js', function () {
26 $(document).off('submit', "#rename_db_form.ajax");
27 $(document).off('submit', "#copy_db_form.ajax");
28 $(document).off('submit', "#change_db_charset_form.ajax");
29 $(document).off('click', "#drop_db_anchor.ajax");
32 AJAX.registerOnload('db_operations.js', function () {
35 * Ajax event handlers for 'Rename Database'
37 $(document).on('submit', "#rename_db_form.ajax", function (event) {
38 event.preventDefault();
40 var old_db_name = PMA_commonParams.get('db');
41 var new_db_name = $('#new_db_name').val();
43 if (new_db_name == old_db_name) {
44 PMA_ajaxShowMessage(PMA_messages.strDropDatabaseStrongWarning);
50 var question = escapeHtml('CREATE DATABASE ' + new_db_name + ' / DROP DATABASE ' + old_db_name);
52 PMA_prepareForAjaxRequest($form);
54 $form.PMA_confirm(question, $form.attr('action'), function (url) {
55 PMA_ajaxShowMessage(PMA_messages.strRenamingDatabases, false);
56 $.get(url, $("#rename_db_form").serialize() + '&is_js_confirmed=1', function (data) {
57 if (typeof data !== 'undefined' && data.success === true) {
58 PMA_ajaxShowMessage(data.message);
59 PMA_commonParams.set('db', data.newname);
61 PMA_reloadNavigation(function () {
62 $('#pma_navigation_tree')
63 .find("a:not('.expander')")
64 .each(function (index) {
65 var $thisAnchor = $(this);
66 if ($thisAnchor.text() == data.newname) {
67 // simulate a click on the new db name
69 $thisAnchor.trigger('click');
74 PMA_ajaxShowMessage(data.error, false);
78 }); // end Rename Database
81 * Ajax Event Handler for 'Copy Database'
83 $(document).on('submit', "#copy_db_form.ajax", function (event) {
84 event.preventDefault();
85 PMA_ajaxShowMessage(PMA_messages.strCopyingDatabase, false);
87 PMA_prepareForAjaxRequest($form);
88 $.get($form.attr('action'), $form.serialize(), function (data) {
89 // use messages that stay on screen
90 $('div.success, div.error').fadeOut();
91 if (typeof data !== 'undefined' && data.success === true) {
92 if ($("#checkbox_switch").is(":checked")) {
93 PMA_commonParams.set('db', data.newname);
94 PMA_commonActions.refreshMain(false, function () {
95 PMA_ajaxShowMessage(data.message);
98 PMA_commonParams.set('db', data.db);
99 PMA_ajaxShowMessage(data.message);
101 PMA_reloadNavigation();
103 PMA_ajaxShowMessage(data.error, false);
106 }); // end copy database
109 * Ajax Event handler for 'Change Charset' of the database
111 $(document).on('submit', "#change_db_charset_form.ajax", function (event) {
112 event.preventDefault();
114 PMA_prepareForAjaxRequest($form);
115 PMA_ajaxShowMessage(PMA_messages.strChangingCharset);
116 $.get($form.attr('action'), $form.serialize() + "&submitcollation=1", function (data) {
117 if (typeof data !== 'undefined' && data.success === true) {
118 PMA_ajaxShowMessage(data.message);
120 PMA_ajaxShowMessage(data.error, false);
123 }); // end change charset
126 * Ajax event handlers for Drop Database
128 $(document).on('click', "#drop_db_anchor.ajax", function (event) {
129 event.preventDefault();
131 * @var question String containing the question to be asked for confirmation
133 var question = PMA_messages.strDropDatabaseStrongWarning + ' ';
134 question += PMA_sprintf(
135 PMA_messages.strDoYouReally,
136 'DROP DATABASE ' + escapeHtml(PMA_commonParams.get('db'))
138 $(this).PMA_confirm(question, $(this).attr('href'), function (url) {
139 PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
140 $.get(url, {'is_js_confirmed': '1', 'ajax_request': true}, function (data) {
141 if (typeof data !== 'undefined' && data.success) {
142 //Database deleted successfully, refresh both the frames
143 PMA_reloadNavigation();
144 PMA_commonParams.set('db', '');
145 PMA_commonActions.refreshMain(
146 'server_databases.php',
148 PMA_ajaxShowMessage(data.message);
152 PMA_ajaxShowMessage(data.error, false);