Translation update done using Pootle.
[phpmyadmin-themes.git] / js / db_operations.js
blob915c5376670c53790bff393c2cde618349f907a9
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    function used in server privilege pages
4  * @name            Database Operations
5  *
6  * @requires    jQuery
7  * @requires    jQueryUI
8  * @requires    js/functions.js
9  *
10  */
12 /**
13  * Ajax event handlers here for db_operations.php
14  *
15  * Actions Ajaxified here:
16  * Rename Database
17  * Copy Database
18  * Change charset
19  */
21 $(document).ready(function() {
23     /**
24      * Ajax event handlers for 'Rename Database'
25      *
26      * @uses    $.PMA_confirm()
27      * @uses    PMA_ajaxShowUser()
28      * @see     $cfg['AjaxEnable']
29      */
30     $("#rename_db_form.ajax").live('submit', function(event) {
31         event.preventDefault();
33         var $form = $(this);
35         var question = 'CREATE DATABASE ' + $('#new_db_name').val() + ' / DROP DATABASE ' + window.parent.db;
37         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
38             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
39         }
41         /**
42          * @var button_options  Object containing options for jQueryUI dialog buttons
43          */
44         var button_options = {};
45         button_options[PMA_messages['strYes']] = function() {
46                                                     $(this).dialog("close").remove();
47                                                     window.parent.refreshMain();
48                                                     window.parent.refreshNavigation();
49                                                 };
50         button_options[PMA_messages['strNo']] = function() { $(this).dialog("close").remove(); }
52         $form.PMA_confirm(question, $form.attr('action'), function(url) {
53             PMA_ajaxShowMessage(PMA_messages['strRenamingDatabases']);
55             $.get(url, $("#rename_db_form").serialize() + '&is_js_confirmed=1', function(data) {
56                 if(data.success == true) {
57                     
58                     PMA_ajaxShowMessage(data.message);
60                     window.parent.db = data.newname;
62                     $("#topmenucontainer")
63                     .next('div')
64                     .remove()
65                     .end()
66                     .after(data.sql_query);
68                     //Remove the empty notice div generated due to a NULL query passed to PMA_showMessage()
69                     var $notice_class = $("#topmenucontainer").next("div").find('.notice');
70                     if ($notice_class.text() == '') {
71                         $notice_class.remove();
72                     }
74                     $("<span>" + PMA_messages['strReloadDatabase'] + "?</span>").dialog({
75                         buttons: button_options
76                     }) //end dialog options
77                 }
78                 else {
79                     PMA_ajaxShowMessage(data.error);
80                 }
81             }) // end $.get()
82         })
83     }); // end Rename Database
85     /**
86      * Ajax Event Handler for 'Copy Database'
87      *
88      * @uses    PMA_ajaxShowMessage()
89      * @see     $cfg['AjaxEnable']
90      */
91     $("#copy_db_form.ajax").live('submit', function(event) {
92         event.preventDefault();
94         PMA_ajaxShowMessage(PMA_messages['strCopyingDatabase']);
96         var $form = $(this);
97         
98         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
99             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
100         }
102         $.get($form.attr('action'), $form.serialize(), function(data) {
103             // use messages that stay on screen
104             $('.success').fadeOut();
105             $('.error').fadeOut();
106             if(data.success == true) {
107                 $('#topmenucontainer').after(data.message);
108                 if( $("#checkbox_switch").is(":checked")) {
109                     window.parent.db = data.newname;
110                     window.parent.refreshMain();
111                     window.parent.refreshNavigation();
112                } else {
113                     // Here we force a refresh because the navigation
114                     // frame url is not changing so this function would
115                     // not refresh it
116                     window.parent.refreshNavigation(true);
117                }
118             }
119             else {
120                 $('#topmenucontainer').after(data.error);
121             }
122         }) // end $.get
123     }) // end copy database
125     /**
126      * Ajax Event handler for 'Change Charset' of the database
127      *
128      * @uses    PMA_ajaxShowMessage()
129      * @see     $cfg['AjaxEnable']
130      */
131     $("#change_db_charset_form.ajax").live('submit', function(event) {
132         event.preventDefault();
134         var $form = $(this);
136         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
137             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
138         }
140         PMA_ajaxShowMessage(PMA_messages['strChangingCharset']);
142         $.get($form.attr('action'), $form.serialize() + "&submitcollation=" + $form.find("input[name=submitcollation]").attr('value'), function(data) {
143             if(data.success == true) {
144                 PMA_ajaxShowMessage(data.message);
145             }
146             else {
147                 PMA_ajaxShowMessage(data.error);
148             }
149         }) // end $.get()
150     }) // end change charset
151     
152 }, 'top.frame_content');