1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * @fileoverview JavaScript functions used on tbl_select.php
6 * @requires js/functions.js
10 * Ajax event handlers for this page
12 * Actions ajaxified here:
17 * Unbind all event handlers before tearing down a page
19 AJAX.registerTeardown('tbl_select.js', function() {
20 $('#togglesearchformlink').unbind('click');
21 $("#tbl_search_form.ajax").die('submit');
22 $('select.geom_func').unbind('change');
23 $('span.open_search_gis_editor').die('click');
26 AJAX.registerOnload('tbl_select.js', function() {
28 * Prepare a div containing a link, otherwise it's incorrectly displayed
29 * after a couple of clicks
31 $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
32 .insertAfter('#tbl_search_form')
33 // don't show it until we have results on-screen
36 $('#togglesearchformlink')
37 .html(PMA_messages['strShowSearchCriteria'])
38 .bind('click', function() {
40 $('#tbl_search_form').slideToggle();
41 if ($link.text() == PMA_messages['strHideSearchCriteria']) {
42 $link.text(PMA_messages['strShowSearchCriteria']);
44 $link.text(PMA_messages['strHideSearchCriteria']);
46 // avoid default click action
51 * Ajax event handler for Table Search
53 $("#tbl_search_form.ajax").live('submit', function(event) {
54 var unaryFunctions = [
60 // jQuery object to reuse
61 $search_form = $(this);
62 event.preventDefault();
64 // empty previous search results while we are waiting for new results
65 $("#sqlqueryresults").empty();
66 var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
68 PMA_prepareForAjaxRequest($search_form);
71 $search_form.find(':input').each(function() {
73 if ($input.attr('type') == 'checkbox' || $input.attr('type') == 'radio') {
74 if ($input.is(':checked')) {
75 values[this.name] = $input.val();
78 values[this.name] = $input.val();
81 var columnCount = $('select[name="columnsToDisplay[]"] option').length;
82 // Submit values only for the columns that have unary column operator or a search criteria
83 for (var a = 0; a < columnCount; a++) {
84 if ($.inArray(values['criteriaColumnOperators[' + a + ']'], unaryFunctions) >= 0) {
88 if (values['criteriaValues[' + a + ']'] == '' || values['criteriaValues[' + a + ']'] == null) {
89 delete values['criteriaValues[' + a + ']'];
90 delete values['criteriaColumnOperators[' + a + ']'];
91 delete values['criteriaColumnNames[' + a + ']'];
92 delete values['criteriaColumnTypes[' + a + ']'];
93 delete values['criteriaColumnCollations[' + a + ']'];
96 // If all columns are selected, use a single parameter to indicate that
97 if (values['columnsToDisplay[]'] != null) {
98 if (values['columnsToDisplay[]'].length == columnCount) {
99 delete values['columnsToDisplay[]'];
100 values['displayAllColumns'] = true;
103 values['displayAllColumns'] = true;
106 $.post($search_form.attr('action'), values, function(data) {
107 PMA_ajaxRemoveMessage($msgbox);
108 if (data.success == true) {
109 if (data.sql_query != null) { // zero rows
110 $("#sqlqueryresults").html(data.sql_query);
111 } else { // results found
112 $("#sqlqueryresults").html(data.message);
113 $("#sqlqueryresults").trigger('makegrid');
115 $('#tbl_search_form')
116 // workaround for bug #3168569 - Issue on toggling the "Hide search criteria" in chrome.
119 $('#togglesearchformlink')
120 // always start with the Show message
121 .text(PMA_messages['strShowSearchCriteria']);
122 $('#togglesearchformdiv')
123 // now it's time to show the div containing the link
125 // needed for the display options slider in the results
128 $("#sqlqueryresults").html(data.error);
133 // Following section is related to the 'function based search' for geometry data types.
134 // Initialy hide all the open_gis_editor spans
135 $('span.open_search_gis_editor').hide();
137 $('select.geom_func').bind('change', function() {
138 var $geomFuncSelector = $(this);
140 var binaryFunctions = [
174 var outputGeomFunctions = binaryFunctions.concat(tempArray);
176 // If the chosen function takes two geometry objects as parameters
177 var $operator = $geomFuncSelector.parents('tr').find('td:nth-child(5)').find('select');
178 if ($.inArray($geomFuncSelector.val(), binaryFunctions) >= 0){
179 $operator.prop('readonly', true);
181 $operator.prop('readonly', false);
184 // if the chosen function's output is a geometry, enable GIS editor
185 var $editorSpan = $geomFuncSelector.parents('tr').find('span.open_search_gis_editor');
186 if ($.inArray($geomFuncSelector.val(), outputGeomFunctions) >= 0){
194 $('span.open_search_gis_editor').live('click', function(event) {
195 event.preventDefault();
199 var value = $span.parent('td').children("input[type='text']").val();
201 var field = 'Parameter';
203 var geom_func = $span.parents('tr').find('.geom_func').val();
204 if (geom_func == 'Envelope') {
205 var type = 'polygon';
206 } else if (geom_func == 'ExteriorRing') {
207 var type = 'linestring';
211 // Names of input field and null checkbox
212 var input_name = $span.parent('td').children("input[type='text']").attr('name');
214 var token = $("input[name='token']").val();
217 if (!gisEditorLoaded) {
218 loadJSAndGISEditor(value, field, type, input_name, token);
220 loadGISEditor(value, field, type, input_name, token);