1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * common functions used for communicating between main, navigation and querywindow
8 * holds the browser query window
13 * holds the query to be load from a new query window
15 var query_to_load = '';
18 * sets current selected db
20 * @param string db name
22 function setDb(new_db)
24 //alert('setDb(' + new_db + ')');
27 //alert( new_db + '(' + new_db.length + ') : ' + db );
32 // the db name as an id exists only when LeftFrameLight is false
33 if (window.frame_navigation.document.getElementById(db) == null) {
34 // happens when LeftFrameLight is true
35 // db is unknown, reload complete left frame
38 // happens when LeftFrameLight is false
39 unmarkDbTable(old_db);
43 // TODO: add code to expand db in lightview mode
45 // refresh querywindow
51 * sets current selected table (called from navigation.php)
53 * @param string table name
55 function setTable(new_table)
57 //alert('setTable(' + new_table + ')');
58 if (new_table != table) {
60 //alert( new_table + '(' + new_table.length + ') : ' + table );
64 if (window.frame_navigation.document.getElementById(db + '.' + table) == null
66 // table is unknown, reload complete left frame
70 // TODO: add code to expand table in lightview mode
72 // refresh querywindow
87 * @uses collation_connection
88 * @uses encodeURIComponent()
89 * @param string url name of page to be loaded
91 function refreshMain(url)
101 goTo(url + '?server=' + encodeURIComponent(server) +
102 '&token=' + encodeURIComponent(token) +
103 '&db=' + encodeURIComponent(db) +
104 '&table=' + encodeURIComponent(table) +
105 '&lang=' + encodeURIComponent(lang) +
106 '&collation_connection=' + encodeURIComponent(collation_connection),
111 * reloads navigation frame
119 * @uses collation_connection
120 * @uses encodeURIComponent()
121 * @param boolean force force reloading
123 function refreshNavigation(force)
125 // The goTo() function won't refresh in case the target
126 // url is the same as the url given as parameter, but sometimes
127 // we want to refresh anyway.
128 if (typeof force != undefined && force && window.parent && window.parent.frame_navigation) {
129 window.parent.frame_navigation.location.reload();
131 goTo('navigation.php?server=' + encodeURIComponent(server) +
132 '&token=' + encodeURIComponent(token) +
133 '&db=' + encodeURIComponent(db) +
134 '&table=' + encodeURIComponent(table) +
135 '&lang=' + encodeURIComponent(lang) +
136 '&collation_connection=' + encodeURIComponent(collation_connection)
141 function unmarkDbTable(db, table)
143 var element_reference = window.frame_navigation.document.getElementById(db);
144 if (element_reference != null) {
145 $(element_reference).parent().removeClass('marked');
148 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
149 if (element_reference != null) {
150 $(element_reference).parent().removeClass('marked');
154 function markDbTable(db, table)
156 var element_reference = window.frame_navigation.document.getElementById(db);
157 if (element_reference != null) {
158 $(element_reference).parent().addClass('marked');
160 element_reference.focus();
161 // opera marks the text, we dont want this ...
162 element_reference.blur();
165 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
166 if (element_reference != null) {
167 $(element_reference).parent().addClass('marked');
169 element_reference.focus();
170 // opera marks the text, we dont want this ...
171 element_reference.blur();
174 // return to main frame ...
175 window.frame_content.focus();
179 * sets current selected server, table and db (called from libraries/footer.inc.php)
181 function setAll( new_lang, new_collation_connection, new_server, new_db, new_table, new_token )
183 if (new_server != server || new_lang != lang
184 || new_collation_connection != collation_connection) {
185 // something important has changed
189 collation_connection = new_collation_connection;
193 } else if (new_db != db || new_table != table) {
194 // save new db and table
196 var old_table = table;
200 if (window.frame_navigation.document.getElementById(db) == null
201 && window.frame_navigation.document.getElementById(db + '.' + table) == null ) {
202 // table or db is unknown, reload complete left frame
205 unmarkDbTable(old_db, old_table);
206 markDbTable(db, table);
209 // TODO: add code to expand db in lightview mode
211 // refresh querywindow
212 refreshQuerywindow();
216 function reload_querywindow(db, table, sql_query)
218 if ( ! querywindow.closed && querywindow.location ) {
219 if ( ! querywindow.document.sqlform.LockFromUpdate
220 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
221 querywindow.document.getElementById('hiddenqueryform').db.value = db;
222 querywindow.document.getElementById('hiddenqueryform').table.value = table;
225 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
228 querywindow.document.getElementById('hiddenqueryform').submit();
234 * brings query window to front and inserts query to be edited
236 function focus_querywindow(sql_query)
238 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
239 if ( !querywindow || querywindow.closed || !querywindow.location) {
240 // we need first to open the window and cannot pass the query with it
241 // as we dont know if the query exceeds max url length
242 query_to_load = sql_query;
246 //var querywindow = querywindow;
247 if ( querywindow.document.getElementById('hiddenqueryform').querydisplay_tab != 'sql' ) {
248 querywindow.document.getElementById('hiddenqueryform').querydisplay_tab.value = "sql";
249 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
250 querywindow.document.getElementById('hiddenqueryform').submit();
260 * inserts query string into query window textarea
261 * called from script tag in querywindow
263 function insertQuery()
265 if (query_to_load != '' && querywindow.document && querywindow.document.getElementById && querywindow.document.getElementById('sqlquery')) {
266 querywindow.document.getElementById('sqlquery').value = query_to_load;
273 function open_querywindow( url )
276 url = 'querywindow.php?' + common_query + '&db=' + encodeURIComponent(db) + '&table=' + encodeURIComponent(table);
279 if (!querywindow.closed && querywindow.location) {
280 goTo( url, 'query' );
283 querywindow = window.open( url + '&init=1', '',
284 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
285 'scrollbars=yes,resizable=yes,' +
286 'width=' + querywindow_width + ',' +
287 'height=' + querywindow_height );
290 if ( ! querywindow.opener ) {
291 querywindow.opener = window.window;
294 if ( window.focus ) {
301 function refreshQuerywindow( url )
304 if ( ! querywindow.closed && querywindow.location ) {
305 if ( ! querywindow.document.sqlform.LockFromUpdate
306 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
307 open_querywindow( url )
313 * opens new url in target frame, with default being left frame
314 * valid is 'main' and 'querywindow' all others leads to 'left'
316 * @param string targeturl new url to load
317 * @param string target frame where to load the new url
319 function goTo(targeturl, target)
322 if ( target == 'main' ) {
323 target = window.frame_content;
324 } else if ( target == 'query' ) {
325 target = querywindow;
326 //return open_querywindow( targeturl );
327 } else if ( ! target ) {
328 target = window.frame_navigation;
332 if ( target.location.href == targeturl ) {
334 } else if ( target.location.href == pma_absolute_uri + targeturl ) {
338 if ( safari_browser ) {
339 target.location.href = targeturl;
341 target.location.replace(targeturl);
348 // opens selected db in main frame
349 function openDb(new_db)
351 //alert('opendb(' + new_db + ')');
354 refreshMain(opendb_url);
358 function updateTableTitle( table_link_id, new_title )
360 //alert('updateTableTitle');
361 if ( window.parent.frame_navigation.document && window.parent.frame_navigation.document.getElementById(table_link_id) ) {
362 var left = window.parent.frame_navigation.document;
364 var link = left.getElementById(table_link_id);
365 link.title = window.parent.pma_text_default_tab + ': ' + new_title;
367 var link = left.getElementById('quick_' + table_link_id);
368 link.title = window.parent.pma_text_left_default_tab + ': ' + new_title;