Speed up PMA_getImage()
[phpmyadmin/roccivic.git] / js / tbl_select.js
blobacd8b1f6ff9b3043204a43c92cde8b3b3e04b903
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() {
17     /**
18      * Set a parameter for all Ajax queries made on this page.  Don't let the
19      * web server serve cached pages
20      */
21     $.ajaxSetup({
22         cache: 'false'
23     });
25     /**
26      * Prepare a div containing a link, otherwise it's incorrectly displayed 
27      * after a couple of clicks
28      */
29     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
30      .insertAfter('#tbl_search_form')
31      // don't show it until we have results on-screen
32      .hide();
34     $('#togglesearchformlink')
35         .html(PMA_messages['strShowSearchCriteria'])
36         .bind('click', function() {
37             var $link = $(this);
38             $('#tbl_search_form').slideToggle();
39             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
40                 $link.text(PMA_messages['strShowSearchCriteria']);
41             } else {
42                 $link.text(PMA_messages['strHideSearchCriteria']);
43             }
44             // avoid default click action
45             return false;
46         });
48     /**
49      * Ajax event handler for Table Search
50      * 
51      * (see $GLOBALS['cfg']['AjaxEnable'])
52      * @uses    PMA_ajaxShowMessage()
53      */
54     $("#tbl_search_form.ajax").live('submit', function(event) {
55         // jQuery object to reuse
56         $search_form = $(this);
57         event.preventDefault();
59         // empty previous search results while we are waiting for new results
60         $("#sqlqueryresults").empty();
61         var $msgbox = PMA_ajaxShowMessage(PMA_messages['strSearching'], false);
63         PMA_prepareForAjaxRequest($search_form);
65         $.post($search_form.attr('action'), $search_form.serialize(), function(response) {
66             PMA_ajaxRemoveMessage($msgbox);
67             if (typeof response == 'string') {
68                 // found results
69                 $("#sqlqueryresults").html(response);
70                 $("#sqlqueryresults").trigger('makegrid');
71                 $('#tbl_search_form')
72                 // workaround for bug #3168569 - Issue on toggling the "Hide search criteria" in chrome.
73                  .slideToggle()    
74                  .hide();
75                 $('#togglesearchformlink')
76                  // always start with the Show message
77                  .text(PMA_messages['strShowSearchCriteria'])
78                 $('#togglesearchformdiv')
79                  // now it's time to show the div containing the link 
80                  .show();
81                  // needed for the display options slider in the results
82                  PMA_init_slider();
83             } else {
84                 // error message (zero rows)
85                 $("#sqlqueryresults").html(response['message']);
86             }
87         }) // end $.post()
88     })
90     // Following section is related to the 'function based search' for geometry data types.
91     // Initialy hide all the open_gis_editor spans
92     $('.open_search_gis_editor').hide();
94     $('.geom_func').bind('change', function() {
95         var $geomFuncSelector = $(this);
97         var binaryFunctions = [
98           'Contains',
99           'Crosses',
100           'Disjoint',
101           'Equals',
102           'Intersects',
103           'Overlaps',
104           'Touches',
105           'Within',
106           'MBRContains',
107           'MBRDisjoint',
108           'MBREquals',
109           'MBRIntersects',
110           'MBROverlaps',
111           'MBRTouches',
112           'MBRWithin',
113           'ST_Contains',
114           'ST_Crosses',
115           'ST_Disjoint',
116           'ST_Equals',
117           'ST_Intersects',
118           'ST_Overlaps',
119           'ST_Touches',
120           'ST_Within'
121         ];
123         var tempArray = [
124            'Envelope',
125            'EndPoint',
126            'StartPoint',
127            'ExteriorRing',
128            'Centroid',
129            'PointOnSurface'
130         ];
131         var outputGeomFunctions = binaryFunctions.concat(tempArray);
133         // If the chosen function takes two geomerty objects as parameters
134         var $operator = $geomFuncSelector.parents('tr').find('td:nth-child(5)').find('select');
135         if ($.inArray($geomFuncSelector.val(), binaryFunctions) >= 0){
136             $operator.attr('readonly', true);
137         } else {
138             $operator.attr('readonly', false);
139         }
141         // if the chosen function's output is a geometry, enable GIS editor
142         var $editorSpan = $geomFuncSelector.parents('tr').find('.open_search_gis_editor');
143         if ($.inArray($geomFuncSelector.val(), outputGeomFunctions) >= 0){
144             $editorSpan.show();
145         } else {
146             $editorSpan.hide();
147         }
148         
149     });
151     $('.open_search_gis_editor').live('click', function(event) {
152         event.preventDefault();
154         var $span = $(this);
155         // Current value
156         var value = $span.parent('td').children("input[type='text']").val();
157         // Field name
158         var field = 'Parameter';
159         // Column type
160         var geom_func = $span.parents('tr').find('.geom_func').val();
161         if (geom_func == 'Envelope') {
162             var type = 'polygon';
163         } else if (geom_func == 'ExteriorRing') {
164             var type = 'linestring';
165         } else {
166             var type = 'point';
167         }
168         // Names of input field and null checkbox
169         var input_name = $span.parent('td').children("input[type='text']").attr('name');
170         //Token
171         var token = $("input[name='token']").val();
173         openGISEditor();
174         if (!gisEditorLoaded) {
175             loadJSAndGISEditor(value, field, type, input_name, token);
176         } else {
177             loadGISEditor(value, field, type, input_name, token);
178         }
179     });
181 }, 'top.frame_content'); // end $(document).ready()