Translated using Weblate.
[phpmyadmin.git] / js / tbl_select.js
blob1067ab05bf48d91769183f624738ad12c3dd48ef
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview JavaScript functions used on tbl_select.php
4  *
5  * @requires    jQuery
6  * @requires    js/functions.js
7  */
9 /**
10  * Ajax event handlers for this page
11  *
12  * Actions ajaxified here:
13  * Table Search
14  */
15 $(document).ready(function() {
16     /**
17      * Prepare a div containing a link, otherwise it's incorrectly displayed 
18      * after a couple of clicks
19      */
20     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
21      .insertAfter('#tbl_search_form')
22      // don't show it until we have results on-screen
23      .hide();
25     $('#togglesearchformlink')
26         .html(PMA_messages['strShowSearchCriteria'])
27         .bind('click', function() {
28             var $link = $(this);
29             $('#tbl_search_form').slideToggle();
30             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
31                 $link.text(PMA_messages['strShowSearchCriteria']);
32             } else {
33                 $link.text(PMA_messages['strHideSearchCriteria']);
34             }
35             // avoid default click action
36             return false;
37         });
39     /**
40      * Ajax event handler for Table Search
41      * 
42      * (see $GLOBALS['cfg']['AjaxEnable'])
43      * @uses    PMA_ajaxShowMessage()
44      */
45     $("#tbl_search_form.ajax").live('submit', function(event) {
47         var unaryFunctions = [
48             'IS NULL', 
49             'IS NOT NULL',
50             "= ''",
51             "!= ''"];
53         // jQuery object to reuse
54         $search_form = $(this);
55         event.preventDefault();
57         // empty previous search results while we are waiting for new results
58         $("#sqlqueryresults").empty();
59         var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
61         PMA_prepareForAjaxRequest($search_form);
63         var values = {};
64         $search_form.find(':input').each(function() {
65             var $input = $(this);
66             if ($input.attr('type') == 'checkbox' || $input.attr('type') == 'radio') {
67                 if ($input.is(':checked')) {
68                     values[this.name] = $input.val();
69                 }
70             } else {
71                 values[this.name] = $input.val();
72             }
73         });
74         var columnCount = $('select[name="param[]"] option').length;
75         // Submit values only for the columns that have unary column operator or a search criteria
76         for (var a = 0; a < columnCount; a++) {
78             if ($.inArray(values['func[' + a + ']'], unaryFunctions) >= 0) {
79                 continue;
80             }
81             if (values['fields[' + a + ']'] == '' || values['fields[' + a + ']'] == null) {
82                 delete values['fields[' + a + ']'];
83                 delete values['func[' + a + ']'];
84                 delete values['names[' + a + ']'];
85                 delete values['types[' + a + ']'];
86                 delete values['collations[' + a + ']'];
87             }
88         }
89         // If all columns are selected, use a single parameter to indicate that
90         if (values['param[]'] != null) {
91             if (values['param[]'].length == columnCount) {
92                 delete values['param[]'];
93                 values['displayAllColumns'] = true;
94             }
95         } else {
96             values['displayAllColumns'] = true;
97         }
99         $.post($search_form.attr('action'), values, function(response) {
100             PMA_ajaxRemoveMessage($msgbox);
101             if (typeof response == 'string') {
102                 // found results
103                 $("#sqlqueryresults").html(response);
104                 $("#sqlqueryresults").trigger('makegrid');
105                 $('#tbl_search_form')
106                 // workaround for bug #3168569 - Issue on toggling the "Hide search criteria" in chrome.
107                  .slideToggle()    
108                  .hide();
109                 $('#togglesearchformlink')
110                  // always start with the Show message
111                  .text(PMA_messages['strShowSearchCriteria'])
112                 $('#togglesearchformdiv')
113                  // now it's time to show the div containing the link 
114                  .show();
115                  // needed for the display options slider in the results
116                  PMA_init_slider();
117             } else {
118                 // error message (zero rows)
119                 if (response.message != undefined) {
120                     $("#sqlqueryresults").html(response['message']);
121                 }
122                 // other error (syntax error?)
123                 if (response.error != undefined) {
124                     $("#sqlqueryresults").html(response['error']);
125                 }
126             }
127         }) // end $.post()
128     })
130     // Following section is related to the 'function based search' for geometry data types.
131     // Initialy hide all the open_gis_editor spans
132     $('.open_search_gis_editor').hide();
134     $('.geom_func').bind('change', function() {
135         var $geomFuncSelector = $(this);
137         var binaryFunctions = [
138           'Contains',
139           'Crosses',
140           'Disjoint',
141           'Equals',
142           'Intersects',
143           'Overlaps',
144           'Touches',
145           'Within',
146           'MBRContains',
147           'MBRDisjoint',
148           'MBREquals',
149           'MBRIntersects',
150           'MBROverlaps',
151           'MBRTouches',
152           'MBRWithin',
153           'ST_Contains',
154           'ST_Crosses',
155           'ST_Disjoint',
156           'ST_Equals',
157           'ST_Intersects',
158           'ST_Overlaps',
159           'ST_Touches',
160           'ST_Within'
161         ];
163         var tempArray = [
164            'Envelope',
165            'EndPoint',
166            'StartPoint',
167            'ExteriorRing',
168            'Centroid',
169            'PointOnSurface'
170         ];
171         var outputGeomFunctions = binaryFunctions.concat(tempArray);
173         // If the chosen function takes two geomerty objects as parameters
174         var $operator = $geomFuncSelector.parents('tr').find('td:nth-child(5)').find('select');
175         if ($.inArray($geomFuncSelector.val(), binaryFunctions) >= 0){
176             $operator.attr('readonly', true);
177         } else {
178             $operator.attr('readonly', false);
179         }
181         // if the chosen function's output is a geometry, enable GIS editor
182         var $editorSpan = $geomFuncSelector.parents('tr').find('.open_search_gis_editor');
183         if ($.inArray($geomFuncSelector.val(), outputGeomFunctions) >= 0){
184             $editorSpan.show();
185         } else {
186             $editorSpan.hide();
187         }
188         
189     });
191     $('.open_search_gis_editor').live('click', function(event) {
192         event.preventDefault();
194         var $span = $(this);
195         // Current value
196         var value = $span.parent('td').children("input[type='text']").val();
197         // Field name
198         var field = 'Parameter';
199         // Column type
200         var geom_func = $span.parents('tr').find('.geom_func').val();
201         if (geom_func == 'Envelope') {
202             var type = 'polygon';
203         } else if (geom_func == 'ExteriorRing') {
204             var type = 'linestring';
205         } else {
206             var type = 'point';
207         }
208         // Names of input field and null checkbox
209         var input_name = $span.parent('td').children("input[type='text']").attr('name');
210         //Token
211         var token = $("input[name='token']").val();
213         openGISEditor();
214         if (!gisEditorLoaded) {
215             loadJSAndGISEditor(value, field, type, input_name, token);
216         } else {
217             loadGISEditor(value, field, type, input_name, token);
218         }
219     });
221 }, 'top.frame_content'); // end $(document).ready()