...

View Full Version : Cant set this value



jacastronunes
08-24-2010, 11:46 AM
Hello i have this js file


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
var page = 0;
var pages = 0;
var linhas = 0;
var lines = 10;
var DivTable = null;
var DivPager = null;
var PhpFile = null;
var css = null;
var pagercss = null;

function setPhpFile(file)
{
this.PhpFile = file;
}

function setPage(page)
{
this.page = page;
}

function setPages(numberPages)
{
this.pages = numberPages;
}

function setDivTable(table)
{
this.DivTable = table;
}

function setDivPager(pager)
{
this.DivPager = pager;
}

function setStyle(style)
{
this.css = style;
}
function setPagerStyle(style)
{
this.pagercss = style;
}
function setRows(rows)
{
this.linhas = rows;
}
function getPhpFile()
{
return this.PhpFile;
}
function getPage()
{
return this.page;
}
function getPages()
{
return this.pages;
}
function getDivTable()
{
return this.DivTable;
}

function getDivPager()
{
return this.DivPager;
}

function getStyle()
{
return this.css;
}
function getPagerStyle()
{
return this.pagercss;
}
function LoadNumberRows()
{
$.ajax({
type: "GET",
url: "AjaxController.php",
data: "action=GetNumberRows",
dataType: "json",
beforeSend: function(){
},
complete: function(){
},
success: function(msg){
setRows(msg[0].Count);
}
});
}
function gerNumberRows()
{
return this.linhas;
}
function CreateDinamicTable(arrHeader,style,divTable,divPager,pagerStyle,phpFile)
{
/********Seting Vars**********/
setStyle(style);
setDivTable(divTable);
setDivPager(divPager);
setPhpFile(phpFile);
setPagerStyle(pagerStyle);
LoadNumberRows(); //Here a function load the number of rows via ajax and set it to var linhas, but var linhas always stays 0


Please help me.

Dormilich
08-24-2010, 02:00 PM
do you have a link?

jacastronunes
08-25-2010, 11:36 AM
http://62.48.206.139:8080/backoffice/gestao/ProductFolder/index2.php,
please help me

Dormilich
08-25-2010, 11:50 AM
how did you determine that linhas doesn’t change?

jacastronunes
08-25-2010, 11:55 AM
function gerNumberRows()
{
return this.linhas;
}


Because if i make an alert of getNumberRows it will return 0, that the value initialized on the var, i thinks that is has to do with returning inside a ajax response.

Dormilich
08-25-2010, 11:57 AM
getNumberRows() != gerNumberRows()

jacastronunes
08-25-2010, 11:59 AM
sory, i didn't understand what you mean by that

Dormilich
08-25-2010, 12:00 PM
there is no getNumberRows() function, because the function is called gerNumberRows()

jacastronunes
08-25-2010, 12:04 PM
I have corrected the function name, but its returning 0 anyway.



/*************************/
var divTable = getDivTable();
var lines = getPageFilterValue();
var page = getPage();
if(getSearchMode() == true)
{
dataToSend = getSearchText()+"&lines="+lines+"&page="+page;
}
else
{
dataToSend = "action=Load&lines="+lines+"&page="+page;
}
$.ajax({
type: "GET",
url: this.dataFile,
data: dataToSend,
dataType: "json",
beforeSend: function(){
$('#'+divTable).show();
$('#'+divTable).html('<img name="imgAjaxLoading3" id="imgAjaxLoading3" style="display: none;" alt="" src="">');
$('#imgAjaxLoading3').show();
$('#imgAjaxLoading3').attr("src","/images/loading2.gif");
},
complete: function(){
$('#imgAjaxLoading3').hide();


},
success: function(msg){
if(msg.length > 0)
{
var head = getArrayHeader().Header;
var genOpt = getArrayHeader().GeneralOptions;
setRows(msg[0].NumberRows);//Here i try to set the var linhas
var html = "<fieldset class=\"first\">"
+"<legend> Resultado: "+msg[0].data.length+"</legend>";
html +="<div id='gen'><p style=\"textAlign:left\">";
if(genOpt[0].AllowSearch == "true")
{
html +="<a href='javascript:Search()'><img src=\"AjaxTable/Images/search.gif\"/></a>";
}
if(genOpt[0].AllowAdd == "true")
{
html +="<a href='javascript:Add()'><img src=\"AjaxTable/Images/add.gif\"/></a>";
}
html +="</p></div><font face=\"verdana\"><table cellspacing=0 cellpadding=0 id='dg' class='"+getStyle()+"' >"
+"<tr>";
if(genOpt[0].BuildActions == "True")
{
html += "<td id='colActions' class='td-header' style='width:50px;' nowrap='true'>ACTIONS"
+"</td>"
}
for(i=0;i<head.length;i++)
{
innerStyle = "";
if(head[i].visible == "false")
{
innerStyle = "display:none;";
}
if(head[i].width)
{
innerStyle += "width:"+head[i].width+";";
}
html += "<td id='"+head[i]["Field"]+"' class='td-header' style='"+innerStyle+"' nowrap='true'>"+head[i]["Name"];
if(getSearchMode() == "false")
{
if(head[i].search == "true")
{
html +="<a href='javascript:Sort(\""+head[i].dataFieldName+"\",\"asc\")'><img src=\"AjaxTable/Images/arrowUp.gif\"/></a>&nbsp;<a href='javascript:Sort(\""+head[i].dataFieldName+"\",\"desc\")'><img src=\"AjaxTable/Images/arrowDown.gif\"/></a></td>";
}
}
}
html +="</tr>";
for(s=0;s<msg[0].data.length;s++)
{
var tdclass = "td-odd";
if(s%2==0)
{
tdclass = "td-even";
}
html += "<tr id='data"+s+"'>"
if(genOpt[0].BuildActions == "True")
{
html +="<td class='"+tdclass+"' id='Actions"+s+"'>"
+"<button onclick='delPath(\"data"+s+"\")' id=\"buttonDel"+s+"\" type=\"button\" style=\"width:20px;\">D</button>"
+"<button onclick='editPath(\"data"+s+"\")' id=\"buttonEdit"+s+"\" type=\"button\" style=\"width:20px;\">E</button>"
+"</td>"
}
for(i=0;i<head.length;i++)
{
innerStyle = "";
if(head[i].visible == "false")
{
innerStyle = "display:none;";
}
if(head[i].width)
{
innerStyle += "width:"+head[i].width+";";
}
html +="<td class='"+tdclass+"' style='"+innerStyle+"' id='"+head[i].Field+s+"'>"+msg[0].data[s][head[i].dataFieldName]+"</td>";

}
html +="</tr>"
}
html +="</table></fieldset>";
}else{
html="<fieldset class=\"first\"><legend><font class=\"smallblinkytext\">ERRO</font></legend><h1 class=\"blinkytext\">Erro a carregar dados<br>Por favor contacte o administrador de sistemas</h1></fieldset>";
}
$('#'+divTable).html(html);
}
});


I have make and alert inside the function that need that value, but its still returning 0.
I think that i cant return a value inside that ajax complete function :S

Dormilich
08-25-2010, 12:06 PM
I don’t see a getNumberRows() function in this code.

jacastronunes
08-25-2010, 12:15 PM
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
var page = 1;
var pages = 0;
var linhas = 0;
var DivTable = null;
var DivPager = null;
var DivSearch = null;
var DivDel = null;
var dataFile = null;
var css = null;
var pagercss = null;
var arrheader = null;
var searchMode = false;
var pageFilterValue = 0;
var firstPagerBuilt = false;
var searchText = null;
var searchFunction = null;

function includes()
{
document.write('<script type="text/javascript" src="/js/DataPicker/ui/ui.core.js"></script>');
document.write('<script type="text/javascript" src="/js/DataPicker/ui/ui.datepicker.js"></script>');
document.write('<script type="text/javascript" src="/js/jquery.bgiframe.js"></script>');
document.write('<script type="text/javascript" src="/js/ui/jquery.ui.core.js"></script>');
document.write('<script type="text/javascript" src="/js/ui/jquery.ui.widget.js"></script>');
document.write('<script type="text/javascript" src="/js/ui/jquery.ui.mouse.js"></script>');
document.write('<script type="text/javascript" src="/js/ui/jquery.ui.position.js"></script>');
document.write('<script type="text/javascript" src="/js/ui/jquery.ui.dialog.js"></script>');
document.write('<script type="text/javascript" src="/js/ui/jquery.ui.dialog.js"></script>');

}

function setPage(page)
{
this.page = page;
}
function setPages(numberPages)
{
this.pages = numberPages;
}
function setDivTable(table)
{
this.DivTable = table;
}
function setDivPager(pager)
{
this.DivPager = pager;
}
function setStyle(style)
{
this.css = style;
}
function setPagerStyle(style)
{
this.pagercss = style;
}
function setRows(rows)
{
this.linhas = rows;
}
function setTableHeader(head)
{
this.arrheader = head;
}
function setDataFile(file)
{
this.dataFile = file;
}
function setSearchMode(value)
{
this.searchMode = value;
}
function setPageFilterValue(value)
{
this.pageFilterValue = value;
}
function setDivSearch(div)
{
this.DivSearch = div;
}
function setDivDel(div)
{
this.DivDel = div;
}
function setSearchtext(text)
{
this.searchText = text;
}
function setSeachFuntion(text)
{
this.searchFunction = text;
}
function getPage()
{
return this.page;
}
function getPages()
{
return this.pages;
}
function getDivTable()
{
return this.DivTable;
}
function getDivPager()
{
return this.DivPager;
}
function getStyle()
{
return this.css;
}
function getPagerStyle()
{
return this.pagercss;
}
function getArrayHeader()
{
return this.arrheader;
}
function getDataFile()
{
return this.dataFile;
}
function getSearchMode()
{
return this.searchMode;
}
function LoadNumberRows()
{
$.ajax({
type: "GET",
url: "AjaxController.php",
data: "action=GetNumberRows",
dataType: "json",
beforeSend: function(){
},
complete: function(){
},
success: function(msg){
setRows(parseInt(msg[0].Count));
}
});
}
function getNumberRows()
{
return this.linhas;
}
function getPageFilterValue()
{
return this.pageFilterValue;
}

function getDivSearch()
{
return this.DivSearch;
}
function getDivDel()
{
return this.DivDel;
}
function getSearchText()
{
return this.searchText;
}
function getSearchFunction()
{
return this.searchFunction;
}
function CreateDinamicTable(arrHeader,style,divTable,divPager,pagerStyle,phpFile,divSearch,divDel)
{
/********Seting Vars**********/
setStyle(style);
setDivTable(divTable);
setDivPager(divPager);
setDataFile(phpFile);
setPagerStyle(pagerStyle);
setTableHeader(arrHeader);
setDivSearch(divSearch);
setDivDel(divDel);
head = getArrayHeader().PageFilter;
for(i=0;i<head.length;i++)
{
if(head[i].Selected == "true")
setPageFilterValue(head[i].Value)
}
showTable();
BuildPager();
}
function showTable()
{
/*************************/
var divTable = getDivTable();
var lines = getPageFilterValue();
var page = getPage();
if(getSearchMode() == true)
{
dataToSend = getSearchText()+"&lines="+lines+"&page="+page;
}
else
{
dataToSend = "action=Load&lines="+lines+"&page="+page;
}
$.ajax({
type: "GET",
url: this.dataFile,
data: dataToSend,
dataType: "json",
beforeSend: function(){
$('#'+divTable).show();
$('#'+divTable).html('<img name="imgAjaxLoading3" id="imgAjaxLoading3" style="display: none;" alt="" src="">');
$('#imgAjaxLoading3').show();
$('#imgAjaxLoading3').attr("src","/images/loading2.gif");
},
complete: function(){
$('#imgAjaxLoading3').hide();


},
success: function(msg){
if(msg.length > 0)
{
var head = getArrayHeader().Header;
var genOpt = getArrayHeader().GeneralOptions;
setRows(msg[0].NumberRows);
var html = "<fieldset class=\"first\">"
+"<legend> Resultado: "+msg[0].data.length+"</legend>";
html +="<div id='gen'><p style=\"textAlign:left\">";
if(genOpt[0].AllowSearch == "true")
{
html +="<a href='javascript:Search()'><img src=\"AjaxTable/Images/search.gif\"/></a>";
}
if(genOpt[0].AllowAdd == "true")
{
html +="<a href='javascript:Add()'><img src=\"AjaxTable/Images/add.gif\"/></a>";
}
html +="</p></div><font face=\"verdana\"><table cellspacing=0 cellpadding=0 id='dg' class='"+getStyle()+"' >"
+"<tr>";
if(genOpt[0].BuildActions == "True")
{
html += "<td id='colActions' class='td-header' style='width:50px;' nowrap='true'>ACTIONS"
+"</td>"
}
for(i=0;i<head.length;i++)
{
innerStyle = "";
if(head[i].visible == "false")
{
innerStyle = "display:none;";
}
if(head[i].width)
{
innerStyle += "width:"+head[i].width+";";
}
html += "<td id='"+head[i]["Field"]+"' class='td-header' style='"+innerStyle+"' nowrap='true'>"+head[i]["Name"];
if(getSearchMode() == "false")
{
if(head[i].search == "true")
{
html +="<a href='javascript:Sort(\""+head[i].dataFieldName+"\",\"asc\")'><img src=\"AjaxTable/Images/arrowUp.gif\"/></a>&nbsp;<a href='javascript:Sort(\""+head[i].dataFieldName+"\",\"desc\")'><img src=\"AjaxTable/Images/arrowDown.gif\"/></a></td>";
}
}
}
html +="</tr>";
for(s=0;s<msg[0].data.length;s++)
{
var tdclass = "td-odd";
if(s%2==0)
{
tdclass = "td-even";
}
html += "<tr id='data"+s+"'>"
if(genOpt[0].BuildActions == "True")
{
html +="<td class='"+tdclass+"' id='Actions"+s+"'>"
+"<button onclick='delPath(\"data"+s+"\")' id=\"buttonDel"+s+"\" type=\"button\" style=\"width:20px;\">D</button>"
+"<button onclick='editPath(\"data"+s+"\")' id=\"buttonEdit"+s+"\" type=\"button\" style=\"width:20px;\">E</button>"
+"</td>"
}
for(i=0;i<head.length;i++)
{
innerStyle = "";
if(head[i].visible == "false")
{
innerStyle = "display:none;";
}
if(head[i].width)
{
innerStyle += "width:"+head[i].width+";";
}
html +="<td class='"+tdclass+"' style='"+innerStyle+"' id='"+head[i].Field+s+"'>"+msg[0].data[s][head[i].dataFieldName]+"</td>";

}
html +="</tr>"
}
html +="</table></fieldset>";
}else{
html="<fieldset class=\"first\"><legend><font class=\"smallblinkytext\">ERRO</font></legend><h1 class=\"blinkytext\">Erro a carregar dados<br>Por favor contacte o administrador de sistemas</h1></fieldset>";
}
$('#'+divTable).html(html);
}
});
}
function BuildPager()
{
var linesFilter = null;
head = getArrayHeader().PageFilter;
linesFilter = "<div id=\"PagerFilter\">"
+"<select id=\"ddlPagerList\" name=\"ddlPagerList\">";
for(i=0;i<head.length;i++)
{
if(head[i].Value == getPageFilterValue())
{
linesFilter += "<option selected=\"\" value=\""+head[i].Value+"\">"+head[i].Value+"</option>";
}else
{
linesFilter += "<option value=\""+head[i].Value+"\">"+head[i].Value+"</option>";
}
}

linesFilter +="</select><button onclick=\"ChangeLines()\" id=\"buttonShowPager\" type=\"button\">Filtrar</button>"
+"</div>";
lines = getPageFilterValue();
alert(getNumberRows());
numberRows = 105;
if(numberRows%lines == 0)
pages = (numberRows/lines);
else {
pages = parseInt((numberRows/lines))+1;
}
setPages(pages);
html = "<table frame='box' rules='all' class='"+getPagerStyle()+"'>"
+"<tbody><tr>";
if(page == 1)
{
html += "<td class='Back-admintable-ON'> &lt;&lt; </td>";
}else {
html += "<td class='Back-admintable'><a href='javascript:changePage(\""+lines+"\",\""+(parseInt(page)-1)+"\")';> &lt;&lt; </a></td>";
}
if(pages > 1)
{
for(i=1;i<=pages;i++)
{
if(i==page)
{
html += "<td class='Number-admintable-ON'>"+i+"</td>";
}else{
html += "<td class='Number-admintable'><a href='javascript:changePage(\""+lines+"\",\""+i+"\")';>"+i+"</a></td>";
}
}
}
if(page == pages)
{
html += "<td class='Back-admintable-ON'> &gt;&gt; </td>";
}else {
html += "<td class='Back-admintable'><a href='javascript:changePage(\""+lines+"\",\""+(parseInt(page)+1)+"\")';> &gt;&gt; </a></td>";
}
html += "<td class='Back-admintable'><a href='javascript:changePage(\""+numberRows+"\",\"1\")';> View ALL </a></td>";
html +="</tr></tbody></table>";
if(lines >= numberRows)
$("#"+getDivPager()).html(linesFilter);
else
$("#"+getDivPager()).html(linesFilter+html);
}
function changePage(lines,page)
{
setPage(page);
setPageFilterValue(lines);
BuildPager();
showTable();
}
function ChangeLines()
{
var pagerVal = $("#ddlPagerList option:selected").val();
setPage(1);
setPageFilterValue(pagerVal);
BuildPager();
showTable();

}
function Search()
{
html = "<fieldset class=\"first\"><legend>Pesquisar</legend>";
var head = getArrayHeader().Header;
for(i=0;i<head.length;i++)
{
if(head[i].search == "true")
{
html +="<fieldset class='second'><legend>"+head[i].Name+"</legend>"
+"<input type='text' size='31' maxlength='255' id='ddl"+head[i].Name+"' name='ddl"+head[i].Name+"'";
if(head[i].searchOptions[0].AutoComplete == "true")
{
html +="onkeyup=\"autoFill('ddl"+head[i].Name+"','"+head[i].dataFieldName+"','AutoComplete"+head[i].Name+"','"+head[i].searchOptions[0].AutoCompleteFunction+"')>"
+"<div id='AutoComplete"+head[i].Name+"' class='clientList'></div></fieldset>";
setSeachFuntion(head[i].searchOptions[0].searchFunction);
}else{
html +=">";
}
}
}
html += "</fieldset>";
$("#"+getDivSearch()).html(html);
$("#"+getDivSearch()).dialog({
resizable: false,
modal: true,
title: "<strong>Pesquisa</strong>",
closeOnEscape: false,
buttons: {
'Pesquisar': function() {
setSearchMode(true);
showTable();
$(this).dialog('close');

},
'Cancelar': function() {
$(this).dialog('close');
},
'Limpar': function() {
setSearchMode(false);
showTable();
$(this).dialog('close');
}
}
});
$("#"+getDivSearch()).dialog("open");
}

function autoFill(htmlField,dataField,div,autoCompleteAjaxFunction)
{
$.ajax({
type: "GET",
url: "AjaxController.php",
data: "action="+autoCompleteAjaxFunction+"&text="+$("#"+htmlField).val(),
dataType: "json",
beforeSend: function(){
var pos = $("#"+htmlField).offset();
var width = $("#"+htmlField).width();
var heigth = $("#"+htmlField).height();
//show the menu directly over the placeholder
$("#"+div).css( {"left": (pos.left) + "px", "top":pos.top+heigth+2 + "px"} );
$("#"+div).show('medium');
$("#"+div).html('<img name="imgAjaxLoading3" id="imgAjaxLoading3" style="display: none;" alt="" src="">');
$('#imgAjaxLoading3').show();
$('#imgAjaxLoading3').attr("src","/images/loading2.gif");
},
complete: function(){
$('#imgAjaxLoading3').hide('medium');
},
success: function(msg){
var html2 = "";
for(i=0;i<msg.length;i++)
{
var name = msg[i][dataField];
html2 += "<a href='javascript:void(0)' onclick=\"complete('"+htmlField+"','"+div+"','"+name+"')\">"+name+"</a><br>";
}
$("#"+div).html(html2);
}
});

}
function complete(htmlField,div,value)
{
$('#'+htmlField).val(value);
$('#'+div).hide('slow');
var text = "action="+getSearchFunction()+"&Field="+value;
setSearchtext(text);
}




I have posted all the code inside this js file im developing



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum