1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * Functionality for communicating with the querywindow
7 * Event handler for click on the open query window link
8 * in the top menu of the navigation panel
10 $('#pma_open_querywindow').click(function (event) {
11 event.preventDefault();
12 PMA_querywindow.focus();
17 * Holds common parameters such as server, db, table, etc
19 * The content for this is normally loaded from Header.class.php or
20 * Response.class.php and executed by ajax.js
22 var PMA_commonParams = (function () {
24 * @var hash params An associative array of key value pairs
28 // The returned object is the public part of the module
31 * Saves all the key value pair that
32 * are provided in the input array
34 * @param hash obj The input array
38 setAll: function (obj) {
40 var updateNavigation = false;
42 if (params[i] !== undefined && params[i] !== obj[i]) {
44 if (i == 'db' || i == 'table') {
45 updateNavigation = true;
50 if (updateNavigation) {
51 PMA_showCurrentNavigation();
54 PMA_querywindow.refresh();
58 * Retrieves a value given its key
59 * Returns empty string for undefined values
61 * @param string name The key
65 get: function (name) {
66 return params[name] || '';
69 * Saves a single key value pair
71 * @param string name The key
72 * @param string value The value
74 * @return self For chainability
76 set: function (name, value) {
77 var updateNavigation = false;
78 if (params[name] !== undefined && params[name] !== value) {
79 PMA_querywindow.refresh();
80 if (name == 'db' || name == 'table') {
81 updateNavigation = true;
85 if (updateNavigation) {
86 PMA_showCurrentNavigation();
91 * Returns the url query string using the saved parameters
95 getUrlQuery: function () {
97 '?%s&server=%s&db=%s&table=%s',
98 this.get('common_query'),
99 encodeURIComponent(this.get('server')),
100 encodeURIComponent(this.get('db')),
101 encodeURIComponent(this.get('table'))
108 * Holds common parameters such as server, db, table, etc
110 * The content for this is normally loaded from Header.class.php or
111 * Response.class.php and executed by ajax.js
113 var PMA_commonActions = {
115 * Saves the database name when it's changed
116 * and reloads the query window, if necessary
118 * @param string new_db The name of the new database
122 setDb: function (new_db) {
123 if (new_db != PMA_commonParams.get('db')) {
124 PMA_commonParams.setAll({'db': new_db, 'table': ''});
128 * Opens a database in the main part of the page
130 * @param string new_db The name of the new database
134 openDb: function (new_db) {
138 PMA_querywindow.refresh();
140 PMA_commonParams.get('opendb_url')
144 * Refreshes the main frame
146 * @param mixed url Undefined to refresh to the same page
147 * String to go to a different page, e.g: 'index.php'
151 refreshMain: function (url, callback) {
153 url = $('#selflink a').attr('href');
154 url = url.substring(0, url.indexOf('?'));
156 url += PMA_commonParams.getUrlQuery();
157 $('<a />', {href: url})
161 AJAX._callback = callback;
166 * Common functions used for communicating with the querywindow
168 var PMA_querywindow = (function ($, window) {
170 * @var Object querywindow Reference to the window
171 * object of the querywindow
174 var querywindow = {};
176 * @var string queryToLoad Stores the SQL query that is to be displayed
177 * in the querywindow when it is ready
180 var queryToLoad = '';
181 // The returned object is the public part of the module
184 * Opens the query window
186 * @param mixed url Undefined to open the default page
187 * String to go to a different
191 open: function (url, sql_query) {
193 url = 'querywindow.php' + PMA_commonParams.getUrlQuery();
196 url += '&sql_query=' + encodeURIComponent(sql_query);
199 if (! querywindow.closed && querywindow.location) {
200 var href = querywindow.location.href;
202 && href != PMA_commonParams.get('pma_absolute_uri') + url
204 if (PMA_commonParams.get('safari_browser')) {
205 querywindow.location.href = targeturl;
207 querywindow.location.replace(targeturl);
212 querywindow = window.open(
215 'toolbar=0,location=0,directories=0,status=1,'
216 + 'menubar=0,scrollbars=yes,resizable=yes,'
217 + 'width=' + PMA_commonParams.get('querywindow_width') + ','
218 + 'height=' + PMA_commonParams.get('querywindow_height')
221 if (! querywindow.opener) {
222 querywindow.opener = window.window;
229 * Opens, if necessary, focuses the query window
230 * and displays an SQL query.
232 * @param string sql_query The SQL query to display in
237 focus: function (sql_query) {
238 if (! querywindow || querywindow.closed || ! querywindow.location) {
239 // we need first to open the window and cannot pass the query with it
240 // as we dont know if the query exceeds max url length
241 queryToLoad = sql_query;
242 this.open(false, sql_query);
244 //var querywindow = querywindow;
245 var hiddenqueryform = querywindow
247 .getElementById('hiddenqueryform');
248 if (hiddenqueryform.querydisplay_tab != 'sql' ) {
249 hiddenqueryform.querydisplay_tab.value = "sql";
250 hiddenqueryform.sql_query.value = sql_query;
251 $(hiddenqueryform).addClass('disableAjax');
252 hiddenqueryform.submit();
260 * Refreshes the query window given a url
262 * @param string url Where to go to
266 refresh: function (url) {
267 if (! querywindow.closed && querywindow.location) {
268 var $form = $(querywindow.document).find('#sqlqueryform');
269 if ($form.find('#checkbox_lock:checked').length == 0) {
270 PMA_querywindow.open(url);
275 * Reloads the query window given the details
276 * of a db, a table and an sql_query
278 * @param string db The name of the database
279 * @param string table The name of the table
280 * @param string sql_query The SQL query to be displayed
284 reload: function (db, table, sql_query) {
285 if (! querywindow.closed && querywindow.location) {
286 var $form = $(querywindow.document).find('#sqlqueryform');
287 if ($form.find('#checkbox_lock:checked').length == 0) {
288 var $hiddenform = $(querywindow.document)
289 .find('#hiddenqueryform');
290 $hiddenform.find('input[name=db]').val(db);
291 $hiddenform.find('input[name=table]').val(table);
293 $hiddenform.find('input[name=sql_query]').val(sql_query);
295 $hiddenform.addClass('disableAjax').submit();