Translation update done using Pootle.
[phpmyadmin.git] / js / tbl_select.js
blobba144959a41c269700586f5aeba4139e549a1f62
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) {
46         // jQuery object to reuse
47         $search_form = $(this);
48         event.preventDefault();
50         // empty previous search results while we are waiting for new results
51         $("#sqlqueryresults").empty();
52         var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
54         PMA_prepareForAjaxRequest($search_form);
56         $.post($search_form.attr('action'), $search_form.serialize(), function(response) {
57             PMA_ajaxRemoveMessage($msgbox);
58             if (typeof response == 'string') {
59                 // found results
60                 $("#sqlqueryresults").html(response);
61                 $("#sqlqueryresults").trigger('makegrid');
62                 $('#tbl_search_form')
63                 // workaround for bug #3168569 - Issue on toggling the "Hide search criteria" in chrome.
64                  .slideToggle()    
65                  .hide();
66                 $('#togglesearchformlink')
67                  // always start with the Show message
68                  .text(PMA_messages['strShowSearchCriteria'])
69                 $('#togglesearchformdiv')
70                  // now it's time to show the div containing the link 
71                  .show();
72                  // needed for the display options slider in the results
73                  PMA_init_slider();
74             } else {
75                 // error message (zero rows)
76                 if (response.message != undefined) {
77                     $("#sqlqueryresults").html(response['message']);
78                 }
79                 // other error (syntax error?)
80                 if (response.error != undefined) {
81                     $("#sqlqueryresults").html(response['error']);
82                 }
83             }
84         }) // end $.post()
85     })
87     // Following section is related to the 'function based search' for geometry data types.
88     // Initialy hide all the open_gis_editor spans
89     $('.open_search_gis_editor').hide();
91     $('.geom_func').bind('change', function() {
92         var $geomFuncSelector = $(this);
94         var binaryFunctions = [
95           'Contains',
96           'Crosses',
97           'Disjoint',
98           'Equals',
99           'Intersects',
100           'Overlaps',
101           'Touches',
102           'Within',
103           'MBRContains',
104           'MBRDisjoint',
105           'MBREquals',
106           'MBRIntersects',
107           'MBROverlaps',
108           'MBRTouches',
109           'MBRWithin',
110           'ST_Contains',
111           'ST_Crosses',
112           'ST_Disjoint',
113           'ST_Equals',
114           'ST_Intersects',
115           'ST_Overlaps',
116           'ST_Touches',
117           'ST_Within'
118         ];
120         var tempArray = [
121            'Envelope',
122            'EndPoint',
123            'StartPoint',
124            'ExteriorRing',
125            'Centroid',
126            'PointOnSurface'
127         ];
128         var outputGeomFunctions = binaryFunctions.concat(tempArray);
130         // If the chosen function takes two geomerty objects as parameters
131         var $operator = $geomFuncSelector.parents('tr').find('td:nth-child(5)').find('select');
132         if ($.inArray($geomFuncSelector.val(), binaryFunctions) >= 0){
133             $operator.attr('readonly', true);
134         } else {
135             $operator.attr('readonly', false);
136         }
138         // if the chosen function's output is a geometry, enable GIS editor
139         var $editorSpan = $geomFuncSelector.parents('tr').find('.open_search_gis_editor');
140         if ($.inArray($geomFuncSelector.val(), outputGeomFunctions) >= 0){
141             $editorSpan.show();
142         } else {
143             $editorSpan.hide();
144         }
145         
146     });
148     $('.open_search_gis_editor').live('click', function(event) {
149         event.preventDefault();
151         var $span = $(this);
152         // Current value
153         var value = $span.parent('td').children("input[type='text']").val();
154         // Field name
155         var field = 'Parameter';
156         // Column type
157         var geom_func = $span.parents('tr').find('.geom_func').val();
158         if (geom_func == 'Envelope') {
159             var type = 'polygon';
160         } else if (geom_func == 'ExteriorRing') {
161             var type = 'linestring';
162         } else {
163             var type = 'point';
164         }
165         // Names of input field and null checkbox
166         var input_name = $span.parent('td').children("input[type='text']").attr('name');
167         //Token
168         var token = $("input[name='token']").val();
170         openGISEditor();
171         if (!gisEditorLoaded) {
172             loadJSAndGISEditor(value, field, type, input_name, token);
173         } else {
174             loadGISEditor(value, field, type, input_name, token);
175         }
176     });
178 }, 'top.frame_content'); // end $(document).ready()