1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview functions used wherever an sql query form is used
6 * @requires js/functions.js
11 * decode a string URL_encoded
14 * @return string the URL-decoded string
17 function PMA_urldecode(str
) {
18 return decodeURIComponent(str
.replace(/\+/g, '%20'));
22 * Get the field name for the current field. Required to construct the query
25 * @param $this_field jQuery object that points to the current field's tr
26 * @param disp_mode string
28 function getFieldName($this_field
, disp_mode
) {
30 if(disp_mode
== 'vertical') {
31 var field_name
= $this_field
.siblings('th').find('a').text();
32 // happens when just one row (headings contain no a)
33 if ("" == field_name
) {
34 field_name
= $this_field
.siblings('th').text();
38 var this_field_index
= $this_field
.index();
39 // ltr or rtl direction does not impact how the DOM was generated
41 // 5 columns to account for the checkbox, edit, appended inline edit, copy and delete anchors but index is zero-based so substract 4
42 var field_name
= $('#table_results').find('thead').find('th:nth('+ (this_field_index
-4 )+') a').text();
43 // happens when just one row (headings contain no a)
44 if ("" == field_name
) {
45 field_name
= $('#table_results').find('thead').find('th:nth('+ (this_field_index
-4 )+')').text();
49 field_name
= $.trim(field_name
);
55 * The function that iterates over each row in the table_results and appends a
56 * new inline edit anchor to each table row.
59 function appendInlineAnchor() {
60 var disp_mode
= $("#top_direction_dropdown").val();
62 if (disp_mode
== 'vertical') {
63 // there can be one or two tr containing this class, depending
64 // on the ModifyDeleteAtLeft and ModifyDeleteAtRight cfg parameters
65 $('#table_results tr')
66 .find('.edit_row_anchor')
67 .removeClass('edit_row_anchor')
68 .parent().each(function() {
69 var $this_tr
= $(this);
70 var $cloned_tr
= $this_tr
.clone();
72 var $img_object
= $cloned_tr
.find('img:first').attr('title', PMA_messages
['strInlineEdit']);
73 if ($img_object
.length
!= 0) {
74 var img_src
= $img_object
.attr('src').replace(/b_edit/,'b_inline_edit');
75 $img_object
.attr('src', img_src
);
79 .addClass('inline_edit_anchor')
80 .find('a').attr('href', '#')
82 .text(' ' + PMA_messages
['strInlineEdit'])
83 .prepend($img_object
);
85 $cloned_tr
.insertAfter($this_tr
);
88 $('#rowsDeleteForm').find('tbody').find('th').each(function() {
89 var $this_th
= $(this);
90 if ($this_th
.attr('rowspan') == 4) {
91 $this_th
.attr('rowspan', '5');
97 $('.edit_row_anchor').each(function() {
99 var $this_td
= $(this);
100 $this_td
.removeClass('edit_row_anchor');
102 var $cloned_anchor
= $this_td
.clone();
104 var $img_object
= $cloned_anchor
.find('img').attr('title', PMA_messages
['strInlineEdit']);
105 if ($img_object
.length
!= 0) {
106 var img_src
= $img_object
.attr('src').replace(/b_edit/,'b_inline_edit');
107 $img_object
.attr('src', img_src
);
109 .find('a').attr('href', '#')
111 .text(' ' + PMA_messages
['strInlineEdit']);
115 .prepend($img_object
);
117 // the link was too big so <input type="image"> is there
118 $img_object
= $cloned_anchor
.find('input:image').attr('title', PMA_messages
['strInlineEdit']);
119 var img_src
= $img_object
.attr('src').replace(/b_edit/,'b_inline_edit');
120 $img_object
.attr('src', img_src
);
122 .find('.clickprevimage')
123 .text(' ' + PMA_messages
['strInlineEdit']);
127 .addClass('inline_edit_anchor');
129 $this_td
.after($cloned_anchor
);
132 $('#rowsDeleteForm').find('thead, tbody').find('th').each(function() {
133 var $this_th
= $(this);
134 if ($this_th
.attr('colspan') == 4) {
135 $this_th
.attr('colspan', '5');
146 * @description <p>Ajax scripts for sql and browse pages</p>
148 * Actions ajaxified here:
150 * <li>Retrieve results of an SQL query</li>
151 * <li>Paginate the results table</li>
152 * <li>Sort the results table</li>
153 * <li>Change table according to display options</li>
154 * <li>Inline editing of data</li>
157 * @name document.ready
160 $(document
).ready(function() {
163 * Set a parameter for all Ajax queries made on this page. Don't let the
164 * web server serve cached pages
171 * current value of the direction in which the table is displayed
176 var disp_mode
= $("#top_direction_dropdown").val();
179 * Update value of {@link jQuery.disp_mode} everytime the direction dropdown changes value
181 * @name direction_dropdown_change
183 $("#top_direction_dropdown, #bottom_direction_dropdown").live('change', function(event
) {
184 disp_mode
= $(this).val();
188 * Attach the {@link appendInlineAnchor} function to a custom event, which
189 * will be triggered manually everytime the table of results is reloaded
192 $("#sqlqueryresults").live('appendAnchor',function() {
193 appendInlineAnchor();
197 * Trigger the appendAnchor event to prepare the first table for inline edit
198 * (see $GLOBALS['cfg']['AjaxEnable'])
200 * @name sqlqueryresults_trigger
202 $("#sqlqueryresults.ajax").trigger('appendAnchor');
205 * Append the "Show/Hide query box" message to the query input form
208 * @name appendToggleSpan
210 // do not add this link more than once
211 if (! $('#sqlqueryform').find('a').is('#togglequerybox')) {
212 $('<a id="togglequerybox"></a>')
213 .html(PMA_messages
['strHideQueryBox'])
214 .appendTo("#sqlqueryform")
215 // initially hidden because at this point, nothing else
216 // appears under the link
219 // Attach the toggling of the query box visibility to a click
220 $("#togglequerybox").bind('click', function() {
222 $link
.siblings().slideToggle("fast");
223 if ($link
.text() == PMA_messages
['strHideQueryBox']) {
224 $link
.text(PMA_messages
['strShowQueryBox']);
225 // cheap trick to add a spacer between the menu tabs
226 // and "Show query box"; feel free to improve!
227 $('#togglequerybox_spacer').remove();
228 $link
.before('<br id="togglequerybox_spacer" />');
230 $link
.text(PMA_messages
['strHideQueryBox']);
232 // avoid default click action
238 * Ajax Event handler for 'SQL Query Submit'
240 * @see PMA_ajaxShowMessage()
241 * @see $cfg['AjaxEnable']
243 * @name sqlqueryform_submit
245 $("#sqlqueryform.ajax").live('submit', function(event
) {
246 event
.preventDefault();
247 // remove any div containing a previous error message
248 $('.error').remove();
251 PMA_ajaxShowMessage();
253 if (! $form
.find('input:hidden').is('#ajax_request_hidden')) {
254 $form
.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
257 $.post($(this).attr('action'), $(this).serialize() , function(data
) {
258 if(data
.success
== true) {
259 // fade out previous messages, if any
260 $('.success').fadeOut();
261 $('.sqlquery_message').fadeOut();
262 // show a message that stays on screen
263 $('#sqlqueryform').before(data
.message
);
264 // and display the query
265 $('<div class="sqlquery_message"></div>')
266 .html(data
.sql_query
)
267 .insertBefore('#sqlqueryform');
268 // unnecessary div that came from data.sql_query
269 $('.notice').remove();
270 $('#sqlqueryresults').show();
271 // this happens if a USE command was typed
272 if (typeof data
.reload
!= 'undefined') {
273 $form
.find('input[name=db]').val(data
.db
);
274 // need to regenerate the whole upper part
275 $form
.find('input[name=ajax_request]').remove();
276 $form
.append('<input type="hidden" name="reload" value="true" />');
277 $.post('db_sql.php', $form
.serialize(), function(data
) {
278 $('body').html(data
);
279 }); // end inner post
282 else if (data
.success
== false ) {
283 // show an error message that stays on screen
284 $('#sqlqueryform').before(data
.error
);
285 $('#sqlqueryresults').hide();
288 // real results are returned
289 $received_data
= $(data
);
290 $zero_row_results
= $received_data
.find('textarea[name="sql_query"]');
291 // if zero rows are returned from the query execution
292 if ($zero_row_results
.length
> 0) {
293 $('#sqlquery').val($zero_row_results
.val());
295 $('#sqlqueryresults').show();
296 $("#sqlqueryresults").html(data
);
297 $("#sqlqueryresults").trigger('appendAnchor');
298 $('#togglequerybox').show();
299 if($("#togglequerybox").siblings(":visible").length
> 0) {
300 $("#togglequerybox").trigger('click');
306 }) // end SQL Query submit
309 * Ajax Event handlers for Paginating the results table
313 * Paginate when we click any of the navigation buttons
314 * (only if the element has the ajax class, see $cfg['AjaxEnable'])
316 * @name paginate_nav_button_click
317 * @uses PMA_ajaxShowMessage()
318 * @see $cfg['AjaxEnable']
320 $("input[name=navig].ajax").live('click', function(event
) {
322 event
.preventDefault();
324 PMA_ajaxShowMessage();
327 * @var $the_form Object referring to the form element that paginates the results table
329 var $the_form
= $(this).parent("form");
331 $the_form
.append('<input type="hidden" name="ajax_request" value="true" />');
333 $.post($the_form
.attr('action'), $the_form
.serialize(), function(data
) {
334 $("#sqlqueryresults").html(data
);
335 $("#sqlqueryresults").trigger('appendAnchor');
338 })// end Paginate results table
341 * Paginate results with Page Selector dropdown
343 * @name paginate_dropdown_change
344 * @see $cfg['AjaxEnable']
346 $("#pageselector").live('change', function(event
) {
347 var $the_form
= $(this).parent("form");
349 if ($(this).hasClass('ajax')) {
350 event
.preventDefault();
352 PMA_ajaxShowMessage();
354 $.post($the_form
.attr('action'), $the_form
.serialize() + '&ajax_request=true', function(data
) {
355 $("#sqlqueryresults").html(data
);
356 $("#sqlqueryresults").trigger('appendAnchor');
363 })// end Paginate results with Page Selector
366 * Ajax Event handler for sorting the results table
368 * @name table_results_sort_click
369 * @see $cfg['AjaxEnable']
371 $("#table_results.ajax").find("a[title=Sort]").live('click', function(event
) {
372 event
.preventDefault();
374 PMA_ajaxShowMessage();
378 $.get($anchor
.attr('href'), $anchor
.serialize() + '&ajax_request=true', function(data
) {
379 $("#sqlqueryresults")
381 .trigger('appendAnchor');
383 })//end Sort results table
386 * Ajax Event handler for the display options
388 * @name displayOptionsForm_submit
389 * @see $cfg['AjaxEnable']
391 $("#displayOptionsForm.ajax").live('submit', function(event
) {
392 event
.preventDefault();
396 $.post($form
.attr('action'), $form
.serialize() + '&ajax_request=true' , function(data
) {
397 $("#sqlqueryresults")
399 .trigger('appendAnchor');
403 //end displayOptionsForm handler
406 * Ajax Event handlers for Inline Editing
410 * On click, replace the fields of current row with an input/textarea
412 * @name inline_edit_start
413 * @see PMA_ajaxShowMessage()
414 * @see getFieldName()
416 $(".inline_edit_anchor span a").live('click', function(event
) {
418 event
.preventDefault();
420 var $edit_td
= $(this).parents('td');
421 $edit_td
.removeClass('inline_edit_anchor').addClass('inline_edit_active').parent('tr').addClass('noclick');
423 // adding submit and hide buttons to inline edit <td>
424 // for "hide", button the original data to be restored is present in .original_data
425 // looping through all columns or rows, to find the required data and then storing it in an array.
427 var $this_children
= $edit_td
.children('span.nowrap').children('a').children('span.nowrap');
428 if (disp_mode
!= 'vertical') {
429 $this_children
.empty();
430 $this_children
.text(PMA_messages
['strSave']);
433 data_vt
= $this_children
.html();
434 $this_children
.text(PMA_messages
['strSave']);
437 var hide_link
= '<br /><br /><a id="hide">' + PMA_messages
['strHide'] + '</a>';
438 if (disp_mode
!= 'vertical') {
439 $edit_td
.append(hide_link
);
440 $('#table_results tbody tr td a#hide').click(function() {
441 $this_children
= $(this).siblings('span.nowrap').children('a').children('span.nowrap');
442 $this_children
.empty();
443 $this_children
.text(PMA_messages
['strInlineEdit']);
445 var $this_hide
= $(this).parent();
446 $this_hide
.removeClass("inline_edit_active hover").addClass("inline_edit_anchor");
447 $this_hide
.parent().removeClass("hover noclick");
448 $this_hide
.siblings().removeClass("hover");
450 var last_column
= $this_hide
.siblings().length
;
452 for(var i
= 4; i
< last_column
; i
++) {
453 if($this_hide
.siblings("td:eq(" + i
+ ")").hasClass("inline_edit") == false) {
456 txt
= $this_hide
.siblings("td:eq(" + i
+ ")").children(' .original_data').html();
457 if($this_hide
.siblings("td:eq(" + i
+ ")").children().length
!= 0) {
458 $this_hide
.siblings("td:eq(" + i
+ ")").empty();
459 $this_hide
.siblings("td:eq(" + i
+ ")").append(txt
);
462 $(this).prev().prev().remove();
463 $(this).prev().remove();
468 var rows
= $edit_td
.parent().siblings().length
;
470 $edit_td
.append(hide_link
);
471 $('#table_results tbody tr td a#hide').click(function() {
472 var pos
= $(this).parent().index();
473 var $chg_submit
= $(this).parent().children('span.nowrap').children('a').children('span.nowrap');
475 $chg_submit
.append(data_vt
);
477 var $this_row
= $(this).parents('tr');
478 // changing inline_edit_active to inline_edit_anchor
479 $this_row
.siblings("tr:eq(3) td:eq(" + pos
+ ")").removeClass("inline_edit_active").addClass("inline_edit_anchor");
481 // removing marked and hover classes.
482 $this_row
.parent('tbody').find('tr').find("td:eq(" + pos
+ ")").removeClass("marked hover");
484 for( var i
= 6; i
<= rows
+ 2; i
++){
485 if( $this_row
.siblings("tr:eq(" + i
+ ") td:eq(" + pos
+ ")").hasClass("inline_edit") == false) {
488 txt
= $this_row
.siblings("tr:eq(" + i
+ ") td:eq(" + pos
+ ") span.original_data").html();
489 $this_row
.siblings("tr:eq(" + i
+ ") td:eq(" + pos
+ ")").empty();
490 $this_row
.siblings("tr:eq(" + i
+ ") td:eq(" + pos
+ ")").append(txt
);
492 $(this).prev().remove();
493 $(this).prev().remove();
498 // Initialize some variables
499 if(disp_mode
== 'vertical') {
501 * @var this_row_index Index of the current <td> in the parent <tr>
502 * Current <td> is the inline edit anchor.
504 var this_row_index
= $edit_td
.index();
506 * @var $input_siblings Object referring to all inline editable events from same row
508 var $input_siblings
= $edit_td
.parents('tbody').find('tr').find('.inline_edit:nth('+this_row_index
+')');
510 * @var where_clause String containing the WHERE clause to select this row
512 var where_clause
= $edit_td
.parents('tbody').find('tr').find('.where_clause:nth('+this_row_index
+')').val();
516 var this_row_index
= $edit_td
.parent().index();
517 var $input_siblings
= $edit_td
.parent('tr').find('.inline_edit');
518 var where_clause
= $edit_td
.parent('tr').find('.where_clause').val();
521 $input_siblings
.each(function() {
524 * @var data_value Current value of this field
526 var data_value
= $(this).html();
528 // We need to retrieve the value from the server for truncated/relation fields
529 // Find the field name
532 * @var this_field Object referring to this field (<td>)
534 var $this_field
= $(this);
536 * @var field_name String containing the name of this field.
537 * @see getFieldName()
539 var field_name
= getFieldName($this_field
, disp_mode
);
541 * @var relation_curr_value String current value of the field (for fields that are foreign keyed).
543 var relation_curr_value
= $this_field
.find('a').text();
545 * @var curr_value String current value of the field (for fields that are of type enum or set).
547 var curr_value
= $this_field
.text();
549 if($this_field
.is(':not(.not_null)')){
550 // add a checkbox to mark null for all the field that are nullable.
551 $this_field
.html('<div class="null_div">Null :<input type="checkbox" class="checkbox_null_'+ field_name
+ '_' + this_row_index
+'"></div>');
552 // check the 'checkbox_null_<field_name>_<row_index>' if the corresponding value is null
553 if($this_field
.is('.null')) {
554 $('.checkbox_null_' + field_name
+ '_' + this_row_index
).attr('checked', true);
557 // if the select/editor is changed un-check the 'checkbox_null_<field_name>_<row_index>'.
558 if ($this_field
.is('.enum, .set')) {
559 $this_field
.find('select').live('change', function(e
) {
560 $('.checkbox_null_' + field_name
+ '_' + this_row_index
).attr('checked', false);
562 } else if ($this_field
.is('.relation')) {
563 $this_field
.find('select').live('change', function(e
) {
564 $('.checkbox_null_' + field_name
+ '_' + this_row_index
).attr('checked', false);
566 $this_field
.find('.browse_foreign').live('click', function(e
) {
567 $('.checkbox_null_' + field_name
+ '_' + this_row_index
).attr('checked', false);
570 $this_field
.find('textarea').live('keypress', function(e
) {
571 $('.checkbox_null_' + field_name
+ '_' + this_row_index
).attr('checked', false);
575 // if 'chechbox_null_<field_name>_<row_index>' is clicked empty the corresponding select/editor.
576 $('.checkbox_null_' + field_name
+ '_' + this_row_index
).bind('click', function(e
) {
577 if ($this_field
.is('.enum')) {
578 $this_field
.find('select').attr('value', '');
579 } else if ($this_field
.is('.set')) {
580 $this_field
.find('select').find('option').each(function() {
581 var $option
= $(this);
582 $option
.attr('selected', false);
584 } else if ($this_field
.is('.relation')) {
585 // if the dropdown is there to select the foreign value
586 if ($this_field
.find('select').length
> 0) {
587 $this_field
.find('select').attr('value', '');
588 // if foriegn value is selected by browsing foreing values
590 $this_field
.find('span.curr_value').empty();
593 $this_field
.find('textarea').val('');
598 $this_field
.html('<div class="null_div"></div>');
601 // In each input sibling, wrap the current value in a textarea
602 // and store the current value in a hidden span
603 if($this_field
.is(':not(.truncated, .transformed, .relation, .enum, .set, .null)')) {
604 // handle non-truncated, non-transformed, non-relation values
605 // We don't need to get any more data, just wrap the value
606 $this_field
.append('<textarea>'+data_value
+'</textarea>');
607 $this_field
.append('<span class="original_data">'+data_value
+'</span>');
608 $(".original_data").hide();
610 else if($this_field
.is('.truncated, .transformed')) {
612 //handle truncated/transformed values values
615 * @var sql_query String containing the SQL query used to retrieve value of truncated/transformed data
617 var sql_query
= 'SELECT ' + field_name
+ ' FROM ' + window
.parent
.table
+ ' WHERE ' + where_clause
;
619 // Make the Ajax call and get the data, wrap it and insert it
621 'token' : window
.parent
.token
,
622 'db' : window
.parent
.db
,
623 'ajax_request' : true,
624 'sql_query' : sql_query
,
627 if(data
.success
== true) {
628 $this_field
.append('<textarea>'+data
.value
+'</textarea>');
629 $this_field
.append('<span class="original_data">'+data_value
+'</span>');
630 $(".original_data").hide();
633 PMA_ajaxShowMessage(data
.error
);
637 else if($this_field
.is('.relation')) {
642 * @var post_params Object containing parameters for the POST request
645 'ajax_request' : true,
646 'get_relational_values' : true,
647 'db' : window
.parent
.db
,
648 'table' : window
.parent
.table
,
649 'column' : field_name
,
650 'token' : window
.parent
.token
,
651 'curr_value' : relation_curr_value
654 $.post('sql.php', post_params
, function(data
) {
655 $this_field
.append(data
.dropdown
);
656 $this_field
.append('<span class="original_data">'+data_value
+'</span>');
657 $(".original_data").hide();
660 else if($this_field
.is('.enum')) {
665 * @var post_params Object containing parameters for the POST request
668 'ajax_request' : true,
669 'get_enum_values' : true,
670 'db' : window
.parent
.db
,
671 'table' : window
.parent
.table
,
672 'column' : field_name
,
673 'token' : window
.parent
.token
,
674 'curr_value' : curr_value
677 $.post('sql.php', post_params
, function(data
) {
678 $this_field
.append(data
.dropdown
);
679 $this_field
.append('<span class="original_data">'+data_value
+'</span>');
680 $(".original_data").hide();
683 else if($this_field
.is('.set')) {
688 * @var post_params Object containing parameters for the POST request
691 'ajax_request' : true,
692 'get_set_values' : true,
693 'db' : window
.parent
.db
,
694 'table' : window
.parent
.table
,
695 'column' : field_name
,
696 'token' : window
.parent
.token
,
697 'curr_value' : curr_value
700 $.post('sql.php', post_params
, function(data
) {
701 $this_field
.append(data
.select
);
702 $this_field
.append('<span class="original_data">'+data_value
+'</span>');
703 $(".original_data").hide();
706 else if($this_field
.is('.null')) {
708 $this_field
.append('<textarea></textarea>');
709 $this_field
.append('<span class="original_data">NULL</span>');
710 $(".original_data").hide();
713 }) // End On click, replace the current field with an input/textarea
716 * After editing, clicking again should post data
719 * @name inline_edit_save
720 * @see PMA_ajaxShowMessage()
721 * @see getFieldName()
723 $(".inline_edit_active span a").live('click', function(event
) {
726 event
.preventDefault();
729 * @var $this_td Object referring to the td containing the
730 * "Inline Edit" link that was clicked to save the row that is
734 var $this_td
= $(this).parent().parent();
735 var $test_element
= ''; // to test the presence of a element
737 // Initialize variables
738 if(disp_mode
== 'vertical') {
740 * @var this_td_index Index of the current <td> in the parent <tr>
741 * Current <td> is the inline edit anchor.
743 var this_td_index
= $this_td
.index();
745 * @var $input_siblings Object referring to all inline editable events from same row
747 var $input_siblings
= $this_td
.parents('tbody').find('tr').find('.inline_edit:nth('+this_td_index
+')');
749 * @var where_clause String containing the WHERE clause to select this row
751 var where_clause
= $this_td
.parents('tbody').find('tr').find('.where_clause:nth('+this_td_index
+')').val();
753 var $input_siblings
= $this_td
.parent('tr').find('.inline_edit');
754 var where_clause
= $this_td
.parent('tr').find('.where_clause').val();
758 * @var nonunique Boolean, whether this row is unique or not
760 if($this_td
.is('.nonunique')) {
767 // Collect values of all fields to submit, we don't know which changed
769 * @var relation_fields Array containing the name/value pairs of relational fields
771 var relation_fields
= {};
773 * @var transform_fields Array containing the name/value pairs for transformed fields
775 var transform_fields
= {};
777 * @var transformation_fields Boolean, if there are any transformed fields in this row
779 var transformation_fields
= false;
782 * @var sql_query String containing the SQL query to update this row
784 var sql_query
= 'UPDATE `' + window
.parent
.table
+ '` SET ';
786 $input_siblings
.each(function() {
789 * @var this_field Object referring to this field (<td>)
791 var $this_field
= $(this);
793 * @var field_name String containing the name of this field.
794 * @see getFieldName()
796 var field_name
= getFieldName($this_field
, disp_mode
);
799 * @var this_field_params Array temporary storage for the name/value of current field
801 var this_field_params
= {};
803 if($this_field
.is('.transformed')) {
804 transformation_fields
= true;
807 * @var is_null String capturing whether 'checkbox_null_<field_name>_<row_index>' is checked.
809 var is_null
= $this_field
.find('input:checkbox').is(':checked');
813 sql_query
+= ' `' + field_name
+ "`=NULL , ";
815 if($this_field
.is(":not(.relation, .enum, .set)")) {
816 this_field_params
[field_name
] = $this_field
.find('textarea').val();
817 if($this_field
.is('.transformed')) {
818 $.extend(transform_fields
, this_field_params
);
820 } else if ($this_field
.is('.set')) {
821 $test_element
= $this_field
.find('select');
822 this_field_params
[field_name
] = $test_element
.map(function(){
823 return $(this).val();
826 // results from a drop-down
827 $test_element
= $this_field
.find('select');
828 if ($test_element
.length
!= 0) {
829 this_field_params
[field_name
] = $test_element
.val();
832 // results from Browse foreign value
833 $test_element
= $this_field
.find('span.curr_value');
834 if ($test_element
.length
!= 0) {
835 this_field_params
[field_name
] = $test_element
.text();
838 if($this_field
.is('.relation')) {
839 $.extend(relation_fields
, this_field_params
);
842 sql_query
+= ' `' + field_name
+ "`='" + this_field_params
[field_name
].replace(/'/g, "''") + "' , ";
846 //Remove the last ',' appended in the above loop
847 sql_query = sql_query.replace(/,\s$/, '');
848 sql_query += ' WHERE ' + PMA_urldecode(where_clause);
851 * @var rel_fields_list String, url encoded representation of {@link relations_fields}
853 var rel_fields_list = $.param(relation_fields);
856 * @var transform_fields_list String, url encoded representation of {@link transform_fields}
858 var transform_fields_list = $.param(transform_fields);
860 // Make the Ajax post after setting all parameters
862 * @var post_params Object containing parameters for the POST request
864 var post_params = {'ajax_request' : true,
865 'sql_query' : sql_query,
866 'disp_direction' : disp_mode,
867 'token' : window.parent.token,
868 'db' : window.parent.db,
869 'table' : window.parent.table,
870 'clause_is_unique' : nonunique,
871 'where_clause' : where_clause,
872 'rel_fields_list' : rel_fields_list,
873 'do_transformations' : transformation_fields,
874 'transform_fields_list' : transform_fields_list,
876 'submit_type' : 'save'
879 // if inline_edit is successful, we need to go back to default view
880 var $del_hide=$(this).parent();
881 var $chg_submit=$(this);
883 $.post('tbl_replace.php', post_params, function(data) {
884 if(data.success == true) {
885 // deleting the hide button if my query was successful
886 // remove <br><br><a> tags
887 for ( var i=0;i<=2;i++) { $del_hide.next().remove(); }
888 if(disp_mode!='vertical'){
890 $chg_submit.html('<span class="nowrap
"></span>');
891 $chg_submit.children('span.nowrap').text(PMA_messages['strInlineEdit']);
894 $chg_submit.children('span.nowrap').empty();
895 $chg_submit.children('span.nowrap').append(data_vt);
898 PMA_ajaxShowMessage(data.message);
900 // changing inline_edit_active to inline_edit_anchor
901 $this_td.removeClass('inline_edit_active').addClass('inline_edit_anchor');
903 // removing hover, marked and noclick classes
904 $this_td.parent('tr').removeClass('noclick');
905 if(disp_mode != 'vertical') {
906 $this_td.parent('tr').removeClass('hover').find('td').removeClass('hover');
908 $this_td.parents('tbody').find('tr').find('td:eq(' + $this_td.index() + ')').removeClass('marked');
911 $input_siblings.each(function() {
912 // Inline edit post has been successful.
913 $this_sibling = $(this);
915 var is_null = $this_sibling.find('input:checkbox').is(':checked');
917 $this_sibling.html('NULL');
918 $this_sibling.addClass('null');
920 $this_sibling.removeClass('null');
921 if($this_sibling.is(':not(.relation, .enum, .set)')) {
923 * @var new_html String containing value of the data field after edit
925 var new_html = $this_sibling.find('textarea').val();
927 if($this_sibling.is('.transformed')) {
928 var field_name = getFieldName($this_sibling, disp_mode);
929 $.each(data.transformations, function(key, value) {
930 if(key == field_name) {
931 if($this_sibling.is('.text_plain, .application_octetstream')) {
936 var new_value = $this_sibling.find('textarea').val();
937 new_html = $(value).append(new_value);
947 $test_element = $this_sibling.find('select');
948 if ($test_element.length != 0) {
949 new_value = $test_element.val();
952 $test_element = $this_sibling.find('span.curr_value');
953 if ($test_element.length != 0) {
954 new_value = $test_element.text();
957 if($this_sibling.is('.relation')) {
958 var field_name = getFieldName($this_sibling, disp_mode);
959 $.each(data.relations, function(key, value) {
960 if(key == field_name) {
961 new_html = $(value).append(new_value);
965 } else if ($this_sibling.is('.enum')) {
966 new_html = new_value;
967 } else if ($this_sibling.is('.set')) {
968 if (new_value != null) {
969 $.each(new_value, function(key, value) {
970 new_html = new_html + value + ',';
972 new_html = new_html.substring(0, new_html.length-1);
976 $this_sibling.html(new_html);
981 PMA_ajaxShowMessage(data.error);
984 }) // End After editing, clicking again should post data
985 }, 'top.frame_content') // end $(document).ready()
988 * Starting from some th, change the class of all td under it
990 function PMA_changeClassForColumn($this_th, newclass) {
991 // index 0 is the th containing the big T
992 var th_index = $this_th.index();
993 // .eq() is zero-based
995 var $tds = $this_th.closest('table').find('tbody tr').find('td.data:eq('+th_index+')');
996 if ($this_th.data('has_class_'+newclass)) {
997 $tds.removeClass(newclass);
998 $this_th.data('has_class_'+newclass, false);
1000 $tds.addClass(newclass);
1001 $this_th.data('has_class_'+newclass, true);
1005 $(document).ready(function() {
1007 $('.browse_foreign').live('click', function(e) {
1009 window.open(this.href, 'foreigners', 'width=640,height=240,scrollbars=yes,resizable=yes');
1011 $anchor.addClass('browse_foreign_clicked');
1016 * vertical column highlighting in horizontal mode when hovering over the column header
1018 $('.column_heading').live('hover', function() {
1019 PMA_changeClassForColumn($(this), 'hover');
1023 * vertical column marking in horizontal mode when clicking the column header
1025 $('.column_heading').live('click', function() {
1026 PMA_changeClassForColumn($(this), 'marked');