Translation update done using Pootle.
[phpmyadmin.git] / js / db_operations.js
blobb0536942c9135f73fc2a8395c22695d1872cba7a
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         PMA_prepareForAjaxRequest($form);
38         /**
39          * @var button_options  Object containing options for jQueryUI dialog buttons
40          */
41         var button_options = {};
42         button_options[PMA_messages['strYes']] = function() {
43                                                     $(this).dialog("close").remove();
44                                                     window.parent.refreshMain();
45                                                     window.parent.refreshNavigation();
46                                                 };
47         button_options[PMA_messages['strNo']] = function() { $(this).dialog("close").remove(); }
49         $form.PMA_confirm(question, $form.attr('action'), function(url) {
50             PMA_ajaxShowMessage(PMA_messages['strRenamingDatabases']);
52             $.get(url, $("#rename_db_form").serialize() + '&is_js_confirmed=1', function(data) {
53                 if(data.success == true) {
54                     
55                     PMA_ajaxShowMessage(data.message);
57                     window.parent.db = data.newname;
59                     $("#topmenucontainer")
60                     .next('div')
61                     .remove()
62                     .end()
63                     .after(data.sql_query);
65                     //Remove the empty notice div generated due to a NULL query passed to PMA_showMessage()
66                     var $notice_class = $("#topmenucontainer").next("div").find('.notice');
67                     if ($notice_class.text() == '') {
68                         $notice_class.remove();
69                     }
71                     $("<span>" + PMA_messages['strReloadDatabase'] + "?</span>").dialog({
72                         buttons: button_options
73                     }) //end dialog options
74                 }
75                 else {
76                     PMA_ajaxShowMessage(data.error);
77                 }
78             }) // end $.get()
79         })
80     }); // end Rename Database
82     /**
83      * Ajax Event Handler for 'Copy Database'
84      *
85      * @uses    PMA_ajaxShowMessage()
86      * @see     $cfg['AjaxEnable']
87      */
88     $("#copy_db_form.ajax").live('submit', function(event) {
89         event.preventDefault();
91         var $msgbox = PMA_ajaxShowMessage(PMA_messages['strCopyingDatabase']);
93         var $form = $(this);
94         
95         PMA_prepareForAjaxRequest($form);
97         $.get($form.attr('action'), $form.serialize(), function(data) {
98             // use messages that stay on screen
99             $('.success').fadeOut();
100             $('.error').fadeOut();
101             if(data.success == true) {
102                 $('#topmenucontainer').after(data.message);
103                 if( $("#checkbox_switch").is(":checked")) {
104                     window.parent.db = data.newname;
105                     window.parent.refreshMain();
106                     window.parent.refreshNavigation();
107                } else {
108                     // Here we force a refresh because the navigation
109                     // frame url is not changing so this function would
110                     // not refresh it
111                     window.parent.refreshNavigation(true);
112                }
113             }
114             else {
115                 $('#topmenucontainer').after(data.error);
116             }
117             
118             PMA_ajaxRemoveMessage($msgbox);
119         }) // end $.get
120     }) // end copy database
122     /**
123      * Ajax Event handler for 'Change Charset' of the database
124      *
125      * @uses    PMA_ajaxShowMessage()
126      * @see     $cfg['AjaxEnable']
127      */
128     $("#change_db_charset_form.ajax").live('submit', function(event) {
129         event.preventDefault();
131         var $form = $(this);
133         PMA_prepareForAjaxRequest($form);
135         PMA_ajaxShowMessage(PMA_messages['strChangingCharset']);
137         $.get($form.attr('action'), $form.serialize() + "&submitcollation=" + $form.find("input[name=submitcollation]").attr('value'), function(data) {
138             if(data.success == true) {
139                 PMA_ajaxShowMessage(data.message);
140             }
141             else {
142                 PMA_ajaxShowMessage(data.error);
143             }
144         }) // end $.get()
145     }) // end change charset
146     
147 }, 'top.frame_content');