Romanian update
[phpmyadmin/arisferyanto.git] / js / querywindow.js
bloba07d16794e07e22e8420131bafb2b1ae72ef8f62
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * functions used by and for querywindow
5 * @version $Id$
6 */
8 /**
9 * holds the browser query window
11 var querywindow = '';
13 /**
14 * holds the query to be load from a new query window
16 var query_to_load = '';
18 /**
19 * sets current selected db
21 * @param string db name
23 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 if (window.frame_navigation.document.getElementById(db) == null) {
33 // db is unknown, reload complete left frame
34 refreshNavigation();
35 } else {
36 unmarkDbTable(old_db);
37 markDbTable(db);
40 // TODO: add code to expand db in lightview mode
42 // refresh querywindow
43 refreshQuerywindow();
47 /**
48 * sets current selected table (called from navigation.php)
50 * @param string table name
52 function setTable(new_table) {
53 //alert('setTable(' + new_table + ')');
54 if (new_table != table) {
55 // table has changed
56 //alert( new_table + '(' + new_table.length + ') : ' + table );
58 table = new_table;
60 if (window.frame_navigation.document.getElementById(db + '.' + table) == null
61 && table != '') {
62 // table is unknown, reload complete left frame
63 refreshNavigation();
66 // TODO: add code to expand table in lightview mode
68 // refresh querywindow
69 refreshQuerywindow();
73 /**
74 * reloads mian frame
76 * @uses goTo()
77 * @uses opendb_url
78 * @uses db
79 * @uses server
80 * @uses table
81 * @uses lang
82 * @uses collation_connection
83 * @uses encodeURIComponent()
84 * @param string url name of page to be loaded
86 function refreshMain(url) {
87 if (! url) {
88 if (db) {
89 url = opendb_url;
90 } else {
91 url = 'main.php';
94 goTo(url + '?server=' + encodeURIComponent(server) +
95 '&db=' + encodeURIComponent(db) +
96 '&table=' + encodeURIComponent(table) +
97 '&lang=' + encodeURIComponent(lang) +
98 '&collation_connection=' + encodeURIComponent(collation_connection),
99 'main');
103 * reloads navigation frame
105 * @uses goTo()
106 * @uses db
107 * @uses server
108 * @uses table
109 * @uses lang
110 * @uses collation_connection
111 * @uses encodeURIComponent()
113 function refreshNavigation() {
114 goTo('navigation.php?server=' + encodeURIComponent(server) +
115 '&db=' + encodeURIComponent(db) +
116 '&table=' + encodeURIComponent(table) +
117 '&lang=' + encodeURIComponent(lang) +
118 '&collation_connection=' + encodeURIComponent(collation_connection)
123 * adds class to element
125 function addClass(element, classname)
127 if (element != null) {
128 element.className += ' ' + classname;
129 //alert('set class: ' + classname + ', now: ' + element.className);
134 * removes class from element
136 function removeClass(element, classname)
138 if (element != null) {
139 element.className = element.className.replace(' ' + classname, '');
140 // if there is no other class anem there is no leading space
141 element.className = element.className.replace(classname, '');
142 //alert('removed class: ' + classname + ', now: ' + element.className);
146 function unmarkDbTable(db, table)
148 var element_reference = window.frame_navigation.document.getElementById(db);
149 if (element_reference != null) {
150 //alert('remove from: ' + db);
151 removeClass(element_reference.parentNode, 'marked');
154 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
155 if (element_reference != null) {
156 //alert('remove from: ' + db + '.' + table);
157 removeClass(element_reference.parentNode, 'marked');
161 function markDbTable(db, table)
163 var element_reference = window.frame_navigation.document.getElementById(db);
164 if (element_reference != null) {
165 addClass(element_reference.parentNode, 'marked');
166 // scrolldown
167 element_reference.focus();
168 // opera marks the text, we dont want this ...
169 element_reference.blur();
172 element_reference = window.frame_navigation.document.getElementById(db + '.' + table);
173 if (element_reference != null) {
174 addClass(element_reference.parentNode, 'marked');
175 // scrolldown
176 element_reference.focus();
177 // opera marks the text, we dont want this ...
178 element_reference.blur();
181 // return to main frame ...
182 window.frame_content.focus();
186 * sets current selected server, table and db (called from libraries/footer.inc.php)
188 function setAll( new_lang, new_collation_connection, new_server, new_db, new_table ) {
189 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ' )');
190 if (new_server != server || new_lang != lang
191 || new_collation_connection != collation_connection) {
192 // something important has changed
193 server = new_server;
194 db = new_db;
195 table = new_table;
196 collation_connection = new_collation_connection;
197 lang = new_lang;
198 refreshNavigation();
199 } else if (new_db != db || new_table != table) {
200 // save new db and table
201 var old_db = db;
202 var old_table = table;
203 db = new_db;
204 table = new_table;
206 if (window.frame_navigation.document.getElementById(db) == null
207 && window.frame_navigation.document.getElementById(db + '.' + table) == null ) {
208 // table or db is unknown, reload complete left frame
209 refreshNavigation();
210 } else {
211 unmarkDbTable(old_db, old_table);
212 markDbTable(db, table);
215 // TODO: add code to expand db in lightview mode
217 // refresh querywindow
218 refreshQuerywindow();
222 function reload_querywindow(db, table, sql_query)
224 if ( ! querywindow.closed && querywindow.location ) {
225 if ( ! querywindow.document.sqlform.LockFromUpdate
226 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
227 querywindow.document.getElementById('hiddenqueryform').db.value = db;
228 querywindow.document.getElementById('hiddenqueryform').table.value = table;
230 if (sql_query) {
231 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
234 querywindow.document.getElementById('hiddenqueryform').submit();
240 * brings query window to front and inserts query to be edited
242 function focus_querywindow(sql_query)
244 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
245 if ( !querywindow || querywindow.closed || !querywindow.location) {
246 // we need first to open the window and cannot pass the query with it
247 // as we dont know if the query exceeds max url length
248 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
249 query_to_load = sql_query;
250 open_querywindow();
251 insertQuery(0);
252 } else {
253 //var querywindow = querywindow;
254 if ( querywindow.document.getElementById('hiddenqueryform').querydisplay_tab != 'sql' ) {
255 querywindow.document.getElementById('hiddenqueryform').querydisplay_tab.value = "sql";
256 querywindow.document.getElementById('hiddenqueryform').sql_query.value = sql_query;
257 querywindow.document.getElementById('hiddenqueryform').submit();
258 querywindow.focus();
259 } else {
260 querywindow.focus();
263 return true;
267 * inserts query string into query window textarea
268 * called from script tag in querywindow
270 function insertQuery() {
271 if (query_to_load != '' && querywindow.document && querywindow.document.getElementById && querywindow.document.getElementById('sqlquery')) {
272 querywindow.document.getElementById('sqlquery').value = query_to_load;
273 query_to_load = '';
274 return true;
276 return false;
279 function open_querywindow( url ) {
280 if ( ! url ) {
281 url = 'querywindow.php?' + common_query + '&db=' + encodeURIComponent(db) + '&table=' + encodeURIComponent(table);
284 if (!querywindow.closed && querywindow.location) {
285 goTo( url, 'query' );
286 querywindow.focus();
287 } else {
288 querywindow = window.open( url + '&init=1', '',
289 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
290 'scrollbars=yes,resizable=yes,' +
291 'width=' + querywindow_width + ',' +
292 'height=' + querywindow_height );
295 if ( ! querywindow.opener ) {
296 querywindow.opener = window.window;
299 if ( window.focus ) {
300 querywindow.focus();
303 return true;
306 function refreshQuerywindow( url ) {
308 if ( ! querywindow.closed && querywindow.location ) {
309 if ( ! querywindow.document.sqlform.LockFromUpdate
310 || ! querywindow.document.sqlform.LockFromUpdate.checked ) {
311 open_querywindow( url )
317 * opens new url in target frame, with default beeing left frame
318 * valid is 'main' and 'querywindow' all others leads to 'left'
320 * @param string targeturl new url to load
321 * @param string target frame where to load the new url
323 function goTo(targeturl, target) {
324 if ( target == 'main' ) {
325 target = window.frame_content;
326 } else if ( target == 'query' ) {
327 target = querywindow;
328 //return open_querywindow( targeturl );
329 } else if ( ! target ) {
330 target = window.frame_navigation;
333 if ( target ) {
334 if ( target.location.href == targeturl ) {
335 return true;
336 } else if ( target.location.href == pma_absolute_uri + targeturl ) {
337 return true;
340 if ( safari_browser ) {
341 target.location.href = targeturl;
342 } else {
343 target.location.replace(targeturl);
347 return true;
350 // opens selected db in main frame
351 function openDb(new_db) {
352 //alert('opendb(' + new_db + ')');
353 setDb(new_db);
354 setTable('');
355 refreshMain(opendb_url);
356 return true;
359 function updateTableTitle( table_link_id, new_title ) {
360 //alert('updateTableTitle');
361 if ( window.parent.frame_navigation.document.getElementById(table_link_id) ) {
362 var left = window.parent.frame_navigation.document;
363 left.getElementById(table_link_id).title = new_title;
364 new_title = left.getElementById('icon_' + table_link_id).alt + ': ' + new_title;
365 left.getElementById('browse_' + table_link_id).title = new_title;
366 return true;
369 return false;