Add OK and Cancel button for grid editing
[phpmyadmin/arisferyanto.git] / js / tbl_select.js
blobfaffeefde45876f35598abca9f861ef0259afe66
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * @fileoverview JavaScript functions used on tbl_select.php
5 * @requires jQuery
6 * @requires js/functions.js
7 */
9 /**
10 * Ajax event handlers for this page
12 * Actions ajaxified here:
13 * Table Search
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
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
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']);
44 // avoid default click action
45 return false;
46 });
48 /**
49 * Ajax event handler for Table Search
51 * (see $GLOBALS['cfg']['AjaxEnable'])
52 * @uses PMA_ajaxShowMessage()
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']);
63 PMA_prepareForAjaxRequest($search_form);
65 $.post($search_form.attr('action'), $search_form.serialize(), function(response) {
66 if (typeof response == 'string') {
67 // found results
68 $("#sqlqueryresults").html(response);
69 $("#sqlqueryresults").trigger('makegrid');
70 $('#tbl_search_form')
71 // workaround for bug #3168569 - Issue on toggling the "Hide search criteria" in chrome.
72 .slideToggle()
73 .hide();
74 $('#togglesearchformlink')
75 // always start with the Show message
76 .text(PMA_messages['strShowSearchCriteria'])
77 $('#togglesearchformdiv')
78 // now it's time to show the div containing the link
79 .show();
80 // needed for the display options slider in the results
81 PMA_init_slider();
82 } else {
83 // error message (zero rows)
84 $("#sqlqueryresults").html(response['message']);
87 msgbox.clearQueue().fadeOut('medium', function() {
88 $(this).hide();
89 });
90 }) // end $.post()
93 // Following section is related to the 'function based search' for geometry data types.
94 // Initialy hide all the open_gis_editor spans
95 $('.open_search_gis_editor').hide();
97 $('.geom_func').bind('change', function() {
98 var $geomFuncSelector = $(this);
100 var binaryFunctions = [
101 'Contains',
102 'Crosses',
103 'Disjoint',
104 'Equals',
105 'Intersects',
106 'Overlaps',
107 'Touches',
108 'Within',
109 'MBRContains',
110 'MBRDisjoint',
111 'MBREquals',
112 'MBRIntersects',
113 'MBROverlaps',
114 'MBRTouches',
115 'MBRWithin',
116 'ST_Contains',
117 'ST_Crosses',
118 'ST_Disjoint',
119 'ST_Equals',
120 'ST_Intersects',
121 'ST_Overlaps',
122 'ST_Touches',
123 'ST_Within'
126 var tempArray = [
127 'Envelope',
128 'EndPoint',
129 'StartPoint',
130 'ExteriorRing',
131 'Centroid',
132 'PointOnSurface'
134 var outputGeomFunctions = binaryFunctions.concat(tempArray);
136 // If the chosen function takes two geomerty objects as parameters
137 var $operator = $geomFuncSelector.parents('tr').find('td:nth-child(5)').find('select');
138 if ($.inArray($geomFuncSelector.val(), binaryFunctions) >= 0){
139 $operator.attr('readonly', true);
140 } else {
141 $operator.attr('readonly', false);
144 // if the chosen function's output is a geometry, enable GIS editor
145 var $editorSpan = $geomFuncSelector.parents('tr').find('.open_search_gis_editor');
146 if ($.inArray($geomFuncSelector.val(), outputGeomFunctions) >= 0){
147 $editorSpan.show();
148 } else {
149 $editorSpan.hide();
154 $('.open_search_gis_editor').live('click', function(event) {
155 event.preventDefault();
157 var $span = $(this);
158 // Current value
159 var value = $span.parent('td').children("input[type='text']").val();
160 // Field name
161 var field = 'Parameter';
162 // Column type
163 var geom_func = $span.parents('tr').find('.geom_func').val();
164 if (geom_func == 'Envelope') {
165 var type = 'polygon';
166 } else if (geom_func == 'ExteriorRing') {
167 var type = 'linestring';
168 } else {
169 var type = 'point';
171 // Names of input field and null checkbox
172 var input_name = $span.parent('td').children("input[type='text']").attr('name');
173 //Token
174 var token = $("input[name='token']").val();
176 openGISEditor(value, field, type, input_name, token);
179 }, 'top.frame_content'); // end $(document).ready()