1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * common functions used for communicating between main, navigation and querywindow
9 * holds the browser query window
14 * holds the query to be load from a new query window
16 var query_to_load
= '';
19 * attach a function to object event
22 * addEvent(window, 'load', PMA_initPage);
25 * @param string event type (load, mouseover, focus, ...)
26 * @param function to be attached
28 function addEvent(obj
, type
, fn
)
30 if (obj
.attachEvent
) {
31 obj
['e' + type
+ fn
] = fn
;
32 obj
[type
+ fn
] = function() {obj
['e' + type
+ fn
](window
.event
);}
33 obj
.attachEvent('on' + type
, obj
[type
+ fn
]);
35 obj
.addEventListener(type
, fn
, false);
40 * detach/remove a function from an object event
43 * @param event type (load, mouseover, focus, ...)
44 * @param function naem of function to be attached
46 function removeEvent(obj
, type
, fn
)
48 if (obj
.detachEvent
) {
49 obj
.detachEvent('on' + type
, obj
[type
+ fn
]);
50 obj
[type
+ fn
] = null;
52 obj
.removeEventListener(type
, fn
, false);
57 * get DOM elements by html class
59 * @param string class_name - name of class
60 * @param node node - search only sub nodes of this node (optional)
61 * @param string tag - search only these tags (optional)
63 function getElementsByClassName(class_name
, node
, tag
)
65 var classElements
= new Array();
75 var els
= node
.getElementsByTagName(tag
);
76 var elsLen
= els
.length
;
78 for (i
= 0; i
< elsLen
; i
++) {
79 if (els
[i
].className
.indexOf(class_name
) != -1) {
80 teststr
= "," + els
[i
].className
.split(" ").join(",") + ",";
81 if (teststr
.indexOf("," + class_name
+ ",") != -1) {
82 classElements
[j
] = els
[i
];
91 * sets current selected db
93 * @param string db name
95 function setDb(new_db
) {
96 //alert('setDb(' + new_db + ')');
99 //alert( new_db + '(' + new_db.length + ') : ' + db );
104 // the db name as an id exists only when LeftFrameLight is false
105 if (window
.frame_navigation
.document
.getElementById(db
) == null) {
106 // happens when LeftFrameLight is true
107 // db is unknown, reload complete left frame
110 // happens when LeftFrameLight is false
111 unmarkDbTable(old_db
);
115 // TODO: add code to expand db in lightview mode
117 // refresh querywindow
118 refreshQuerywindow();
123 * sets current selected table (called from navigation.php)
125 * @param string table name
127 function setTable(new_table
) {
128 //alert('setTable(' + new_table + ')');
129 if (new_table
!= table
) {
131 //alert( new_table + '(' + new_table.length + ') : ' + table );
135 if (window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null
137 // table is unknown, reload complete left frame
141 // TODO: add code to expand table in lightview mode
143 // refresh querywindow
144 refreshQuerywindow();
158 * @uses collation_connection
159 * @uses encodeURIComponent()
160 * @param string url name of page to be loaded
162 function refreshMain(url
) {
171 goTo(url
+ '?server=' + encodeURIComponent(server
) +
172 '&token=' + encodeURIComponent(token
) +
173 '&db=' + encodeURIComponent(db
) +
174 '&table=' + encodeURIComponent(table
) +
175 '&lang=' + encodeURIComponent(lang
) +
176 '&collation_connection=' + encodeURIComponent(collation_connection
),
181 * reloads navigation frame
189 * @uses collation_connection
190 * @uses encodeURIComponent()
192 function refreshNavigation() {
193 goTo('navigation.php?server=' + encodeURIComponent(server
) +
194 '&token=' + encodeURIComponent(token
) +
195 '&db=' + encodeURIComponent(db
) +
196 '&table=' + encodeURIComponent(table
) +
197 '&lang=' + encodeURIComponent(lang
) +
198 '&collation_connection=' + encodeURIComponent(collation_connection
)
203 * adds class to element
205 function addClass(element
, classname
)
207 if (element
!= null) {
208 element
.className
+= ' ' + classname
;
209 //alert('set class: ' + classname + ', now: ' + element.className);
214 * removes class from element
216 function removeClass(element
, classname
)
218 if (element
!= null) {
219 element
.className
= element
.className
.replace(' ' + classname
, '');
220 // if there is no other class anem there is no leading space
221 element
.className
= element
.className
.replace(classname
, '');
222 //alert('removed class: ' + classname + ', now: ' + element.className);
226 function unmarkDbTable(db
, table
)
228 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
229 if (element_reference
!= null) {
230 //alert('remove from: ' + db);
231 removeClass(element_reference
.parentNode
, 'marked');
234 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
235 if (element_reference
!= null) {
236 //alert('remove from: ' + db + '.' + table);
237 removeClass(element_reference
.parentNode
, 'marked');
241 function markDbTable(db
, table
)
243 var element_reference
= window
.frame_navigation
.document
.getElementById(db
);
244 if (element_reference
!= null) {
245 addClass(element_reference
.parentNode
, 'marked');
247 element_reference
.focus();
248 // opera marks the text, we dont want this ...
249 element_reference
.blur();
252 element_reference
= window
.frame_navigation
.document
.getElementById(db
+ '.' + table
);
253 if (element_reference
!= null) {
254 addClass(element_reference
.parentNode
, 'marked');
256 element_reference
.focus();
257 // opera marks the text, we dont want this ...
258 element_reference
.blur();
261 // return to main frame ...
262 window
.frame_content
.focus();
266 * sets current selected server, table and db (called from libraries/footer.inc.php)
268 function setAll( new_lang
, new_collation_connection
, new_server
, new_db
, new_table
, new_token
) {
269 //alert('setAll( ' + new_lang + ', ' + new_collation_connection + ', ' + new_server + ', ' + new_db + ', ' + new_table + ', ' + new_token + ' )');
270 if (new_server
!= server
|| new_lang
!= lang
271 || new_collation_connection
!= collation_connection
) {
272 // something important has changed
276 collation_connection
= new_collation_connection
;
280 } else if (new_db
!= db
|| new_table
!= table
) {
281 // save new db and table
283 var old_table
= table
;
287 if (window
.frame_navigation
.document
.getElementById(db
) == null
288 && window
.frame_navigation
.document
.getElementById(db
+ '.' + table
) == null ) {
289 // table or db is unknown, reload complete left frame
292 unmarkDbTable(old_db
, old_table
);
293 markDbTable(db
, table
);
296 // TODO: add code to expand db in lightview mode
298 // refresh querywindow
299 refreshQuerywindow();
303 function reload_querywindow(db
, table
, sql_query
)
305 if ( ! querywindow
.closed
&& querywindow
.location
) {
306 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
307 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
308 querywindow
.document
.getElementById('hiddenqueryform').db
.value
= db
;
309 querywindow
.document
.getElementById('hiddenqueryform').table
.value
= table
;
312 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
315 querywindow
.document
.getElementById('hiddenqueryform').submit();
321 * brings query window to front and inserts query to be edited
323 function focus_querywindow(sql_query
)
325 /* if ( querywindow && !querywindow.closed && querywindow.location) { */
326 if ( !querywindow
|| querywindow
.closed
|| !querywindow
.location
) {
327 // we need first to open the window and cannot pass the query with it
328 // as we dont know if the query exceeds max url length
329 /* url = 'querywindow.php?' + common_query + '&db=' + db + '&table=' + table + '&sql_query=SELECT * FROM'; */
330 query_to_load
= sql_query
;
334 //var querywindow = querywindow;
335 if ( querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
!= 'sql' ) {
336 querywindow
.document
.getElementById('hiddenqueryform').querydisplay_tab
.value
= "sql";
337 querywindow
.document
.getElementById('hiddenqueryform').sql_query
.value
= sql_query
;
338 querywindow
.document
.getElementById('hiddenqueryform').submit();
348 * inserts query string into query window textarea
349 * called from script tag in querywindow
351 function insertQuery() {
352 if (query_to_load
!= '' && querywindow
.document
&& querywindow
.document
.getElementById
&& querywindow
.document
.getElementById('sqlquery')) {
353 querywindow
.document
.getElementById('sqlquery').value
= query_to_load
;
360 function open_querywindow( url
) {
362 url
= 'querywindow.php?' + common_query
+ '&db=' + encodeURIComponent(db
) + '&table=' + encodeURIComponent(table
);
365 if (!querywindow
.closed
&& querywindow
.location
) {
366 goTo( url
, 'query' );
369 querywindow
= window
.open( url
+ '&init=1', '',
370 'toolbar=0,location=0,directories=0,status=1,menubar=0,' +
371 'scrollbars=yes,resizable=yes,' +
372 'width=' + querywindow_width
+ ',' +
373 'height=' + querywindow_height
);
376 if ( ! querywindow
.opener
) {
377 querywindow
.opener
= window
.window
;
380 if ( window
.focus
) {
387 function refreshQuerywindow( url
) {
389 if ( ! querywindow
.closed
&& querywindow
.location
) {
390 if ( ! querywindow
.document
.sqlform
.LockFromUpdate
391 || ! querywindow
.document
.sqlform
.LockFromUpdate
.checked
) {
392 open_querywindow( url
)
398 * opens new url in target frame, with default being left frame
399 * valid is 'main' and 'querywindow' all others leads to 'left'
401 * @param string targeturl new url to load
402 * @param string target frame where to load the new url
404 function goTo(targeturl
, target
) {
406 if ( target
== 'main' ) {
407 target
= window
.frame_content
;
408 } else if ( target
== 'query' ) {
409 target
= querywindow
;
410 //return open_querywindow( targeturl );
411 } else if ( ! target
) {
412 target
= window
.frame_navigation
;
416 if ( target
.location
.href
== targeturl
) {
418 } else if ( target
.location
.href
== pma_absolute_uri
+ targeturl
) {
422 if ( safari_browser
) {
423 target
.location
.href
= targeturl
;
425 target
.location
.replace(targeturl
);
432 // opens selected db in main frame
433 function openDb(new_db
) {
434 //alert('opendb(' + new_db + ')');
437 refreshMain(opendb_url
);
441 function updateTableTitle( table_link_id
, new_title
) {
442 //alert('updateTableTitle');
443 if ( window
.parent
.frame_navigation
.document
&& window
.parent
.frame_navigation
.document
.getElementById(table_link_id
) ) {
444 var left
= window
.parent
.frame_navigation
.document
;
446 var link
= left
.getElementById(table_link_id
);
447 link
.title
= window
.parent
.pma_text_default_tab
+ ': ' + new_title
;
449 var link
= left
.getElementById('quick_' + table_link_id
);
450 link
.title
= window
.parent
.pma_text_left_default_tab
+ ': ' + new_title
;