Advisor: don't run 'MyISAM concurrent inserts' on Drizzle
[phpmyadmin.git] / js / common.js
blob47fd3bf4d551d22616cc84948a5f640ca365e0bb
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * common functions used for communicating between main, navigation and querywindow
4  *
5  */
7 /**
8  * holds the browser query window
9  */
10 var querywindow = '';
12 /**
13  * holds the query to be load from a new query window
14  */
15 var query_to_load = '';
17 /**
18  * sets current selected db
19  *
20  * @param    string    db name
21  */
22 function setDb(new_db)
24     //alert('setDb(' + new_db + ')');
25     if (new_db != db) {
26         // db has changed
27         //alert( new_db + '(' + new_db.length + ') : ' + db );
29         var old_db = db;
30         db = new_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
36             refreshNavigation();
37         } else {
38             // happens when LeftFrameLight is false
39             unmarkDbTable(old_db);
40             markDbTable(db);
41         }
43         // TODO: add code to expand db in lightview mode
45         // refresh querywindow
46         refreshQuerywindow();
47     }
50 /**
51  * sets current selected table (called from navigation.php)
52  *
53  * @param    string    table name
54  */
55 function setTable(new_table)
57     //alert('setTable(' + new_table + ')');
58     if (new_table != table) {
59         // table has changed
60         //alert( new_table + '(' + new_table.length + ') : ' + table );
62         table = new_table;
64         if (window.frame_navigation.document.getElementById(db + '.' + table) == null
65          && table != '') {
66             // table is unknown, reload complete left frame
67             refreshNavigation();
69         }
70         // TODO: add code to expand table in lightview mode
72         // refresh querywindow
73         refreshQuerywindow();
74     }
77 /**
78  * reloads main frame
79  *
80  * @uses     goTo()
81  * @uses     opendb_url
82  * @uses     token
83  * @uses     db
84  * @uses     server
85  * @uses     table
86  * @uses     lang
87  * @uses    collation_connection
88  * @uses    encodeURIComponent()
89  * @param    string    url    name of page to be loaded
90  */
91 function refreshMain(url)
93     if (! url) {
94         if (db) {
95             url = opendb_url;
96         } else {
97             url = 'main.php';
98         }
99     }
100     //alert(db);
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),
107         'main');
111  * reloads navigation frame
113  * @uses     goTo()
114  * @uses     token
115  * @uses     db
116  * @uses     server
117  * @uses     table
118  * @uses     lang
119  * @uses    collation_connection
120  * @uses    encodeURIComponent()
121  * @param    boolean    force   force reloading
122  */
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();
130     } else {
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)
137             );
138     }
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');
146     }
148     element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
149     if (element_reference != null) {
150         $(element_reference).parent().removeClass('marked');
151     }
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');
159         // scrolldown
160         element_reference.focus();
161         // opera marks the text, we dont want this ...
162         element_reference.blur();
163     }
165     element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
166     if (element_reference != null) {
167         $(element_reference).parent().addClass('marked');
168         // scrolldown
169         element_reference.focus();
170         // opera marks the text, we dont want this ...
171         element_reference.blur();
172     }
174     // return to main frame ...
175     window.frame_content.focus();
179  * sets current selected server, table and db (called from libraries/footer.inc.php)
180  */
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
186         server = new_server;
187         db     = new_db;
188         table  = new_table;
189         collation_connection  = new_collation_connection;
190         lang  = new_lang;
191         token  = new_token;
192         refreshNavigation();
193     } else if (new_db != db || new_table != table) {
194         // save new db and table
195         var old_db    = db;
196         var old_table = table;
197         db        = new_db;
198         table     = new_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
203             refreshNavigation();
204         } else {
205             unmarkDbTable(old_db, old_table);
206             markDbTable(db, table);
207         }
209         // TODO: add code to expand db in lightview mode
211         // refresh querywindow
212         refreshQuerywindow();
213     }
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;
224             if (sql_query) {
225                 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
226             }
228             querywindow.document.getElementById('hiddenqueryform').submit();
229         }
230     }
234  * brings query window to front and inserts query to be edited
235  */
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;
243         open_querywindow();
244         insertQuery(0);
245     } else {
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();
251             querywindow.focus();
252         } else {
253             querywindow.focus();
254         }
255     }
256     return true;
260  * inserts query string into query window textarea
261  * called from script tag in querywindow
262  */
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;
267         query_to_load = '';
268         return true;
269     }
270     return false;
273 function open_querywindow( url )
275     if ( ! url ) {
276         url = 'querywindow.php?' + common_query + '&db=' + encodeURIComponent(db) + '&table=' + encodeURIComponent(table);
277     }
279     if (!querywindow.closed && querywindow.location) {
280         goTo( url, 'query' );
281         querywindow.focus();
282     } else {
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 );
288     }
290     if ( ! querywindow.opener ) {
291        querywindow.opener = window.window;
292     }
294     if ( window.focus ) {
295         querywindow.focus();
296     }
298     return true;
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 )
308         }
309     }
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
318  */
319 function goTo(targeturl, target)
321     //alert(targeturl);
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;
329     }
331     if ( target ) {
332         if ( target.location.href == targeturl ) {
333             return true;
334         } else if ( target.location.href == pma_absolute_uri + targeturl ) {
335             return true;
336         }
338         if ( safari_browser ) {
339             target.location.href = targeturl;
340         } else {
341             target.location.replace(targeturl);
342         }
343     }
345     return true;
348 // opens selected db in main frame
349 function openDb(new_db)
351     //alert('opendb(' +  new_db + ')');
352     setDb(new_db);
353     setTable('');
354     refreshMain(opendb_url);
355     return true;
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;
370         return true;
371     }
373     return false;