Got rid of inline JS in PMD

This commit is contained in:
Rouslan Placella 2012-06-18 11:34:40 +01:00
parent 61fac554d6
commit 08e79ed030
3 changed files with 75 additions and 49 deletions

26
js/pmd/init.js Normal file
View File

@ -0,0 +1,26 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Initialises the data required to run PMD, then fires it up.
*/
var j_tabs, h_tabs, contr, server, db, token;
$(function() {
$(".trigger").click(function() {
$(".panel").toggle("fast");
$(this).toggleClass("active");
return false;
});
var tables_data = $.parseJSON($("#script_tables").html());
j_tabs = tables_data.j_tabs;
h_tabs = tables_data.h_tabs;
contr = $.parseJSON($("#script_contr").html());
display_field = $.parseJSON($("#script_display_field").html());
server = $("#script_server").html();
db = $("#script_db").html();
token = $("#script_token").html();
Main();
});

View File

@ -20,7 +20,7 @@ $cfgRelation = PMA_getRelationsParam();
*/
function get_tables_info()
{
$GLOBALS['script_display_field'] = 'var display_field = new Array();' . "\n";
$retval = array();
$GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
$GLOBALS['PMD']['OWNER'] = array();
@ -47,15 +47,13 @@ function get_tables_info()
$DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
if ($DF != '') {
$GLOBALS['script_display_field'] .= " display_field['"
. $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . "'] = '"
. urlencode($DF) . "';\n";
$retval[$GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i]] = urlencode($DF);
}
$i++;
}
return $GLOBALS['script_display_field'];
return $retval;
}
/**
@ -122,26 +120,22 @@ function get_script_contr()
}
$ti = 0;
$script_contr = 'var contr = new Array();' . "\n";
$retval = array();
for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
$js_var = ' contr[' . $ti . ']';
$script_contr .= $js_var . " = new Array();\n";
$js_var .= "['" . $con['C_NAME'][$i] . "']";
$script_contr .= $js_var . " = new Array();\n";
$retval[$ti] = array();
$retval[$ti][$con['C_NAME'][$i]] = array();
if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])
&& in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])
) {
$js_var .= "['" . $con['DTN'][$i] . "']";
$script_contr .= $js_var . " = new Array();\n";
$m_col = array();//}
$js_var .= "['" . $con['DCN'][$i] . "']";
$script_contr .= $js_var . " = new Array();\n";//}
$script_contr .= $js_var . "[0] = '" . $con['STN'][$i] . "';\n"; //
$script_contr .= $js_var . "[1] = '" . $con['SCN'][$i] . "';\n"; //
$retval[$ti][$con['C_NAME'][$i]][$con['DTN'][$i]] = array();
$retval[$ti][$con['C_NAME'][$i]][$con['DTN'][$i]][$con['DCN'][$i]] = array(
0 => $con['STN'][$i],
1 => $con['SCN'][$i]
);
}
$ti++;
}
return $script_contr;
return $retval;
}
/**
@ -190,16 +184,24 @@ function get_script_tabs()
{
$script_tabs = 'var j_tabs = new Array();' . "\n"
. 'var h_tabs = new Array();' . "\n" ;
$retval = array(
'j_tabs' => array(),
'h_tabs' => array()
);
for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
$script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '"
. PMA_Util::isForeignKeySupported(
$j = 0;
if (PMA_Util::isForeignKeySupported(
$GLOBALS['PMD']['TABLE_TYPE'][$i]
)
? '1' : '0'
. "';\n"
. "h_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = 1;" . "\n";
) {
$j = 1;
}
$retval['j_tabs'][$GLOBALS['PMD_URL']['TABLE_NAME'][$i]] = $j;
$retval['h_tabs'][$GLOBALS['PMD_URL']['TABLE_NAME'][$i]] = 1;
}
return $script_tabs;
return $retval;
}
/**

View File

@ -28,7 +28,7 @@ foreach ($get_params as $one_get_param) {
$script_display_field = get_tables_info();
$tab_column = get_columns_info();
$script_tabs = get_script_tabs();
$script_tables = get_script_tabs();
$script_contr = get_script_contr();
$tab_pos = get_tab_pos();
$tables_pk_or_unique_keys = get_pk_or_unique_keys();
@ -48,34 +48,32 @@ $scripts->addFile('pmd/ajax.js');
$scripts->addFile('pmd/history.js');
$scripts->addFile('pmd/move.js');
$scripts->addFile('pmd/iecanvas.js', true);
$scripts->addCode(
'var server = "' . PMA_escapeJsString($server) . '";
var db = "' . PMA_escapeJsString($db) . '";
var token = "' . PMA_escapeJsString($token) . '";'
);
if (isset($_REQUEST['query'])) {
$scripts->addCode(
'$(function() {
$(".trigger").click(function() {
$(".panel").toggle("fast");
$(this).toggleClass("active");
return false;
});
});'
);
}
$scripts->addCode(
'$(function() {
Main();
});'
);
$scripts->addCode($script_tabs);
$scripts->addCode($script_contr);
$scripts->addCode($script_display_field);
$scripts->addFile('pmd/init.js');
require 'libraries/db_common.inc.php';
require 'libraries/db_info.inc.php';
// Embed some data into HTML, later it will be read
// by pmd/init.js and converted to JS variables.
echo '<div id="script_server" class="hide">';
echo htmlspecialchars($GLOBALS['server']);
echo '</div>';
echo '<div id="script_db" class="hide">';
echo htmlspecialchars($GLOBALS['db']);
echo '</div>';
echo '<div id="script_token" class="hide">';
echo htmlspecialchars($GLOBALS['token']);
echo '</div>';
echo '<div id="script_tables" class="hide">';
echo htmlspecialchars(json_encode($script_tables));
echo '</div>';
echo '<div id="script_contr" class="hide">';
echo htmlspecialchars(json_encode($script_contr));
echo '</div>';
echo '<div id="script_display_field" class="hide">';
echo htmlspecialchars(json_encode($script_display_field));
echo '</div>';
?>
<div class="pmd_header" id="top_menu">
<a href="#" onclick="Show_left_menu(document.getElementById('key_Show_left_menu')); return false"