minor bugsfixed documentation added

This commit is contained in:
ankitg
2010-08-17 00:23:57 +05:30
parent e6bb88117f
commit 369b5d00f8
3 changed files with 738 additions and 649 deletions

View File

@@ -1,9 +1,18 @@
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* @fileoverview function used in this file builds history tab and generates query.
*
* @requires jQuery
* @requires moves.js
* @version $Id$
*/
var history_array = []; // Global array to store history objects
var select_field = [];
var select_field = []; // Global array to store informaation for columns which are used in select clause
var g_index;
/**
* J-query function for panel, hides and shows toggle_container <div>
* function for panel, hides and shows toggle_container <div>,which is for history elements uses {@link JQuery}.
*
* @param index has value 1 or 0,decides wheter to hide toggle_container on load.
**/
@@ -18,25 +27,27 @@ function panel(index) {
}
/**
* Sorts history_array[] first then generates the HTML code for history tab,clubbing all objects of same tables together
* Sorts history_array[] first,using table name as the key and then generates the HTML code for history tab,
* clubbing all objects of same tables together
* This function is called whenever changes are made in history_array[]
*
* @uses and_or()
* @uses history_edit()
* @uses history_delete()
*
* @param init starting index of unsorted array
* @param fianl last index of unsorted array
* @param {int} init starting index of unsorted array
* @param {int} final last index of unsorted array
*
**/
function display(init,final) {
var str,i,j,k,sto;
// this part sorts the history array based on table name,this is needed for clubbing all object of same name together.
for (i = init;i < final;i++) {
sto = history_array[i];
var temp = history_array[i].get_tab() + '.' + history_array[i].get_obj_no();
var temp = history_array[i].get_tab() ;//+ '.' + history_array[i].get_obj_no(); for Self JOINS
for(j = 0;j < i;j++){
if(temp > (history_array[j].get_tab() + '.' + history_array[j].get_obj_no())) {
if(temp > (history_array[j].get_tab())) {//+ '.' + history_array[j].get_obj_no())) { //for Self JOINS
for(k = i;k > j;k--) {
history_array[k] = history_array[k-1];
}
@@ -45,12 +56,13 @@ function display(init,final) {
}
}
}
// this part generates HTML code for history tab.adds delete,edit,and/or and detail features with objects.
str =''; // string to store Html code for history tab
for ( var i=0; i < history_array.length; i++){
var temp = history_array[i].get_tab() + '.' + history_array[i].get_obj_no();
var temp = history_array[i].get_tab(); //+ '.' + history_array[i].get_obj_no(); for Self JOIN
str += '<h2 class="tiger"><a href="#">' + temp + '</a></h2>';
str += '<div class="toggle_container">\n';
while((history_array[i].get_tab() + '.' + history_array[i].get_obj_no()) == temp) {
while((history_array[i].get_tab()) == temp) { //+ '.' + history_array[i].get_obj_no()) == temp) {
str +='<div class="block"> <table width ="250">';
str += '<thead><tr><td>';
if(history_array[i].get_and_or()){
@@ -64,7 +76,7 @@ function display(init,final) {
str += '</td><td align="center"><img src="themes/original/img/b_info.png" title="'+detail(i)+'"/><td title="' + detail(i) +'">' + history_array[i].get_type() + '</td></td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')><img src="themes/original/img/b_drop.png" title="Delete"></td></tr></thead>';
}
else {
str += '</td><td align="center"><img src="themes/original/img/b_info.png" title="'+detail(i)+'"/></td><td title="' + detail(i) +'">' + history_array[i].get_type() + '</td><td <td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_edit('+ i +')><img src="themes/original/img/b_edit.png" title="Edit"/></td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')><img src="themes/original/img/b_drop.png" title="Delete"></td></tr></thead>';
str += '</td><td align="center"><img src="themes/original/img/b_info.png" title="'+detail(i)+'"/></td><td title="' + detail(i) +'">' + history_array[i]. get_type() + '</td><td <td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_edit('+ i +')><img src="themes/original/img/b_edit.png" title="Edit"/></td><td onmouseover="this.className=\'history_table\';" onmouseout="this.className=\'history_table2\'" onclick=history_delete('+ i +')><img src="themes/original/img/b_drop.png" title="Delete"></td></tr></thead>';
}
i++;
if(i >= history_array.length) {
@@ -83,7 +95,7 @@ function display(init,final) {
*
* @uses panel()
*
* @param index index of history_array where change is to be made
* @param {int} index of history_array where change is to be made
*
**/
@@ -100,7 +112,7 @@ function and_or(index) {
}
/**
* To display details of obects(where,rename,aggregate,groupby,orderby,having)
* To display details of obects(where,rename,Having,aggregate,groupby,orderby,having)
*
* @param index index of history_array where change is to be made
*
@@ -160,9 +172,9 @@ function history_delete(index) {
}
/**
* To show where,rename,aggregate forms to edit a object
* To show where,rename,aggregate,having forms to edit a object
*
* @param index index of history_array where change is to be made
* @param{int} index index of history_array where change is to be made
*
**/
@@ -172,8 +184,8 @@ function history_edit(index) {
if (type == "Where") {
document.getElementById('eQuery').value = history_array[index].get_obj().getquery();
document.getElementById('erel_opt').value = history_array[index].get_obj().getrelation_operator();
document.getElementById('query_where').style.left = '230px';
document.getElementById('query_where').style.top = '330px';
document.getElementById('query_where').style.left = '530px';
document.getElementById('query_where').style.top = '130px';
document.getElementById('query_where').style.position = 'absolute';
document.getElementById('query_where').style.zIndex = '9';
document.getElementById('query_where').style.visibility = 'visible';
@@ -182,15 +194,15 @@ function history_edit(index) {
document.getElementById('hQuery').value = history_array[index].get_obj().getquery();
document.getElementById('hrel_opt').value = history_array[index].get_obj().getrelation_operator();
document.getElementById('hoperator').value = history_array[index].get_obj().get_operator();
document.getElementById('query_having').style.left = '230px';
document.getElementById('query_having').style.top = '330px';
document.getElementById('query_having').style.left = '530px';
document.getElementById('query_having').style.top = '130px';
document.getElementById('query_having').style.position = 'absolute';
document.getElementById('query_having').style.zIndex = '9';
document.getElementById('query_having').style.visibility = 'visible';
}
if (type == "Rename") {
document.getElementById('query_rename_to').style.left = '230px';
document.getElementById('query_rename_to').style.top = '330px';
document.getElementById('query_rename_to').style.left = '530px';
document.getElementById('query_rename_to').style.top = '130px';
document.getElementById('query_rename_to').style.position = 'absolute';
document.getElementById('query_rename_to').style.zIndex = '9';
document.getElementById('query_rename_to').style.visibility = 'visible';
@@ -205,8 +217,8 @@ function history_edit(index) {
}
/**
* Make changes in history_array when Edit is clicked
*
* Make changes in history_array when Edit button is clicked
* checks for the type of object and then sets the new value
* @uses panel()
* @uses display()
*
@@ -341,6 +353,15 @@ var where = function (nrelation_operator,nquery) {
this.setrelation_operator(nrelation_operator);
};
/**
* Having object closure, makes an object with all information of where
*
* @param nrelation_operator type of relation operator to be applied
* @param nquery stores value of value/sub-query
*
**/
var having = function (nrelation_operator,nquery,noperator) {
var relation_operator;
var query;
@@ -404,6 +425,13 @@ var aggregate = function(noperator) {
this.set_operator(noperator);
};
/**
* This function returns unique element from an array
*
* @param arraName array from which duplicate elem are to be removed.
* @return unique array
*/
function unique(arrayName) {
var newArray=new Array();
label:for(var i=0; i<arrayName.length;i++ )
@@ -418,6 +446,14 @@ function unique(arrayName) {
return newArray;
}
/**
* This function takes in array and a value as input and returns 1 if values is present in array
* else returns -1
*
* @param arrayName array
* @param value value which is to be searched in the array
*/
function found(arrayName,value) {
for(var i=0; i<arrayName.length; i++) {
if(arrayName[i] == value) { return 1;}
@@ -425,8 +461,20 @@ function found(arrayName,value) {
return -1;
}
function build_query(formtitle, fadin) {
/**
* This function is the main function for query building.
* uses history object details for this.
*
* @ uses query_where()
* @ uses query_groupby()
* @ uses query_having()
* @ uses query_orderby()
*
* @param formtitle title for the form
* @param fadin
*/
function build_query(formtitle, fadin) {
var q_select = "SELECT ";
var temp;
for(i = 0;i < select_field.length; i++) {
@@ -453,19 +501,26 @@ function build_query(formtitle, fadin) {
var box = document.getElementById('box');
document.getElementById('filter').style.display='block';
var btitle = document.getElementById('boxtitle');
btitle.innerHTML = formtitle;
if(fadin)
{
btitle.innerHTML = 'SELECT';//formtitle;
if(fadin){
gradient("box", 0);
fadein("box");
}
else
{
else{
box.style.display='block';
}
document.getElementById('textSqlquery').innerHTML = q_select;
// document.getElementById('hint').style.visibility = "visible";
}
/**
* This function builds from clause of query
* makes automatic joins.
*
* @uses unique
* @uses add_array
* @uses remove_array
*
*/
function query_from() {
var i =0;
@@ -488,11 +543,11 @@ function query_from() {
temp = tab_left.shift();
quer = temp;
tab_used.push(temp);
// if master table (key2) matches with tab used get all keys and check if tab_left matches
//after this check if master table (key2) matches with tab left then check if any foriegn matches with master .
for( i =0; i<2 ; i++) {
for (K in contr){
for (key in contr[K]){// contr name
// if master table (key2) matches with tab used get all keys and check if tab_left matches
//after this check if master table (key2) matches with tab left then check if any foriegn matches with master .
for (key2 in contr[K][key]){// table name
parts = key2.split(".");
if(found(tab_used,parts[1]) > 0) {
@@ -519,17 +574,14 @@ function query_from() {
for (key in contr[K]) {
for (key2 in contr[K][key]){// table name
parts = key2.split(".");
if(found(tab_left,parts[1]) > 0)
{
for (key3 in contr[K][key][key2]) // field name
{
if(found(tab_left,parts[1]) > 0){
for (key3 in contr[K][key][key2]){
parts1 = contr[K][key][key2][key3][0].split(".");
if(found(tab_used,parts1[1]) > 0) {
query += "\n" + 'LEFT JOIN ';
query += '`' + parts[0] + '`.`' + parts[1] + '` ON ' ;
query += '`' + parts1[1] + '`.`' + contr[K][key][key2][key3][1] + '` = ';
query += '`' + parts[1] + '`.`' + key3 + '` ';
t_tab_left.push(parts[1]);
}
}
@@ -552,7 +604,12 @@ function query_from() {
/* document.write(key3+";"); //master_field
document.write(contr[K][key][key2][key3][0]+";"); // foreign_table
document.write(contr[K][key][key2][key3][1]+";"); //forieign_feild */
/**
* This function concatenates two array
*
* @params add array elements of which are pushed in
* @params arr array in which elemnets are added
*/
function add_array(add,arr){
for( var i=0; i<add.length; i++){
arr.push(add[i]);
@@ -560,6 +617,12 @@ function add_array(add,arr){
return arr;
}
/* This fucntion removes all elements present in one array from the other.
*
* @params rem array from which each element is removed from other array.
* @params arr array from which elements are removed.
*
*/
function remove_array(rem,arr){
for(var i=0; i<rem.length; i++){
for(var j=0; j<arr.length; j++)
@@ -568,6 +631,11 @@ function remove_array(rem,arr){
return arr;
}
/**
* This function builds the groupby clause from history object
*
*/
function query_groupby() {
var i = 0;
var str = "";
@@ -578,6 +646,11 @@ function query_groupby() {
return str;
}
/**
* This function builds the Having clause from the history object.
*
*/
function query_having() {
var i = 0;
var and = "(";
@@ -597,6 +670,12 @@ function query_having() {
return and;
}
/**
* This function builds the orderby clause from the history object.
*
*/
function query_orderby() {
var i = 0;
var str = "" ;
@@ -607,6 +686,12 @@ function query_orderby() {
return str;
}
/**
* This function builds the Where clause from the history object.
*
*/
function query_where(){
var i = 0;
var and = "(";
@@ -617,7 +702,8 @@ function query_where(){
and += "( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() +" " + history_array[i].get_obj().getquery() + ")"; and += " AND ";
}
else {
or +="( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() +")"; or +=" OR " ;
or +="( " + history_array[i].get_column_name() + " " + history_array[i].get_obj().getrelation_operator() + " " + history_array[i].get_obj().getquery() +")";
or +=" OR " ;
}
}
}
@@ -650,6 +736,7 @@ function check_rename(id_this) {
}
return "";
}
function gradient(id, level)
{
var box = document.getElementById(id);
@@ -665,8 +752,7 @@ function gradient(id, level)
function fadein(id)
{
var level = 0;
while(level <= 1)
{
while(level <= 1){
setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
level += 0.01;
}

View File

@@ -623,7 +623,6 @@ function Small_tab(t, re_load)
var id = document.getElementById('id_tbody_' + t);
var id_this = document.getElementById('id_hide_tbody_' + t);
var id_t = document.getElementById(t);
id_t.style.width = id_t.offsetWidth + 'px';
if (id_this.innerHTML == "v") {
//---CROSS
@@ -649,7 +648,6 @@ function Select_tab(t)
//----------
var id_t = document.getElementById(t);
window.scrollTo(parseInt(id_t.style.left) - 300, parseInt(id_t.style.top) - 300);
setTimeout(function(){document.getElementById('id_zag_' + t).className = 'tab_zag';}, 800);
}
//------------------------------------------------------------------------------
@@ -1008,13 +1006,11 @@ function Select_all(id_this,owner)
select_field.push('`' + id_this.substring(owner.length +1) + '`.*');
tab = id_this.split(".");
from_array.push(tab[1]);
}
else {
for (i =0; i < select_field.length; i++) {
if (select_field[i] == ('`' + id_this.substring(owner.length +1) + '`.*')) {
select_field.splice(i,1);
}
}
for(k =0 ;k < from_array.length;k++){
@@ -1027,16 +1023,20 @@ function Select_all(id_this,owner)
Re_load();
}
function Table_onover(id_this,val)
function Table_onover(id_this,val,buil)
{
if(!val) {
document.getElementById("id_zag_" + id_this).className="tab_zag_2";
if(buil) {
document.getElementById("id_zag_" + id_this + "_2").className="tab_zag_2";
}
}
else {
document.getElementById("id_zag_" + id_this).className="tab_zag";
if(buil) {
document.getElementById("id_zag_" + id_this + "_2").className="tab_zag";
}
}
}
/* This function stores selected column information in select_field[]
@@ -1142,5 +1142,4 @@ function add_object() {
existingDiv.innerHTML = display(init,history_array.length);
Close_option();
panel(0);
}

View File

@@ -114,11 +114,14 @@ echo $script_tabs . $script_contr . $script_display_field;
class="M_butt" target="_self"
><img src="pmd/images/pdf.png" alt="key" width="20" height="20"
title="<?php echo __('Import/Export coordinates for PDF schema'); ?>" /></a
><a href="#" onClick="build_query('SQL Query on Database', 0)" onmousedown="return false;"
class="M_butt" target="_self"
><img src="pmd/images/query_builder.png" alt="key" width="20" height="20"
title="<?php echo __('Build Query'); ?>" /></a
><a href="javascript:Top_menu_right(document.getElementById('key_Left_Right'));"
>
<?php if($_REQUEST['query']){
echo '<a href="#" onClick="build_query(\'SQL Query on Database\', 0)" onmousedown="return false;"
class="M_butt" target="_self">';
echo '<img src="pmd/images/query_builder.png" alt="key" width="20" height="20" title="';
echo __('Build Query');
echo '"/></a>'; }?>
<a href="javascript:Top_menu_right(document.getElementById('key_Left_Right'));"
onmousedown="return false;" class="M_butt last" target="_self">
<img src="pmd/images/2rightarrow_m.png" id="key_Left_Right" alt=">"
title="<?php echo __('Move Menu'); ?>" /></a>
@@ -227,9 +230,9 @@ for ($i = 0; $i < count($GLOBALS['PMD']["TABLE_NAME"]); $i++) {
onclick="Start_tab_upd('<?php echo $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i]; ?>');">
<img src="pmd/images/exec_small.png" alt="" /></td>
<td nowrap="nowrap" id="id_zag_<?php echo $t_n_url ?>" class="tab_zag"
onmousedown="cur_click=document.getElementById('<?php echo $t_n_url ?>');"
onmouseover="Table_onover('<?php echo $t_n_url ?>',0)"
onmouseout="Table_onover('<?php echo $t_n_url ?>',1)">
onmousedown="cur_click=document.getElementById('<?php echo $t_n_url ?>');"/
onmouseover="Table_onover('<?php echo $t_n_url ?>',0,<?php echo (isset($_REQUEST['query'])? 1 : 0 )?> )"
onmouseout="Table_onover('<?php echo $t_n_url ?>',1,<?php echo (isset($_REQUEST['query']) ? 1 : 0 )?>)">
<span class='owner'>
<?php
echo $GLOBALS['PMD_OUT']["OWNER"][$i];
@@ -238,9 +241,9 @@ for ($i = 0; $i < count($GLOBALS['PMD']["TABLE_NAME"]); $i++) {
?></td>
<?php
if(isset($_REQUEST['query'])) {
echo '<td class="tab_zag" onmouseover="Table_onover(\''.htmlspecialchars($t_n_url).'\',0)" id="id_zag_'.htmlspecialchars($t_n_url).'_2"';
echo '<td class="tab_zag" onmouseover="Table_onover(\''.htmlspecialchars($t_n_url).'\',0,1)" id="id_zag_'.htmlspecialchars($t_n_url).'_2"';
echo 'onmousedown="cur_click=document.getElementById(\''.htmlspecialchars($t_n_url).'\');"';
echo 'onmouseout="Table_onover(\''.htmlspecialchars($t_n_url).'\',1)">';
echo 'onmouseout="Table_onover(\''.htmlspecialchars($t_n_url).'\',1,1)">';
}?>
</tr>
</thead>
@@ -810,15 +813,16 @@ if($_REQUEST['query']) {
echo '<div id="filter"></div>';
echo '<div id="box">';
echo '<span id="boxtitle"></span>';
echo '<form method="GET" action="" target="_parent">';
echo '<form method="post" action="pmd_general" target="_parent">';
echo '<textarea cols="80" name="sql_query" id="textSqlquery" rows="15"></textarea><div id="tblfooter">';
echo ' <input type="submit" name="submit" class="btn">';
echo ' <input type="submit" name="submit_sql" class="btn">';
echo ' <input type="button" name="cancel" value="Cancel" onClick="closebox()" class="btn">';
echo '</div></p>';
echo '</form></div>';
} ?>
<!-- cache images -->
<img src="pmd/images/2leftarrow_m.png" width="0" height="0" alt="" />
<img src="pmd/images/rightarrow1.png" width="0" height="0" alt="" />