/* vim: set expandtab sw=4 ts=4 sts=4: */ /** * @fileoverview functions used wherever an sql query form is used * * @requires jQuery * @requires js/functions.js * */ var $data_a; var prevScrollX = 0; /** * decode a string URL_encoded * * @param string str * @return string the URL-decoded string */ function PMA_urldecode (str) { if (typeof str !== 'undefined') { return decodeURIComponent(str.replace(/\+/g, '%20')); } } /** * endecode a string URL_decoded * * @param string str * @return string the URL-encoded string */ function PMA_urlencode (str) { if (typeof str !== 'undefined') { return encodeURIComponent(str).replace(/\%20/g, '+'); } } /** * Saves SQL query in local storage or cookie * * @param string SQL query * @return void */ function PMA_autosaveSQL (query) { if (query) { if (isStorageSupported('localStorage')) { window.localStorage.auto_saved_sql = query; } else { Cookies.set('auto_saved_sql', query); } } } /** * Saves SQL query with sort in local storage or cookie * * @param string SQL query * @return void */ function PMA_autosaveSQLSort (query) { if (query) { if (isStorageSupported('localStorage')) { window.localStorage.auto_saved_sql_sort = query; } else { Cookies.set('auto_saved_sql_sort', query); } } } /** * Clear saved SQL query with sort in local storage or cookie * * @return void */ function PMA_clearAutoSavedSQLSort () { if (isStorageSupported('localStorage')) { window.localStorage.removeItem('auto_saved_sql_sort'); } else { Cookies.set('auto_saved_sql_sort', ''); } } /** * Get the field name for the current field. Required to construct the query * for grid editing * * @param $table_results enclosing results table * @param $this_field jQuery object that points to the current field's tr */ function getFieldName ($table_results, $this_field) { var this_field_index = $this_field.index(); // ltr or rtl direction does not impact how the DOM was generated // check if the action column in the left exist var left_action_exist = !$table_results.find('th:first').hasClass('draggable'); // number of column span for checkbox and Actions var left_action_skip = left_action_exist ? $table_results.find('th:first').attr('colspan') - 1 : 0; // If this column was sorted, the text of the a element contains something // like 1 that is useful to indicate the order in case // of a sort on multiple columns; however, we dont want this as part // of the column name so we strip it ( .clone() to .end() ) var field_name = $table_results .find('thead') .find('th:eq(' + (this_field_index - left_action_skip) + ') a') .clone() // clone the element .children() // select all the children .remove() // remove all of them .end() // go back to the selected element .text(); // grab the text // happens when just one row (headings contain no a) if (field_name === '') { var $heading = $table_results.find('thead').find('th:eq(' + (this_field_index - left_action_skip) + ')').children('span'); // may contain column comment enclosed in a span - detach it temporarily to read the column name var $tempColComment = $heading.children().detach(); field_name = $heading.text(); // re-attach the column comment $heading.append($tempColComment); } field_name = $.trim(field_name); return field_name; } /** * Unbind all event handlers before tearing down a page */ AJAX.registerTeardown('sql.js', function () { $(document).off('click', 'a.delete_row.ajax'); $(document).off('submit', '.bookmarkQueryForm'); $('input#bkm_label').off('input'); $(document).off('makegrid', '.sqlqueryresults'); $(document).off('stickycolumns', '.sqlqueryresults'); $('#togglequerybox').off('click'); $(document).off('click', '#button_submit_query'); $(document).off('change', '#id_bookmark'); $('input[name=\'bookmark_variable\']').off('keypress'); $(document).off('submit', '#sqlqueryform.ajax'); $(document).off('click', 'input[name=navig].ajax'); $(document).off('submit', 'form[name=\'displayOptionsForm\'].ajax'); $(document).off('mouseenter', 'th.column_heading.pointer'); $(document).off('mouseleave', 'th.column_heading.pointer'); $(document).off('click', 'th.column_heading.marker'); $(window).off('scroll'); $(document).off('keyup', '.filter_rows'); $(document).off('click', '#printView'); if (codemirror_editor) { codemirror_editor.off('change'); } else { $('#sqlquery').off('input propertychange'); } $('body').off('click', '.navigation .showAllRows'); $('body').off('click', 'a.browse_foreign'); $('body').off('click', '#simulate_dml'); $('body').off('keyup', '#sqlqueryform'); $('body').off('click', 'form[name="resultsForm"].ajax button[name="submit_mult"], form[name="resultsForm"].ajax input[name="submit_mult"]'); }); /** * @description
Ajax scripts for sql and browse pages
* * Actions ajaxified here: *