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 * attach a function to object event
21 * addEvent(window, 'load', PMA_initPage);
24 * @param string event type (load, mouseover, focus, ...)
25 * @param function to be attached
27 function addEvent(obj
, type
, fn
)
29 if (obj
.attachEvent
) {
30 obj
['e' + type
+ fn
] = fn
;
31 obj
[type
+ fn
] = function() {obj
['e' + type
+ fn
](window
.event
);}
32 obj
.attachEvent('on' + type
, obj
[type
+ fn
]);
34 obj
.addEventListener(type
, fn
, false);
39 * detach/remove a function from an object event
42 * @param event type (load, mouseover, focus, ...)
43 * @param function naem of function to be attached
45 function removeEvent(obj
, type
, fn
)
47 if (obj
.detachEvent
) {
48 obj
.detachEvent('on' + type
, obj
[type
+ fn
]);
49 obj
[type
+ fn
] = null;
51 obj
.removeEventListener(type
, fn
, false);
56 * get DOM elements by html class
58 * @param string class_name - name of class
59 * @param node node - search only sub nodes of this node (optional)
60 * @param string tag - search only these tags (optional)
62 function getElementsByClassName(class_name
, node
, tag
)
64 var classElements
= new Array();
74 var els
= node
.getElementsByTagName(tag
);
75 var elsLen
= els
.length
;
77 for (i
= 0; i
< elsLen
; i
++) {
78 if (els
[i
].className
.indexOf(class_name
) != -1) {
79 teststr
= "," + els
[i
].className
.split(" ").join(",") + ",";
80 if (teststr
.indexOf("," + class_name
+ ",") != -1) {
81 classElements
[j
] = els
[i
];
90 * sets current selected db
92 * @param string db name
94 function setDb(new_db
) {
95 //alert('setDb(' + new_db + ')');
98 //alert( new_db + '(' + new_db.length + ') : ' + db );
103 // the db name as an id exists only when LeftFrameLight is false
104 if (window
.frame_navigation
.document
.getElementById(db
) == null) {
105 // happens when LeftFrameLight is true
106 // db is unknown, reload complete left frame
109 // happens when LeftFrameLight is false
110 unmarkDbTable(old_db
);
114 // TODO: add code to expand db in lightview mode
116 // refresh querywindow
117 refreshQuerywindow();
122 * sets current selected table (called from navigation.php)
124 * @param string table name
126 function setTable(new_table
) {
127 //alert('setTable(' + new_table + ')');
128 if (new_table
!= table
) {
130 //alert( new_table + '(' + new_table.length + ') : ' + table );
134 if (window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null
136 // table is unknown, reload complete left frame
140 // TODO: add code to expand table in lightview mode
142 // refresh querywindow
143 refreshQuerywindow();
157 * @uses collation_connection
158 * @uses encodeURIComponent()
159 * @param string url name of page to be loaded
161 function refreshMain(url
) {
170 goTo(url
+ '?server=' + encodeURIComponent(server
) +
171 '&token=' + encodeURIComponent(token
) +
172 '&db=' + encodeURIComponent(db
) +
173 '&table=' + encodeURIComponent(table
) +
174 '&lang=' + encodeURIComponent(lang
) +
175 '&collation_connection=' + encodeURIComponent(collation_connection
),
180 * reloads navigation frame
188 * @uses collation_connection
189 * @uses encodeURIComponent()
190 * @param boolean force force reloading
192 function refreshNavigation(force
) {
193 // The goTo() function won't refresh in case the target
194 // url is the same as the url given as parameter, but sometimes
195 // we want to refresh anyway.
196 if (typeof force
!= undefined && force
&& window
.parent
&& window
.parent
.frame_navigation
) {
197 window
.parent
.frame_navigation
.location
.reload();
199 goTo('navigation.php?server=' + encodeURIComponent(server
) +
200 '&token=' + encodeURIComponent(token
) +
201 '&db=' + encodeURIComponent(db
) +
202 '&table=' + encodeURIComponent(table
) +
203 '&lang=' + encodeURIComponent(lang
) +
204 '&collation_connection=' + encodeURIComponent(collation_connection
)
209 function unmarkDbTable(db
, table
)
211 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
212 if (element_reference
!= null) {
213 $(element_reference
).parent().removeClass('marked');
216 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
217 if (element_reference
!= null) {
218 $(element_reference
).parent().removeClass('marked');
222 function markDbTable(db
, table
)
224 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
225 if (element_reference
!= null) {
226 $(element_reference
).parent().addClass('marked');
228 element_reference
.focus();
229 // opera marks the text, we dont want this ...
230 element_reference
.blur();
233 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
234 if (element_reference
!= null) {
235 $(element_reference
).parent().addClass('marked');
237 element_reference
.focus();
238 // opera marks the text, we dont want this ...
239 element_reference
.blur();
242 // return to main frame ...
243 window
.frame_content
.focus();
247 * sets current selected server, table and db (called from libraries/footer.inc.php)
249 function setAll( new_lang
, new_collation_connection
, new_server
, new_db
, new_table
, new_token
) {
250 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ', ' + new_token + ' )');
251 if (new_server
!= server
|| new_lang
!= lang
252 || new_collation_connection
!= collation_connection
) {
253 // something important has changed
257 collation_connection
= new_collation_connection
;
261 } else if (new_db
!= db
|| new_table
!= table
) {
262 // save new db and table
264 var old_table
= table
;
268 if (window
.frame_navigation
.document
.getElementById(db
) == null
269 && window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null ) {
270 // table or db is unknown, reload complete left frame
273 unmarkDbTable(old_db
, old_table
);
274 markDbTable(db
, table
);
277 // TODO: add code to expand db in lightview mode
279 // refresh querywindow
280 refreshQuerywindow();
284 function reload_querywindow(db
, table
, sql_query
)
286 if ( ! querywindow
.closed
&& querywindow
.location
) {
287 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
288 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
289 querywindow
.document
.getElementById('hiddenqueryform').db
.value
= db
;
290 querywindow
.document
.getElementById('hiddenqueryform').table
.value
= table
;
293 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
296 querywindow
.document
.getElementById('hiddenqueryform').submit();
302 * brings query window to front and inserts query to be edited
304 function focus_querywindow(sql_query
)
306 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
307 if ( !querywindow
|| querywindow
.closed
|| !querywindow
.location
) {
308 // we need first to open the window and cannot pass the query with it
309 // as we dont know if the query exceeds max url length
310 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
311 query_to_load
= sql_query
;
315 //var querywindow = querywindow;
316 if ( querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
!= 'sql' ) {
317 querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
.value
= "sql";
318 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
319 querywindow
.document
.getElementById('hiddenqueryform').submit();
329 * inserts query string into query window textarea
330 * called from script tag in querywindow
332 function insertQuery() {
333 if (query_to_load
!= '' && querywindow
.document
&& querywindow
.document
.getElementById
&& querywindow
.document
.getElementById('sqlquery')) {
334 querywindow
.document
.getElementById('sqlquery').value
= query_to_load
;
341 function open_querywindow( url
) {
343 url
= 'querywindow.php?' + common_query
+ '&db=' + encodeURIComponent(db
) + '&table=' + encodeURIComponent(table
);
346 if (!querywindow
.closed
&& querywindow
.location
) {
347 goTo( url
, 'query' );
350 querywindow
= window
.open( url
+ '&init=1', '',
351 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
352 'scrollbars=yes,resizable=yes,' +
353 'width=' + querywindow_width
+ ',' +
354 'height=' + querywindow_height
);
357 if ( ! querywindow
.opener
) {
358 querywindow
.opener
= window
.window
;
361 if ( window
.focus
) {
368 function refreshQuerywindow( url
) {
370 if ( ! querywindow
.closed
&& querywindow
.location
) {
371 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
372 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
373 open_querywindow( url
)
379 * opens new url in target frame, with default being left frame
380 * valid is 'main' and 'querywindow' all others leads to 'left'
382 * @param string targeturl new url to load
383 * @param string target frame where to load the new url
385 function goTo(targeturl
, target
) {
387 if ( target
== 'main' ) {
388 target
= window
.frame_content
;
389 } else if ( target
== 'query' ) {
390 target
= querywindow
;
391 //return open_querywindow( targeturl );
392 } else if ( ! target
) {
393 target
= window
.frame_navigation
;
397 if ( target
.location
.href
== targeturl
) {
399 } else if ( target
.location
.href
== pma_absolute_uri
+ targeturl
) {
403 if ( safari_browser
) {
404 target
.location
.href
= targeturl
;
406 target
.location
.replace(targeturl
);
413 // opens selected db in main frame
414 function openDb(new_db
) {
415 //alert('opendb(' + new_db + ')');
418 refreshMain(opendb_url
);
422 function updateTableTitle( table_link_id
, new_title
) {
423 //alert('updateTableTitle');
424 if ( window
.parent
.frame_navigation
.document
&& window
.parent
.frame_navigation
.document
.getElementById(table_link_id
) ) {
425 var left
= window
.parent
.frame_navigation
.document
;
427 var link
= left
.getElementById(table_link_id
);
428 link
.title
= window
.parent
.pma_text_default_tab
+ ': ' + new_title
;
430 var link
= left
.getElementById('quick_' + table_link_id
);
431 link
.title
= window
.parent
.pma_text_left_default_tab
+ ': ' + new_title
;