Tab and white space clean up.
[phpmyadmin-themes.git] / js / sql.js
blob80d24ff1a57233ba5a0a73c7fc1480e1179d37e6
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    functions used wherever an sql query form is used
4  *
5  * @requires    jQuery
6  * @requires    js/functions.js
7  *
8  */
10 /**
11  * decode a string URL_encoded
12  *
13  * @param string str
14  * @return string the URL-decoded string
15  */
16 function PMA_urldecode(str) {
17     return decodeURIComponent(str.replace(/\+/g, '%20'));
20 /**
21  * Get the field name for the current field.  Required to construct the query
22  * for inline editing
23  *
24  * @param   $this_field  jQuery object that points to the current field's tr
25  * @param   disp_mode    string
26  */
27 function getFieldName($this_field, disp_mode) {
29     if(disp_mode == 'vertical') {
30         var field_name = $this_field.siblings('th').find('a').text();
31         // happens when just one row (headings contain no a)
32         if ("" == field_name) {
33             field_name = $this_field.siblings('th').text();
34         }
35     }
36     else {
37         var this_field_index = $this_field.index();
38         // ltr or rtl direction does not impact how the DOM was generated
39         //
40         // 5 columns to account for the checkbox, edit, appended inline edit, copy and delete anchors but index is zero-based so substract 4
41         var field_name = $('#table_results').find('thead').find('th:nth('+ (this_field_index-4 )+') a').text();
42         // happens when just one row (headings contain no a)
43         if ("" == field_name) {
44             field_name = $('#table_results').find('thead').find('th:nth('+ (this_field_index-4 )+')').text();
45         }
46     }
48     field_name = $.trim(field_name);
50     return field_name;
53 /**
54  * The function that iterates over each row in the table_results and appends a
55  * new inline edit anchor to each table row.
56  *
57  */
58 function appendInlineAnchor() {
59     var disp_mode = $("#top_direction_dropdown").val();
61     if (disp_mode == 'vertical') {
62         // there can be one or two tr containing this class, depending
63         // on the ModifyDeleteAtLeft and ModifyDeleteAtRight cfg parameters
64         $('#table_results tr')
65             .find('.edit_row_anchor')
66             .removeClass('.edit_row_anchor')
67             .parent().each(function() {
68             var $this_tr = $(this);
69             var $cloned_tr = $this_tr.clone();
71             var $img_object = $cloned_tr.find('img:first').attr('title', PMA_messages['strInlineEdit']);
72             var img_src = $img_object.attr('src').replace(/b_edit/,'b_inline_edit');
73             $img_object.attr('src', img_src);
75             $cloned_tr.find('td')
76              .addClass('inline_edit_anchor')
77              .find('a').attr('href', '#')
78              .find('span')
79              .text(' ' + PMA_messages['strInlineEdit'])
80              .prepend($img_object);
82             $cloned_tr.insertAfter($this_tr);
83         });
85         $('#rowsDeleteForm').find('tbody').find('th').each(function() {
86             var $this_th = $(this);
87             if ($this_th.attr('rowspan') == 4) {
88                 $this_th.attr('rowspan', '5');
89             }
90         });
91     }
92     else {
93         $('.edit_row_anchor').each(function() {
95             $this_td = $(this)
96             $this_td.removeClass('edit_row_anchor');
98             var $cloned_anchor = $this_td.clone();
100             var $img_object = $cloned_anchor.find('img').attr('title', PMA_messages['strInlineEdit']);
101             var img_src = $img_object.attr('src').replace(/b_edit/,'b_inline_edit');
102             $img_object.attr('src', img_src);
104             $cloned_anchor.addClass('inline_edit_anchor')
105             .find('a').attr('href', '#')
106             .find('span')
107             .text(' ' + PMA_messages['strInlineEdit'])
108             .prepend($img_object);
110             $this_td.after($cloned_anchor);
111         });
113         $('#rowsDeleteForm').find('thead, tbody').find('th').each(function() {
114             var $this_th = $(this);
115             if ($this_th.attr('colspan') == 4) {
116                 $this_th.attr('colspan', '5');
117             }
118         });
119     }
122 /**#@+
123  * @namespace   jQuery
124  */
127  * @description <p>Ajax scripts for sql and browse pages</p>
129  * Actions ajaxified here:
130  * <ul>
131  * <li>Retrieve results of an SQL query</li>
132  * <li>Paginate the results table</li>
133  * <li>Sort the results table</li>
134  * <li>Change table according to display options</li>
135  * <li>Inline editing of data</li>
136  * </ul>
138  * @name        document.ready
139  * @memberOf    jQuery
140  */
141 $(document).ready(function() {
143     /**
144      * Set a parameter for all Ajax queries made on this page.  Don't let the
145      * web server serve cached pages
146      */
147     $.ajaxSetup({
148         cache: 'false'
149     });
151     /**
152      * current value of the direction in which the table is displayed
153      * @type    String
154      * @fieldOf jQuery
155      * @name    disp_mode
156      */
157     var disp_mode = $("#top_direction_dropdown").val();
159     /**
160      * Update value of {@link jQuery.disp_mode} everytime the direction dropdown changes value
161      * @memberOf    jQuery
162      * @name        direction_dropdown_change
163      */
164     $("#top_direction_dropdown, #bottom_direction_dropdown").live('change', function(event) {
165         disp_mode = $(this).val();
166     })
168     /**
169      * Attach the {@link appendInlineAnchor} function to a custom event, which
170      * will be triggered manually everytime the table of results is reloaded
171      * @memberOf    jQuery
172      */
173     $("#sqlqueryresults").live('appendAnchor',function() {
174         appendInlineAnchor();
175     })
177     /**
178      * Trigger the appendAnchor event to prepare the first table for inline edit
179      * (see $GLOBALS['cfg']['AjaxEnable'])
180      * @memberOf    jQuery
181      * @name        sqlqueryresults_trigger
182      */
183     $("#sqlqueryresults.ajax").trigger('appendAnchor');
185     /**
186      * Append the "Show/Hide query box" message to the query input form
187      *
188      * @memberOf jQuery
189      * @name    appendToggleSpan
190      */
191     // do not add this link more than once
192     if (! $('#sqlqueryform').find('a').is('#togglequerybox')) {
193         $('<a id="togglequerybox"></a>')
194         .html(PMA_messages['strHideQueryBox'])
195         .appendTo("#sqlqueryform");
197         // Attach the toggling of the query box visibility to a click
198         $("#togglequerybox").bind('click', function() {
199             var $link = $(this)
200             $link.siblings().slideToggle("medium");
201             if ($link.text() == PMA_messages['strHideQueryBox']) {
202                 $link.text(PMA_messages['strShowQueryBox']);
203             } else {
204                 $link.text(PMA_messages['strHideQueryBox']);
205             }
206             // avoid default click action
207             return false;
208         })
209     }
211     /**
212      * Ajax Event handler for 'SQL Query Submit'
213      *
214      * @see         PMA_ajaxShowMessage()
215      * @see         $cfg['AjaxEnable']
216      * @memberOf    jQuery
217      * @name        sqlqueryform_submit
218      */
219     $("#sqlqueryform.ajax").live('submit', function(event) {
220         event.preventDefault();
221         // remove any div containing a previous error message
222         $('.error').remove();
224         $form = $(this);
225         PMA_ajaxShowMessage();
227         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
228             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
229         }
231         $.post($(this).attr('action'), $(this).serialize() , function(data) {
232             if(data.success == true) {
233                 // fade out previous messages, if any
234                 $('.success').fadeOut();
235                 $('.sqlquery_message').fadeOut();
236                 // show a message that stays on screen
237                 $('#sqlqueryform').before(data.message);
238                 // and display the query
239                 $('<div class="sqlquery_message"></div>')
240                  .html(data.sql_query)
241                  .insertBefore('#sqlqueryform');
242                 // unnecessary div that came from data.sql_query
243                 $('.notice').remove();
244                 $('#sqlqueryresults').show();
245                 // this happens if a USE command was typed
246                 if (typeof data.reload != 'undefined') {
247                     $form.find('input[name=db]').val(data.db);
248                     // need to regenerate the whole upper part
249                     $form.find('input[name=ajax_request]').remove();
250                     $form.append('<input type="hidden" name="reload" value="true" />');
251                     $.post('db_sql.php', $form.serialize(), function(data) {
252                         $('body').html(data);
253                     }); // end inner post
254                 }
255             }
256             else if (data.success == false ) {
257                 // show an error message that stays on screen
258                 $('#sqlqueryform').before(data.error);
259                 $('#sqlqueryresults').hide();
260             }
261             else {
262                 // real results are returned
263                 $('#sqlqueryresults').show();
264                 $("#sqlqueryresults").html(data);
265                 $("#sqlqueryresults").trigger('appendAnchor');
266                 if($("#togglequerybox").siblings(":visible").length > 0) {
267                     $("#togglequerybox").trigger('click');
268                 }
269                 PMA_init_slider();
270             }
271         }) // end $.post()
272     }) // end SQL Query submit
274     /**
275      * Ajax Event handlers for Paginating the results table
276      */
278     /**
279      * Paginate when we click any of the navigation buttons
280      * (only if the element has the ajax class, see $cfg['AjaxEnable'])
281      * @memberOf    jQuery
282      * @name        paginate_nav_button_click
283      * @uses        PMA_ajaxShowMessage()
284      * @see         $cfg['AjaxEnable']
285      */
286     $("input[name=navig].ajax").live('click', function(event) {
287         /** @lends jQuery */
288         event.preventDefault();
290         PMA_ajaxShowMessage();
292         /**
293          * @var $the_form    Object referring to the form element that paginates the results table
294          */
295         var $the_form = $(this).parent("form");
297         $the_form.append('<input type="hidden" name="ajax_request" value="true" />');
299         $.post($the_form.attr('action'), $the_form.serialize(), function(data) {
300             $("#sqlqueryresults").html(data);
301             $("#sqlqueryresults").trigger('appendAnchor');
302             PMA_init_slider();
303         }) // end $.post()
304     })// end Paginate results table
306     /**
307      * Paginate results with Page Selector dropdown
308      * @memberOf    jQuery
309      * @name        paginate_dropdown_change
310      * @see         $cfg['AjaxEnable']
311      */
312     $("#pageselector").live('change', function(event) {
313         var $the_form = $(this).parent("form");
315         if ($(this).hasClass('ajax')) {
316             event.preventDefault();
318             PMA_ajaxShowMessage();
320             $.post($the_form.attr('action'), $the_form.serialize() + '&ajax_request=true', function(data) {
321                 $("#sqlqueryresults").html(data);
322                 $("#sqlqueryresults").trigger('appendAnchor');
323                 PMA_init_slider();
324             }) // end $.post()
325         } else {
326             $the_form.submit();
327         }
329     })// end Paginate results with Page Selector
331     /**
332      * Ajax Event handler for sorting the results table
333      * @memberOf    jQuery
334      * @name        table_results_sort_click
335      * @see         $cfg['AjaxEnable']
336      */
337     $("#table_results.ajax").find("a[title=Sort]").live('click', function(event) {
338         event.preventDefault();
340         PMA_ajaxShowMessage();
342         $anchor = $(this);
344         $.get($anchor.attr('href'), $anchor.serialize() + '&ajax_request=true', function(data) {
345             $("#sqlqueryresults")
346              .html(data)
347              .trigger('appendAnchor');
348         }) // end $.get()
349     })//end Sort results table
351     /**
352      * Ajax Event handler for the display options
353      * @memberOf    jQuery
354      * @name        displayOptionsForm_submit
355      * @see         $cfg['AjaxEnable']
356      */
357     $("#displayOptionsForm.ajax").live('submit', function(event) {
358         event.preventDefault();
360         $form = $(this);
362         $.post($form.attr('action'), $form.serialize() + '&ajax_request=true' , function(data) {
363             $("#sqlqueryresults")
364              .html(data)
365              .trigger('appendAnchor');
366             PMA_init_slider();
367         }) // end $.post()
368     })
369     //end displayOptionsForm handler
371     /**
372      * Ajax Event handlers for Inline Editing
373      */
375     /**
376      * On click, replace the fields of current row with an input/textarea
377      * @memberOf    jQuery
378      * @name        inline_edit_start
379      * @see         PMA_ajaxShowMessage()
380      * @see         getFieldName()
381      */
382     $(".inline_edit_anchor").live('click', function(event) {
383         /** @lends jQuery */
384         event.preventDefault();
386         $(this).removeClass('inline_edit_anchor').addClass('inline_edit_active');
388         // Initialize some variables
389         if(disp_mode == 'vertical') {
390             /**
391              * @var this_row_index  Index of the current <td> in the parent <tr>
392              *                      Current <td> is the inline edit anchor.
393              */
394             var this_row_index = $(this).index();
395             /**
396              * @var $input_siblings  Object referring to all inline editable events from same row
397              */
398             var $input_siblings = $(this).parents('tbody').find('tr').find('.inline_edit:nth('+this_row_index+')');
399             /**
400              * @var where_clause    String containing the WHERE clause to select this row
401              */
402             var where_clause = $(this).parents('tbody').find('tr').find('.where_clause:nth('+this_row_index+')').val();
403         }
404         else {
405             var $input_siblings = $(this).parent('tr').find('.inline_edit');
406             var where_clause = $(this).parent('tr').find('.where_clause').val();
407         }
409         $input_siblings.each(function() {
410             /** @lends jQuery */
411             /**
412              * @var data_value  Current value of this field
413              */
414             var data_value = $(this).html();
416             // We need to retrieve the value from the server for truncated/relation fields
417             // Find the field name
419             /**
420              * @var this_field  Object referring to this field (<td>)
421              */
422             var $this_field = $(this);
423             /**
424              * @var field_name  String containing the name of this field.
425              * @see getFieldName()
426              */
427             var field_name = getFieldName($this_field, disp_mode);
428             /**
429              * @var relation_curr_value String current value of the field (for fields that are foreign keyed).
430              */
431             var relation_curr_value = $this_field.find('a').text();
432             /**
433              * @var enum_curr_value String current value of the field (for fields that are of type enum).
434              */
435             var enum_curr_value = $this_field.text();
437             if($this_field.is(':not(.not_null)')){
438                 // add a checkbox to mark null for all the field that are nullable.
439                 $this_field.html('<div class="null_div">Null :<input type="checkbox" class="checkbox_null_'+ field_name +'"></div>');
440                 // check the 'checkbox_null_<field_name>' if the value is null
441                 if($this_field.is('.null')) {
442                     $('.checkbox_null_' + field_name).attr('checked', true);
443                 }
445                 // if 'chechbox_null_<field_name>' is clicked empty the select/editor.
446                 $('.checkbox_null_' + field_name).bind('click', function(e) {
447                     if ($this_field.is('.enum, .set')) {
448                         $this_field.find('select').selectedIndex = -1;
449                     } else if ($this_field.is('.relation')) {
450                         $this_field.find('select').attr('value', '');
451                     } else {
452                         $this_field.find('textarea').empty();
453                     }
454                 })
456             } else {
457                 $this_field.html('<div class="null_div"></div>');
458             }
460             // In each input sibling, wrap the current value in a textarea
461             // and store the current value in a hidden span
462             if($this_field.is(':not(.truncated, .transformed, .relation, .enum, .null)')) {
463                 // handle non-truncated, non-transformed, non-relation values
464                 // We don't need to get any more data, just wrap the value
465                 $this_field.append('<textarea>'+data_value+'</textarea>');
466                 $this_field.append('<span class="original_data">'+data_value+'</span>');
467                 $(".original_data").hide();
468             }
469             else if($this_field.is('.truncated, .transformed')) {
470                 /** @lends jQuery */
471                 //handle truncated/transformed values values
473                 /**
474                  * @var sql_query   String containing the SQL query used to retrieve value of truncated/transformed data
475                  */
476                 var sql_query = 'SELECT ' + field_name + ' FROM ' + window.parent.table + ' WHERE ' + where_clause;
478                 // Make the Ajax call and get the data, wrap it and insert it
479                 $.post('sql.php', {
480                     'token' : window.parent.token,
481                     'db' : window.parent.db,
482                     'ajax_request' : true,
483                     'sql_query' : sql_query,
484                     'inline_edit' : true
485                 }, function(data) {
486                     if(data.success == true) {
487                         $this_field.append('<textarea>'+data.value+'</textarea>');
488                         $this_field.append('<span class="original_data">'+data_value+'</span>');
489                         $(".original_data").hide();
490                     }
491                     else {
492                         PMA_ajaxShowMessage(data.error);
493                     }
494                 }) // end $.post()
495             }
496             else if($this_field.is('.relation')) {
497                 /** @lends jQuery */
498                 //handle relations
500                 /**
501                  * @var post_params Object containing parameters for the POST request
502                  */
503                 var post_params = {
504                         'ajax_request' : true,
505                         'get_relational_values' : true,
506                         'db' : window.parent.db,
507                         'table' : window.parent.table,
508                         'column' : field_name,
509                         'token' : window.parent.token,
510                         'curr_value' : relation_curr_value
511                 }
513                 $.post('sql.php', post_params, function(data) {
514                     $this_field.append(data.dropdown);
515                     $this_field.append('<span class="original_data">'+data_value+'</span>');
516                     $(".original_data").hide();
517                 }) // end $.post()
518             }
519             else if($this_field.is('.enum')) {
520                 /** @lends jQuery */
521                 //handle enum fields
523                 /**
524                  * @var post_params Object containing parameters for the POST request
525                  */
526                 var post_params = {
527                         'ajax_request' : true,
528                         'get_enum_values' : true,
529                         'db' : window.parent.db,
530                         'table' : window.parent.table,
531                         'column' : field_name,
532                         'token' : window.parent.token,
533                         'curr_value' : enum_curr_value
534                 }
536                 $.post('sql.php', post_params, function(data) {
537                     $this_field.append(data.dropdown);
538                     $this_field.append('<span class="original_data">'+data_value+'</span>');
539                     $(".original_data").hide();
540                 }) // end $.post()
541             }
542             else if($this_field.is('.null')) {
543                 //handle null fields
544                 $this_field.append('<textarea></textarea>');
545                 $this_field.append('<span class="original_data">NULL</span>');
546                 $(".original_data").hide();
547             }
548         })
549     }) // End On click, replace the current field with an input/textarea
551     /**
552      * After editing, clicking again should post data
553      *
554      * @memberOf    jQuery
555      * @name        inline_edit_save
556      * @see         PMA_ajaxShowMessage()
557      * @see         getFieldName()
558      */
559     $(".inline_edit_active").live('click', function(event) {
560         /** @lends jQuery */
561         event.preventDefault();
563         /**
564          * @var $this_td    Object referring to the td containing the
565          * "Inline Edit" link that was clicked to save the row that is
566          * being edited
567          *
568          */
569         var $this_td = $(this);
571         var $test_element = ''; // to test the presence of a element
573         // Initialize variables
574         if(disp_mode == 'vertical') {
575             /**
576              * @var this_td_index  Index of the current <td> in the parent <tr>
577              *                      Current <td> is the inline edit anchor.
578              */
579             var this_td_index = $this_td.index();
580             /**
581              * @var $input_siblings  Object referring to all inline editable events from same row
582              */
583             var $input_siblings = $this_td.parents('tbody').find('tr').find('.inline_edit:nth('+this_td_index+')');
584             /**
585              * @var where_clause    String containing the WHERE clause to select this row
586              */
587             var where_clause = $this_td.parents('tbody').find('tr').find('.where_clause:nth('+this_td_index+')').val();
588         }
589         else {
590             var $input_siblings = $this_td.parent('tr').find('.inline_edit');
591             var where_clause = $this_td.parent('tr').find('.where_clause').val();
592         }
594         /**
595          * @var nonunique   Boolean, whether this row is unique or not
596          */
597         if($this_td.is('.nonunique')) {
598             var nonunique = 0;
599         }
600         else {
601             var nonunique = 1;
602         }
604         // Collect values of all fields to submit, we don't know which changed
605         /**
606          * @var relation_fields Array containing the name/value pairs of relational fields
607          */
608         var relation_fields = {};
609         /**
610          * @var transform_fields    Array containing the name/value pairs for transformed fields
611          */
612         var transform_fields = {};
613         /**
614          * @var transformation_fields   Boolean, if there are any transformed fields in this row
615          */
616         var transformation_fields = false;
618         /**
619          * @var sql_query String containing the SQL query to update this row
620          */
621         var sql_query = 'UPDATE ' + window.parent.table + ' SET ';
623         $input_siblings.each(function() {
624             /** @lends jQuery */
625             /**
626              * @var this_field  Object referring to this field (<td>)
627              */
628             var $this_field = $(this);
629             /**
630              * @var field_name  String containing the name of this field.
631              * @see getFieldName()
632              */
633             var field_name = getFieldName($this_field, disp_mode);
635             /**
636              * @var this_field_params   Array temporary storage for the name/value of current field
637              */
638             var this_field_params = {};
640             if($this_field.is('.transformed')) {
641                 transformation_fields =  true;
642             }
643             /**
644              * @var is_null String capturing whether 'checkbox_null_<field_name>' is checked.
645              */
646             var is_null = $this_field.find('input:checkbox').is(':checked');
647             var value;
649             if (is_null) {
650                 sql_query += ' ' + field_name + "=NULL , ";
651             } else {
652                 if($this_field.is(":not(.relation, .enum)")) {
653                     this_field_params[field_name] = $this_field.find('textarea').val();
654                     if($this_field.is('.transformed')) {
655                         $.extend(transform_fields, this_field_params);
656                     }
657                 }
658                 else {
659                     // results from a drop-down
660                     $test_element = $this_field.find('select');
661                     if ($test_element.length != 0) {
662                         this_field_params[field_name] = $test_element.val();
663                     }
665                     // results from Browse foreign value
666                     $test_element = $this_field.find('span.curr_value');
667                     if ($test_element.length != 0) {
668                         this_field_params[field_name] = $test_element.text();
669                     }
671                     if($this_field.is('.relation')) {
672                         $.extend(relation_fields, this_field_params);
673                     }
674                 }
676                 sql_query += ' ' + field_name + "='" + this_field_params[field_name].replace(/'/g, "''") + "' , ";
677             }
678         })
680         //Remove the last ',' appended in the above loop
681         sql_query = sql_query.replace(/,\s$/, '');
682         sql_query += ' WHERE ' + PMA_urldecode(where_clause);
684         /**
685          * @var rel_fields_list  String, url encoded representation of {@link relations_fields}
686          */
687         var rel_fields_list = $.param(relation_fields);
689         /**
690          * @var transform_fields_list  String, url encoded representation of {@link transform_fields}
691          */
692         var transform_fields_list = $.param(transform_fields);
694         // Make the Ajax post after setting all parameters
695         /**
696          * @var post_params Object containing parameters for the POST request
697          */
698         var post_params = {'ajax_request' : true,
699                             'sql_query' : sql_query,
700                             'disp_direction' : disp_mode,
701                             'token' : window.parent.token,
702                             'db' : window.parent.db,
703                             'table' : window.parent.table,
704                             'clause_is_unique' : nonunique,
705                             'where_clause' : where_clause,
706                             'rel_fields_list' : rel_fields_list,
707                             'do_transformations' : transformation_fields,
708                             'transform_fields_list' : transform_fields_list,
709                             'goto' : 'sql.php',
710                             'submit_type' : 'save'
711                           };
713         $.post('tbl_replace.php', post_params, function(data) {
714             if(data.success == true) {
715                 PMA_ajaxShowMessage(data.message);
716                 $this_td.removeClass('inline_edit_active').addClass('inline_edit_anchor');
718                 $input_siblings.each(function() {
719                     // Inline edit post has been successful.
720                     $this_sibling = $(this);
722                     var is_null = $this_sibling.find('input:checkbox').is(':checked');
723                     if (is_null) {
724                         $this_sibling.html('NULL');
725                         $this_sibling.addClass('null');
726                     } else {
727                         $this_sibling.removeClass('null');
728                         if($this_sibling.is(':not(.relation, .enum)')) {
729                             /**
730                              * @var new_html    String containing value of the data field after edit
731                              */
732                             var new_html = $this_sibling.find('textarea').val();
734                             if($this_sibling.is('.transformed')) {
735                                 var field_name = getFieldName($this_sibling, disp_mode);
736                                 $.each(data.transformations, function(key, value) {
737                                     if(key == field_name) {
738                                         if($this_sibling.is('.text_plain, .application_octetstream')) {
739                                             new_html = value;
740                                             return false;
741                                         }
742                                         else {
743                                             var new_value = $this_sibling.find('textarea').val();
744                                             new_html = $(value).append(new_value);
745                                             return false;
746                                         }
747                                     }
748                                 })
749                             }
750                         }
751                         else {
752                             var new_html = '';
753                             var new_value = '';
754                             $test_element = $this_sibling.find('select');
755                             if ($test_element.length != 0) {
756                                 new_value = $test_element.val();
757                             }
759                             $test_element = $this_sibling.find('span.curr_value');
760                             if ($test_element.length != 0) {
761                                 new_value = $test_element.text();
762                             }
764                             if($this_sibling.is('.relation')) {
765                                 var field_name = getFieldName($this_sibling, disp_mode);
766                                 $.each(data.relations, function(key, value) {
767                                     if(key == field_name) {
768                                         new_html = $(value).append(new_value);
769                                         return false;
770                                     }
771                                 })
772                             }
773                             if($this_sibling.is('.enum')) {
774                                 new_html = new_value;
775                             }
776                         }
777                         $this_sibling.html(new_html);
778                     }
779                 })
780             }
781             else {
782                 PMA_ajaxShowMessage(data.error);
783             };
784         }) // end $.post()
785     }) // End After editing, clicking again should post data
786 }, 'top.frame_content') // end $(document).ready()
789  * Starting from some th, change the class of all td under it
790  */
791 function PMA_changeClassForColumn($this_th, newclass) {
792     // index 0 is the th containing the big T
793     var th_index = $this_th.index();
794     // .eq() is zero-based
795     th_index--;
796     var $tr_with_data = $this_th.closest('table').find('tbody tr ').has('td.data');
797     $tr_with_data.each(function() {
798         $(this).find('td.data:eq('+th_index+')').toggleClass(newclass);
799     });
802 $(document).ready(function() {
804     $('.browse_foreign').live('click', function(e) {
805         e.preventDefault();
806         window.open(this.href, 'foreigners', 'width=640,height=240,scrollbars=yes,resizable=yes');
807         $anchor = $(this);
808         $anchor.addClass('browse_foreign_clicked');
809         return false;
810     });
812     /**
813      * vertical column highlighting in horizontal mode when hovering over the column header
814      */
815     $('.column_heading').live('hover', function() {
816         PMA_changeClassForColumn($(this), 'hover');
817         });
819     /**
820      * vertical column marking in horizontal mode when clicking the column header
821      */
822     $('.column_heading').live('click', function() {
823         PMA_changeClassForColumn($(this), 'marked');
824         });
827 /**#@- */