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
14 * decode a string URL_encoded
17 * @return string the URL-decoded string
19 function PMA_urldecode (str) {
20 if (typeof str !== 'undefined') {
21 return decodeURIComponent(str.replace(/\+/g, '%20'));
26 * endecode a string URL_decoded
29 * @return string the URL-encoded string
31 function PMA_urlencode (str) {
32 if (typeof str !== 'undefined') {
33 return encodeURIComponent(str).replace(/\%20/g, '+');
38 * Saves SQL query in local storage or cookie
40 * @param string SQL query
43 function PMA_autosaveSQL (query) {
45 if (isStorageSupported('localStorage')) {
46 window.localStorage.auto_saved_sql = query;
48 Cookies.set('auto_saved_sql', query);
54 * Saves SQL query with sort in local storage or cookie
56 * @param string SQL query
59 function PMA_autosaveSQLSort (query) {
61 if (isStorageSupported('localStorage')) {
62 window.localStorage.auto_saved_sql_sort = query;
64 Cookies.set('auto_saved_sql_sort', query);
70 * Get the field name for the current field. Required to construct the query
73 * @param $table_results enclosing results table
74 * @param $this_field jQuery object that points to the current field's tr
76 function getFieldName ($table_results, $this_field) {
77 var this_field_index = $this_field.index();
78 // ltr or rtl direction does not impact how the DOM was generated
79 // check if the action column in the left exist
80 var left_action_exist = !$table_results.find('th:first').hasClass('draggable');
81 // number of column span for checkbox and Actions
82 var left_action_skip = left_action_exist ? $table_results.find('th:first').attr('colspan') - 1 : 0;
84 // If this column was sorted, the text of the a element contains something
85 // like <small>1</small> that is useful to indicate the order in case
86 // of a sort on multiple columns; however, we dont want this as part
87 // of the column name so we strip it ( .clone() to .end() )
88 var field_name = $table_results
90 .find('th:eq(' + (this_field_index - left_action_skip) + ') a')
91 .clone() // clone the element
92 .children() // select all the children
93 .remove() // remove all of them
94 .end() // go back to the selected element
95 .text(); // grab the text
96 // happens when just one row (headings contain no a)
97 if (field_name === '') {
98 var $heading = $table_results.find('thead').find('th:eq(' + (this_field_index - left_action_skip) + ')').children('span');
99 // may contain column comment enclosed in a span - detach it temporarily to read the column name
100 var $tempColComment = $heading.children().detach();
101 field_name = $heading.text();
102 // re-attach the column comment
103 $heading.append($tempColComment);
106 field_name = $.trim(field_name);
112 * Unbind all event handlers before tearing down a page
114 AJAX.registerTeardown('sql.js', function () {
115 $(document).off('click', 'a.delete_row.ajax');
116 $(document).off('submit', '.bookmarkQueryForm');
117 $('input#bkm_label').off('keyup');
118 $(document).off('makegrid', '.sqlqueryresults');
119 $(document).off('stickycolumns', '.sqlqueryresults');
120 $('#togglequerybox').off('click');
121 $(document).off('click', '#button_submit_query');
122 $(document).off('change', '#id_bookmark');
123 $('input[name=\'bookmark_variable\']').off('keypress');
124 $(document).off('submit', '#sqlqueryform.ajax');
125 $(document).off('click', 'input[name=navig].ajax');
126 $(document).off('submit', 'form[name=\'displayOptionsForm\'].ajax');
127 $(document).off('mouseenter', 'th.column_heading.pointer');
128 $(document).off('mouseleave', 'th.column_heading.pointer');
129 $(document).off('click', 'th.column_heading.marker');
130 $(window).off('scroll');
131 $(document).off('keyup', '.filter_rows');
132 $(document).off('click', '#printView');
133 if (codemirror_editor) {
134 codemirror_editor.off('change');
136 $('#sqlquery').off('input propertychange');
138 $('body').off('click', '.navigation .showAllRows');
139 $('body').off('click', 'a.browse_foreign');
140 $('body').off('click', '#simulate_dml');
141 $('body').off('keyup', '#sqlqueryform');
142 $('body').off('click', 'form[name="resultsForm"].ajax button[name="submit_mult"], form[name="resultsForm"].ajax input[name="submit_mult"]');
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>Grid editing of data</li>
155 * <li>Saving a bookmark</li>
158 * @name document.ready
161 AJAX.registerOnload('sql.js', function () {
163 if (codemirror_editor) {
164 codemirror_editor.on('change', function () {
165 PMA_autosaveSQL(codemirror_editor.getValue());
168 $('#sqlquery').on('input propertychange', function () {
169 PMA_autosaveSQL($('#sqlquery').val());
171 // Save sql query with sort
172 if ($('#RememberSorting') !== undefined && $('#RememberSorting').is(':checked')) {
173 $('select[name="sql_query"]').on('change', function () {
174 PMA_autosaveSQLSort($('select[name="sql_query"]').val());
177 if (isStorageSupported('localStorage') && window.localStorage.auto_saved_sql_sort !== undefined) {
178 window.localStorage.removeItem('auto_saved_sql_sort');
180 Cookies.set('auto_saved_sql_sort', '');
183 // If sql query with sort for current table is stored, change sort by key select value
184 var sortStoredQuery = (isStorageSupported('localStorage') && typeof window.localStorage.auto_saved_sql_sort !== 'undefined') ? window.localStorage.auto_saved_sql_sort : Cookies.get('auto_saved_sql_sort');
185 if (typeof sortStoredQuery !== 'undefined' && sortStoredQuery !== $('select[name="sql_query"]').val() && $('select[name="sql_query"] option[value="' + sortStoredQuery + '"]').length !== 0) {
186 $('select[name="sql_query"]').val(sortStoredQuery).change();
191 // Delete row from SQL results
192 $(document).on('click', 'a.delete_row.ajax', function (e) {
194 var question = PMA_sprintf(PMA_messages.strDoYouReally, escapeHtml($(this).closest('td').find('div').text()));
196 $link.PMA_confirm(question, $link.attr('href'), function (url) {
197 $msgbox = PMA_ajaxShowMessage();
198 var argsep = PMA_commonParams.get('arg_separator');
199 var params = 'ajax_request=1' + argsep + 'is_js_confirmed=1';
200 var postData = $link.getPostData();
202 params += argsep + postData;
204 $.post(url, params, function (data) {
206 PMA_ajaxShowMessage(data.message);
207 $link.closest('tr').remove();
209 PMA_ajaxShowMessage(data.error, false);
215 // Ajaxification for 'Bookmark this SQL query'
216 $(document).on('submit', '.bookmarkQueryForm', function (e) {
218 PMA_ajaxShowMessage();
219 var argsep = PMA_commonParams.get('arg_separator');
220 $.post($(this).attr('action'), 'ajax_request=1' + argsep + $(this).serialize(), function (data) {
222 PMA_ajaxShowMessage(data.message);
224 PMA_ajaxShowMessage(data.error, false);
229 /* Hides the bookmarkoptions checkboxes when the bookmark label is empty */
230 $('input#bkm_label').keyup(function () {
231 $('input#id_bkm_all_users, input#id_bkm_replace')
233 .toggle($(this).val().length > 0);
237 * Attach Event Handler for 'Copy to clipbpard
239 $(document).on('click', '#copyToClipBoard', function (event) {
240 event.preventDefault();
242 var textArea = document.createElement('textarea');
245 // *** This styling is an extra step which is likely not required. ***
247 // Why is it here? To ensure:
248 // 1. the element is able to have focus and selection.
249 // 2. if element was to flash render it has minimal visual impact.
250 // 3. less flakyness with selection and copying which **might** occur if
251 // the textarea element is not visible.
253 // The likelihood is the element won't even render, not even a flash,
254 // so some of these are just precautions. However in IE the element
255 // is visible whilst the popup box asking the user for permission for
256 // the web page to copy to the clipboard.
259 // Place in top-left corner of screen regardless of scroll position.
260 textArea.style.position = 'fixed';
261 textArea.style.top = 0;
262 textArea.style.left = 0;
264 // Ensure it has a small width and height. Setting to 1px / 1em
265 // doesn't work as this gives a negative w/h on some browsers.
266 textArea.style.width = '2em';
267 textArea.style.height = '2em';
269 // We don't need padding, reducing the size if it does flash render.
270 textArea.style.padding = 0;
272 // Clean up any borders.
273 textArea.style.border = 'none';
274 textArea.style.outline = 'none';
275 textArea.style.boxShadow = 'none';
277 // Avoid flash of white box if rendered for any reason.
278 textArea.style.background = 'transparent';
282 $('#serverinfo a').each(function () {
283 textArea.value += $(this).text().split(':')[1].trim() + '/';
285 textArea.value += '\t\t' + window.location.href;
286 textArea.value += '\n';
287 $('.success').each(function () {
288 textArea.value += $(this).text() + '\n\n';
291 $('.sql pre').each(function () {
292 textArea.value += $(this).text() + '\n\n';
295 $('.table_results .column_heading a').each(function () {
296 //Don't copy ordering number text within <small> tag
297 textArea.value += $(this).clone().find('small').remove().end().text() + '\t';
300 textArea.value += '\n';
301 $('.table_results tbody tr').each(function () {
302 $(this).find('.data span').each(function () {
303 textArea.value += $(this).text() + '\t';
305 textArea.value += '\n';
308 document.body.appendChild(textArea);
313 document.execCommand('copy');
315 alert('Sorry! Unable to copy');
318 document.body.removeChild(textArea);
319 }); // end of Copy to Clipboard action
322 * Attach Event Handler for 'Print' link
324 $(document).on('click', '#printView', function (event) {
325 event.preventDefault();
327 // Take to preview mode
329 }); // end of 'Print' action
332 * Attach the {@link makegrid} function to a custom event, which will be
333 * triggered manually everytime the table of results is reloaded
336 $(document).on('makegrid', '.sqlqueryresults', function () {
337 $('.table_results').each(function () {
343 * Attach a custom event for sticky column headings which will be
344 * triggered manually everytime the table of results is reloaded
347 $(document).on('stickycolumns', '.sqlqueryresults', function () {
348 $('.sticky_columns').remove();
349 $('.table_results').each(function () {
350 var $table_results = $(this);
351 // add sticky columns div
352 var $stick_columns = initStickyColumns($table_results);
353 rearrangeStickyColumns($stick_columns, $table_results);
354 // adjust sticky columns on scroll
355 $(window).on('scroll', function () {
356 handleStickyColumns($stick_columns, $table_results);
362 * Append the "Show/Hide query box" message to the query input form
365 * @name appendToggleSpan
367 // do not add this link more than once
368 if (! $('#sqlqueryform').find('a').is('#togglequerybox')) {
369 $('<a id="togglequerybox"></a>')
370 .html(PMA_messages.strHideQueryBox)
371 .appendTo('#sqlqueryform')
372 // initially hidden because at this point, nothing else
373 // appears under the link
376 // Attach the toggling of the query box visibility to a click
377 $('#togglequerybox').bind('click', function () {
379 $link.siblings().slideToggle('fast');
380 if ($link.text() === PMA_messages.strHideQueryBox) {
381 $link.text(PMA_messages.strShowQueryBox);
382 // cheap trick to add a spacer between the menu tabs
383 // and "Show query box"; feel free to improve!
384 $('#togglequerybox_spacer').remove();
385 $link.before('<br id="togglequerybox_spacer" />');
387 $link.text(PMA_messages.strHideQueryBox);
389 // avoid default click action
396 * Event handler for sqlqueryform.ajax button_submit_query
400 $(document).on('click', '#button_submit_query', function (event) {
401 $('.success,.error').hide();
402 // hide already existing error or success message
403 var $form = $(this).closest('form');
404 // the Go button related to query submission was clicked,
405 // instead of the one related to Bookmarks, so empty the
406 // id_bookmark selector to avoid misinterpretation in
407 // import.php about what needs to be done
408 $form.find('select[name=id_bookmark]').val('');
409 // let normal event propagation happen
413 * Event handler to show appropiate number of variable boxes
414 * based on the bookmarked query
416 $(document).on('change', '#id_bookmark', function (event) {
417 var varCount = $(this).find('option:selected').data('varcount');
418 if (typeof varCount === 'undefined') {
422 var $varDiv = $('#bookmark_variables');
424 for (var i = 1; i <= varCount; i++) {
425 $varDiv.append($('<label for="bookmark_variable_' + i + '">' + PMA_sprintf(PMA_messages.strBookmarkVariable, i) + '</label>'));
426 $varDiv.append($('<input type="text" size="10" name="bookmark_variable[' + i + ']" id="bookmark_variable_' + i + '"/>'));
429 if (varCount === 0) {
430 $varDiv.parent('.formelement').hide();
432 $varDiv.parent('.formelement').show();
437 * Event handler for hitting enter on sqlqueryform bookmark_variable
438 * (the Variable textfield in Bookmarked SQL query section)
442 $('input[name=bookmark_variable]').on('keypress', function (event) {
443 // force the 'Enter Key' to implicitly click the #button_submit_bookmark
444 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
445 if (keycode === 13) { // keycode for enter key
446 // When you press enter in the sqlqueryform, which
447 // has 2 submit buttons, the default is to run the
448 // #button_submit_query, because of the tabindex
450 // This submits #button_submit_bookmark instead,
451 // because when you are in the Bookmarked SQL query
452 // section and hit enter, you expect it to do the
453 // same action as the Go button in that section.
454 $('#button_submit_bookmark').click();
462 * Ajax Event handler for 'SQL Query Submit'
464 * @see PMA_ajaxShowMessage()
466 * @name sqlqueryform_submit
468 $(document).on('submit', '#sqlqueryform.ajax', function (event) {
469 event.preventDefault();
472 if (codemirror_editor) {
473 $form[0].elements.sql_query.value = codemirror_editor.getValue();
475 if (! checkSqlQuery($form[0])) {
479 // remove any div containing a previous error message
480 $('div.error').remove();
482 var $msgbox = PMA_ajaxShowMessage();
483 var $sqlqueryresultsouter = $('#sqlqueryresultsouter');
485 PMA_prepareForAjaxRequest($form);
487 var argsep = PMA_commonParams.get('arg_separator');
488 $.post($form.attr('action'), $form.serialize() + argsep + 'ajax_page_request=true', function (data) {
489 if (typeof data !== 'undefined' && data.success === true) {
490 // success happens if the query returns rows or not
492 // show a message that stays on screen
493 if (typeof data.action_bookmark !== 'undefined') {
495 if ('1' === data.action_bookmark) {
496 $('#sqlquery').text(data.sql_query);
497 // send to codemirror if possible
498 setQuery(data.sql_query);
501 if ('2' === data.action_bookmark) {
502 $('#id_bookmark option[value=\'' + data.id_bookmark + '\']').remove();
503 // if there are no bookmarked queries now (only the empty option),
504 // remove the bookmark section
505 if ($('#id_bookmark option').length === 1) {
506 $('#fieldsetBookmarkOptions').hide();
507 $('#fieldsetBookmarkOptionsFooter').hide();
511 $sqlqueryresultsouter
514 PMA_highlightSQL($sqlqueryresultsouter);
517 if (history && history.pushState) {
518 history.replaceState({
523 AJAX.handleMenu.replace(data._menu);
525 PMA_MicroHistory.menus.replace(data._menu);
526 PMA_MicroHistory.menus.add(data._menuHash, data._menu);
528 } else if (data._menuHash) {
529 if (! (history && history.pushState)) {
530 PMA_MicroHistory.menus.replace(PMA_MicroHistory.menus.get(data._menuHash));
535 PMA_commonParams.setAll(data._params);
538 if (typeof data.ajax_reload !== 'undefined') {
539 if (data.ajax_reload.reload) {
540 if (data.ajax_reload.table_name) {
541 PMA_commonParams.set('table', data.ajax_reload.table_name);
542 PMA_commonActions.refreshMain();
544 PMA_reloadNavigation();
547 } else if (typeof data.reload !== 'undefined') {
548 // this happens if a USE or DROP command was typed
549 PMA_commonActions.setDb(data.db);
553 url = 'table_sql.php';
558 url = 'server_sql.php';
560 PMA_commonActions.refreshMain(url, function () {
561 $('#sqlqueryresultsouter')
564 PMA_highlightSQL($('#sqlqueryresultsouter'));
568 $('.sqlqueryresults').trigger('makegrid').trigger('stickycolumns');
569 $('#togglequerybox').show();
572 if (typeof data.action_bookmark === 'undefined') {
573 if ($('#sqlqueryform input[name="retain_query_box"]').is(':checked') !== true) {
574 if ($('#togglequerybox').siblings(':visible').length > 0) {
575 $('#togglequerybox').trigger('click');
579 } else if (typeof data !== 'undefined' && data.success === false) {
580 // show an error message that stays on screen
581 $sqlqueryresultsouter
585 PMA_ajaxRemoveMessage($msgbox);
587 }); // end SQL Query submit
590 * Ajax Event handler for the display options
592 * @name displayOptionsForm_submit
594 $(document).on('submit', 'form[name=\'displayOptionsForm\'].ajax', function (event) {
595 event.preventDefault();
599 var $msgbox = PMA_ajaxShowMessage();
600 var argsep = PMA_commonParams.get('arg_separator');
601 $.post($form.attr('action'), $form.serialize() + argsep + 'ajax_request=true', function (data) {
602 PMA_ajaxRemoveMessage($msgbox);
603 var $sqlqueryresults = $form.parents('.sqlqueryresults');
607 .trigger('stickycolumns');
609 PMA_highlightSQL($sqlqueryresults);
611 }); // end displayOptionsForm handler
613 // Filter row handling. --STARTS--
614 $(document).on('keyup', '.filter_rows', function () {
615 var unique_id = $(this).data('for');
616 var $target_table = $('.table_results[data-uniqueId=\'' + unique_id + '\']');
617 var $header_cells = $target_table.find('th[data-column]');
618 var target_columns = Array();
619 // To handle colspan=4, in case of edit,copy etc options.
620 var dummy_th = ($('.edit_row_anchor').length !== 0 ?
621 '<th class="hide dummy_th"></th><th class="hide dummy_th"></th><th class="hide dummy_th"></th>'
623 // Selecting columns that will be considered for filtering and searching.
624 $header_cells.each(function () {
625 target_columns.push($.trim($(this).text()));
628 var phrase = $(this).val();
629 // Set same value to both Filter rows fields.
630 $('.filter_rows[data-for=\'' + unique_id + '\']').not(this).val(phrase);
632 $target_table.find('thead > tr').prepend(dummy_th);
633 $.uiTableFilter($target_table, phrase, target_columns);
634 $target_table.find('th.dummy_th').remove();
636 // Filter row handling. --ENDS--
638 // Prompt to confirm on Show All
639 $('body').on('click', '.navigation .showAllRows', function (e) {
641 var $form = $(this).parents('form');
643 if (! $(this).is(':checked')) { // already showing all rows
646 $form.PMA_confirm(PMA_messages.strShowAllRowsWarning, $form.attr('action'), function (url) {
651 function submitShowAllForm () {
652 var argsep = PMA_commonParams.get('arg_separator');
653 var submitData = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true';
654 PMA_ajaxShowMessage();
656 $.post($form.attr('action'), submitData, AJAX.responseHandler);
660 $('body').on('keyup', '#sqlqueryform', function () {
661 PMA_handleSimulateQueryButton();
665 * Ajax event handler for 'Simulate DML'.
667 $('body').on('click', '#simulate_dml', function () {
668 var $form = $('#sqlqueryform');
670 var delimiter = $('#id_sql_delimiter').val();
671 var db_name = $form.find('input[name="db"]').val();
673 if (codemirror_editor) {
674 query = codemirror_editor.getValue();
676 query = $('#sqlquery').val();
679 if (query.length === 0) {
680 alert(PMA_messages.strFormEmpty);
681 $('#sqlquery').focus();
685 var $msgbox = PMA_ajaxShowMessage();
688 url: $form.attr('action'),
690 server: PMA_commonParams.get('server'),
695 sql_delimiter: delimiter
697 success: function (response) {
698 PMA_ajaxRemoveMessage($msgbox);
699 if (response.success) {
700 var dialog_content = '<div class="preview_sql">';
701 if (response.sql_data) {
702 var len = response.sql_data.length;
703 for (var i = 0; i < len; i++) {
704 dialog_content += '<strong>' + PMA_messages.strSQLQuery +
705 '</strong>' + response.sql_data[i].sql_query +
706 PMA_messages.strMatchedRows +
707 ' <a href="' + response.sql_data[i].matched_rows_url +
708 '">' + response.sql_data[i].matched_rows + '</a><br>';
710 dialog_content += '<hr>';
714 dialog_content += response.message;
716 dialog_content += '</div>';
717 var $dialog_content = $(dialog_content);
718 var button_options = {};
719 button_options[PMA_messages.strClose] = function () {
720 $(this).dialog('close');
722 var $response_dialog = $('<div />').append($dialog_content).dialog({
726 buttons: button_options,
727 title: PMA_messages.strSimulateDML,
729 PMA_highlightSQL($(this));
736 PMA_ajaxShowMessage(response.error);
739 error: function (response) {
740 PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest);
746 * Handles multi submits of results browsing page such as edit, delete and export
748 $('body').on('click', 'form[name="resultsForm"].ajax button[name="submit_mult"], form[name="resultsForm"].ajax input[name="submit_mult"]', function (e) {
750 var $button = $(this);
751 var $form = $button.closest('form');
752 var argsep = PMA_commonParams.get('arg_separator');
753 var submitData = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true' + argsep + 'submit_mult=' + $button.val();
754 PMA_ajaxShowMessage();
756 $.post($form.attr('action'), submitData, AJAX.responseHandler);
761 * Starting from some th, change the class of all td under it.
762 * If isAddClass is specified, it will be used to determine whether to add or remove the class.
764 function PMA_changeClassForColumn ($this_th, newclass, isAddClass) {
765 // index 0 is the th containing the big T
766 var th_index = $this_th.index();
767 var has_big_t = $this_th.closest('tr').children(':first').hasClass('column_action');
768 // .eq() is zero-based
772 var $table = $this_th.parents('.table_results');
773 if (! $table.length) {
774 $table = $this_th.parents('table').siblings('.table_results');
776 var $tds = $table.find('tbody tr').find('td.data:eq(' + th_index + ')');
777 if (isAddClass === undefined) {
778 $tds.toggleClass(newclass);
780 $tds.toggleClass(newclass, isAddClass);
785 * Handles browse foreign values modal dialog
787 * @param object $this_a reference to the browse foreign value link
789 function browseForeignDialog ($this_a) {
790 var formId = '#browse_foreign_form';
791 var showAllId = '#foreign_showAll';
792 var tableId = '#browse_foreign_table';
793 var filterId = '#input_foreign_filter';
795 var argSep = PMA_commonParams.get('arg_separator');
796 var params = $this_a.getPostData();
797 params += argSep + 'ajax_request=true';
798 $.post($this_a.attr('href'), params, function (data) {
799 // Creates browse foreign value dialog
800 $dialog = $('<div>').append(data.message).dialog({
801 title: PMA_messages.strBrowseForeignValues,
802 width: Math.min($(window).width() - 100, 700),
803 maxHeight: $(window).height() - 100,
804 dialogClass: 'browse_foreign_modal',
805 close: function (ev, ui) {
806 // remove event handlers attached to elements related to dialog
807 $(tableId).off('click', 'td a.foreign_value');
808 $(formId).off('click', showAllId);
809 $(formId).off('submit');
810 // remove dialog itself
815 }).done(function () {
817 $(tableId).on('click', 'td a.foreign_value', function (e) {
819 var $input = $this_a.prev('input[type=text]');
820 // Check if input exists or get CEdit edit_box
821 if ($input.length === 0) {
822 $input = $this_a.closest('.edit_area').prev('.edit_box');
824 // Set selected value as input value
825 $input.val($(this).data('key'));
826 $dialog.dialog('close');
828 $(formId).on('click', showAllId, function () {
831 $(formId).on('submit', function (e) {
833 // if filter value is not equal to old value
834 // then reset page number to 1
835 if ($(filterId).val() !== $(filterId).data('old')) {
836 $(formId).find('select[name=pos]').val('0');
838 var postParams = $(this).serializeArray();
839 // if showAll button was clicked to submit form then
840 // add showAll button parameter to form
843 name: $(showAllId).attr('name'),
844 value: $(showAllId).val()
847 // updates values in dialog
848 $.post($(this).attr('action') + '?ajax_request=1', postParams, function (data) {
849 var $obj = $('<div>').html(data.message);
850 $(formId).html($obj.find(formId).html());
851 $(tableId).html($obj.find(tableId).html());
858 AJAX.registerOnload('sql.js', function () {
859 $('body').on('click', 'a.browse_foreign', function (e) {
861 browseForeignDialog($(this));
865 * vertical column highlighting in horizontal mode when hovering over the column header
867 $(document).on('mouseenter', 'th.column_heading.pointer', function (e) {
868 PMA_changeClassForColumn($(this), 'hover', true);
870 $(document).on('mouseleave', 'th.column_heading.pointer', function (e) {
871 PMA_changeClassForColumn($(this), 'hover', false);
875 * vertical column marking in horizontal mode when clicking the column header
877 $(document).on('click', 'th.column_heading.marker', function () {
878 PMA_changeClassForColumn($(this), 'marked');
882 * create resizable table
884 $('.sqlqueryresults').trigger('makegrid').trigger('stickycolumns');
890 function makeProfilingChart () {
891 if ($('#profilingchart').length === 0 ||
892 $('#profilingchart').html().length !== 0 ||
893 !$.jqplot || !$.jqplot.Highlighter || !$.jqplot.PieRenderer
899 $.each(JSON.parse($('#profilingChartData').html()), function (key, value) {
900 data.push([key, parseFloat(value)]);
903 // Remove chart and data divs contents
904 $('#profilingchart').html('').show();
905 $('#profilingChartData').html('');
907 PMA_createProfilingChart('profilingchart', data);
911 * initialize profiling data tables
913 function initProfilingTables () {
914 if (!$.tablesorter) {
918 $('#profiletable').tablesorter({
921 textExtraction: function (node) {
922 if (node.children.length > 0) {
923 return node.children[0].innerHTML;
925 return node.innerHTML;
930 $('#profilesummarytable').tablesorter({
933 textExtraction: function (node) {
934 if (node.children.length > 0) {
935 return node.children[0].innerHTML;
937 return node.innerHTML;
944 * Set position, left, top, width of sticky_columns div
946 function setStickyColumnsPosition ($sticky_columns, $table_results, position, top, left, margin_left) {
948 .css('position', position)
950 .css('left', left ? left : 'auto')
951 .css('margin-left', margin_left ? margin_left : '0px')
952 .css('width', $table_results.width());
956 * Initialize sticky columns
958 function initStickyColumns ($table_results) {
959 return $('<table class="sticky_columns"></table>')
960 .insertBefore($table_results)
961 .css('position', 'fixed')
962 .css('z-index', '99')
963 .css('width', $table_results.width())
964 .css('margin-left', $('#page_content').css('margin-left'))
965 .css('top', $('#floating_menubar').height())
966 .css('display', 'none');
970 * Arrange/Rearrange columns in sticky header
972 function rearrangeStickyColumns ($sticky_columns, $table_results) {
973 var $originalHeader = $table_results.find('thead');
974 var $originalColumns = $originalHeader.find('tr:first').children();
975 var $clonedHeader = $originalHeader.clone();
976 // clone width per cell
977 $clonedHeader.find('tr:first').children().width(function (i,val) {
978 var width = $originalColumns.eq(i).width();
979 var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
985 $sticky_columns.empty().append($clonedHeader);
989 * Adjust sticky columns on horizontal/vertical scroll for all tables
991 function handleAllStickyColumns () {
992 $('.sticky_columns').each(function () {
993 handleStickyColumns($(this), $(this).next('.table_results'));
998 * Adjust sticky columns on horizontal/vertical scroll
1000 function handleStickyColumns ($sticky_columns, $table_results) {
1001 var currentScrollX = $(window).scrollLeft();
1002 var windowOffset = $(window).scrollTop();
1003 var tableStartOffset = $table_results.offset().top;
1004 var tableEndOffset = tableStartOffset + $table_results.height();
1005 if (windowOffset >= tableStartOffset && windowOffset <= tableEndOffset) {
1006 // for horizontal scrolling
1007 if (prevScrollX !== currentScrollX) {
1008 prevScrollX = currentScrollX;
1009 setStickyColumnsPosition($sticky_columns, $table_results, 'absolute', $('#floating_menubar').height() + windowOffset - tableStartOffset);
1010 // for vertical scrolling
1012 setStickyColumnsPosition($sticky_columns, $table_results, 'fixed', $('#floating_menubar').height(), $('#pma_navigation').width() - currentScrollX, $('#page_content').css('margin-left'));
1014 $sticky_columns.show();
1016 $sticky_columns.hide();
1020 AJAX.registerOnload('sql.js', function () {
1021 makeProfilingChart();
1022 initProfilingTables();