Translation update done using Pootle.
[phpmyadmin-themes.git] / js / tbl_structure.js
blob352848cb6530f5133ce20ed002f9cbea0455cea7
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    functions used on the table structure page
4  * @name            Table Structure
5  *
6  * @requires    jQuery
7  * @requires    jQueryUI
8  * @required    js/functions.js
9  */
11 /**
12  * AJAX scripts for tbl_structure.php
13  *
14  * Actions ajaxified here:
15  * Drop Column
16  * Add Primary Key
17  * Drop Primary Key/Index
18  *
19  */
20 $(document).ready(function() {
21     
22     /**
23      * Attach Event Handler for 'Drop Column'
24      *
25      * @uses    $.PMA_confirm()
26      * @uses    PMA_ajaxShowMessage()
27      * (see $GLOBALS['cfg']['AjaxEnable'])
28      */
29     $(".drop_column_anchor").live('click', function(event) {
30         event.preventDefault();
32         /**
33          * @var curr_table_name String containing the name of the current table
34          */
35         var curr_table_name = window.parent.table;
36         /**
37          * @var curr_row    Object reference to the currently selected row (i.e. field in the table)
38          */
39         var curr_row = $(this).parents('tr');
40         /**
41          * @var curr_column_name    String containing name of the field referred to by {@link curr_row}
42          */
43         var curr_column_name = $(curr_row).children('th').children('label').text();
44         /**
45          * @var question    String containing the question to be asked for confirmation
46          */
47         var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` DROP `' + curr_column_name + '`';
49         $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
51             PMA_ajaxShowMessage(PMA_messages['strDroppingColumn']);
53             $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
54                 if(data.success == true) {
55                     PMA_ajaxShowMessage(data.message);
56                     $(curr_row).hide("medium").remove();
57                 }
58                 else {
59                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
60                 }
61             }) // end $.get()
62         }); // end $.PMA_confirm()
63     }) ; //end of Drop Column Anchor action
65     /**
66      * Ajax Event handler for 'Add Primary Key'
67      *
68      * @uses    $.PMA_confirm()
69      * @uses    PMA_ajaxShowMessage()
70      * (see $GLOBALS['cfg']['AjaxEnable'])
71      */
72     $(".action_primary a").live('click', function(event) {
73         event.preventDefault();
75         /**
76          * @var curr_table_name String containing the name of the current table
77          */
78         var curr_table_name = window.parent.table;
79         /**
80          * @var curr_column_name    String containing name of the field referred to by {@link curr_row}
81          */
82         var curr_column_name = $(this).parents('tr').children('th').children('label').text();
83         /**
84          * @var question    String containing the question to be asked for confirmation
85          */
86         var question = PMA_messages['strDoYouReally'] + ' :\n ALTER TABLE `' + curr_table_name + '` ADD PRIMARY KEY(`' + curr_column_name + '`)';
88         $(this).PMA_confirm(question, $(this).attr('href'), function(url) {
90             PMA_ajaxShowMessage(PMA_messages['strAddingPrimaryKey']);
92             $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
93                 if(data.success == true) {
94                     PMA_ajaxShowMessage(data.message);
95                     $(this).remove();
96                     if (typeof data.reload != 'undefined') {
97                         window.parent.frame_content.location.reload();
98                     }
99                 }
100                 else {
101                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
102                 }
103             }) // end $.get()
104         }) // end $.PMA_confirm()
105     })//end Add Primary Key
107     /**
108      * Ajax Event handler for 'Drop Primary Key/Index'
109      *
110      * @uses    $.PMA_confirm()
111      * @uses    PMA_ajaxShowMessage()
112      * (see $GLOBALS['cfg']['AjaxEnable'])
113      */
114     $('.drop_primary_key_index_anchor').live('click', function(event) {
115         event.preventDefault();
117         $anchor = $(this);
119         /**
120          * @var $curr_row    Object containing reference to the current field's row
121          */
122         var $curr_row = $anchor.parents('tr');
123         /** @var    Number of columns in the key */
124         var rows = $anchor.parents('td').attr('rowspan') || 1;
125         /** @var    Rows that should be hidden */
126         var $rows_to_hide = $curr_row;
127         for (var i = 1, $last_row = $curr_row.next(); i < rows; i++, $last_row = $last_row.next()) {
128             $rows_to_hide = $rows_to_hide.add($last_row);
129         }
131         var question = $curr_row.children('td').children('.drop_primary_key_index_msg').val();
133         $anchor.PMA_confirm(question, $anchor.attr('href'), function(url) {
135             PMA_ajaxShowMessage(PMA_messages['strDroppingPrimaryKeyIndex']);
137             $.get(url, {'is_js_confirmed': 1, 'ajax_request': true}, function(data) {
138                 if(data.success == true) {
139                     PMA_ajaxShowMessage(data.message);
140                     $rows_to_hide.hide("medium").remove();
141                 }
142                 else {
143                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error);
144                 }
145             }) // end $.get()
146         }) // end $.PMA_confirm()
147     }) //end Drop Primary Key/Index
148     
149 }) // end $(document).ready()