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) {
23 //alert('setDb(' + new_db + ')');
26 //alert( new_db + '(' + new_db.length + ') : ' + db );
31 // the db name as an id exists only when LeftFrameLight is false
32 if (window.frame_navigation.document.getElementById(db) == null) {
33 // happens when LeftFrameLight is true
34 // db is unknown, reload complete left frame
37 // happens when LeftFrameLight is false
38 unmarkDbTable(old_db);
42 // TODO: add code to expand db in lightview mode
44 // refresh querywindow
50 * sets current selected table (called from navigation.php)
52 * @param string table name
54 function setTable(new_table) {
55 //alert('setTable(' + new_table + ')');
56 if (new_table != table) {
58 //alert( new_table + '(' + new_table.length + ') : ' + table );
62 if (window.frame_navigation.document.getElementById(db + '.' + table) == null
64 // table is unknown, reload complete left frame
68 // TODO: add code to expand table in lightview mode
70 // refresh querywindow
85 * @uses collation_connection
86 * @uses encodeURIComponent()
87 * @param string url name of page to be loaded
89 function refreshMain(url) {
98 goTo(url + '?server=' + encodeURIComponent(server) +
99 '&token=' + encodeURIComponent(token) +
100 '&db=' + encodeURIComponent(db) +
101 '&table=' + encodeURIComponent(table) +
102 '&lang=' + encodeURIComponent(lang) +
103 '&collation_connection=' + encodeURIComponent(collation_connection),
108 * reloads navigation frame
116 * @uses collation_connection
117 * @uses encodeURIComponent()
118 * @param boolean force force reloading
120 function refreshNavigation(force) {
121 // The goTo() function won't refresh in case the target
122 // url is the same as the url given as parameter, but sometimes
123 // we want to refresh anyway.
124 if (typeof force != undefined && force && window.parent && window.parent.frame_navigation) {
125 window.parent.frame_navigation.location.reload();
127 goTo('navigation.php?server=' + encodeURIComponent(server) +
128 '&token=' + encodeURIComponent(token) +
129 '&db=' + encodeURIComponent(db) +
130 '&table=' + encodeURIComponent(table) +
131 '&lang=' + encodeURIComponent(lang) +
132 '&collation_connection=' + encodeURIComponent(collation_connection)
137 function unmarkDbTable(db, table)
139 var element_reference = window.frame_navigation.document.getElementById(db);
140 if (element_reference != null) {
141 $(element_reference).parent().removeClass('marked');
144 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
145 if (element_reference != null) {
146 $(element_reference).parent().removeClass('marked');
150 function markDbTable(db, table)
152 var element_reference = window.frame_navigation.document.getElementById(db);
153 if (element_reference != null) {
154 $(element_reference).parent().addClass('marked');
156 element_reference.focus();
157 // opera marks the text, we dont want this ...
158 element_reference.blur();
161 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
162 if (element_reference != null) {
163 $(element_reference).parent().addClass('marked');
165 element_reference.focus();
166 // opera marks the text, we dont want this ...
167 element_reference.blur();
170 // return to main frame ...
171 window.frame_content.focus();
175 * sets current selected server, table and db (called from libraries/footer.inc.php)
177 function setAll( new_lang, new_collation_connection, new_server, new_db, new_table, new_token ) {
178 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ', ' + new_token + ' )');
179 if (new_server != server || new_lang != lang
180 || new_collation_connection != collation_connection) {
181 // something important has changed
185 collation_connection = new_collation_connection;
189 } else if (new_db != db || new_table != table) {
190 // save new db and table
192 var old_table = table;
196 if (window.frame_navigation.document.getElementById(db) == null
197 && window.frame_navigation.document.getElementById(db + '.' + table) == null ) {
198 // table or db is unknown, reload complete left frame
201 unmarkDbTable(old_db, old_table);
202 markDbTable(db, table);
205 // TODO: add code to expand db in lightview mode
207 // refresh querywindow
208 refreshQuerywindow();
212 function reload_querywindow(db, table, sql_query)
214 if ( ! querywindow.closed && querywindow.location ) {
215 if ( ! querywindow.document.sqlform.LockFromUpdate
216 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
217 querywindow.document.getElementById('hiddenqueryform').db.value = db;
218 querywindow.document.getElementById('hiddenqueryform').table.value = table;
221 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
224 querywindow.document.getElementById('hiddenqueryform').submit();
230 * brings query window to front and inserts query to be edited
232 function focus_querywindow(sql_query)
234 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
235 if ( !querywindow || querywindow.closed || !querywindow.location) {
236 // we need first to open the window and cannot pass the query with it
237 // as we dont know if the query exceeds max url length
238 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
239 query_to_load = sql_query;
243 //var querywindow = querywindow;
244 if ( querywindow.document.getElementById('hiddenqueryform').querydisplay_tab != 'sql' ) {
245 querywindow.document.getElementById('hiddenqueryform').querydisplay_tab.value = "sql";
246 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
247 querywindow.document.getElementById('hiddenqueryform').submit();
257 * inserts query string into query window textarea
258 * called from script tag in querywindow
260 function insertQuery() {
261 if (query_to_load != '' && querywindow.document && querywindow.document.getElementById && querywindow.document.getElementById('sqlquery')) {
262 querywindow.document.getElementById('sqlquery').value = query_to_load;
269 function open_querywindow( url ) {
271 url = 'querywindow.php?' + common_query + '&db=' + encodeURIComponent(db) + '&table=' + encodeURIComponent(table);
274 if (!querywindow.closed && querywindow.location) {
275 goTo( url, 'query' );
278 querywindow = window.open( url + '&init=1', '',
279 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
280 'scrollbars=yes,resizable=yes,' +
281 'width=' + querywindow_width + ',' +
282 'height=' + querywindow_height );
285 if ( ! querywindow.opener ) {
286 querywindow.opener = window.window;
289 if ( window.focus ) {
296 function refreshQuerywindow( url ) {
298 if ( ! querywindow.closed && querywindow.location ) {
299 if ( ! querywindow.document.sqlform.LockFromUpdate
300 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
301 open_querywindow( url )
307 * opens new url in target frame, with default being left frame
308 * valid is 'main' and 'querywindow' all others leads to 'left'
310 * @param string targeturl new url to load
311 * @param string target frame where to load the new url
313 function goTo(targeturl, target) {
315 if ( target == 'main' ) {
316 target = window.frame_content;
317 } else if ( target == 'query' ) {
318 target = querywindow;
319 //return open_querywindow( targeturl );
320 } else if ( ! target ) {
321 target = window.frame_navigation;
325 if ( target.location.href == targeturl ) {
327 } else if ( target.location.href == pma_absolute_uri + targeturl ) {
331 if ( safari_browser ) {
332 target.location.href = targeturl;
334 target.location.replace(targeturl);
341 // opens selected db in main frame
342 function openDb(new_db) {
343 //alert('opendb(' + new_db + ')');
346 refreshMain(opendb_url);
350 function updateTableTitle( table_link_id, new_title ) {
351 //alert('updateTableTitle');
352 if ( window.parent.frame_navigation.document && window.parent.frame_navigation.document.getElementById(table_link_id) ) {
353 var left = window.parent.frame_navigation.document;
355 var link = left.getElementById(table_link_id);
356 link.title = window.parent.pma_text_default_tab + ': ' + new_title;
358 var link = left.getElementById('quick_' + table_link_id);
359 link.title = window.parent.pma_text_left_default_tab + ': ' + new_title;