/* esegue la get di e richiama la funzione il cui nome è in */ function getUrl( url, callbackName ) { url += getLastSearchParam( url ); // esecuzione della richiesta req = getXmlHttp(); if(req!=null) { req.onreadystatechange = eval( callbackName ); //alert( url + ", " + callbackName ); //req.onreadystatechange = callbackName; req.open( "get", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send( null ); } startLoading(); } /* funziona che ritorna se nella url è presente il parametro lastSearch=true e lo propaga alla action */ var doneLastSearch = false; function getLastSearchParam( url ) { if( !doneLastSearch ) { doneLastSearch = true; var concatSymbol = "?"; if( url.indexOf("?") >0 ) concatSymbol = "&"; if( (window.location + "").indexOf( "lastSearch=true" ) >= 0 ) { //alert( "do last search" ); return concatSymbol + "lastSearch=true"; } } return ""; } function remove(s, t) { /* ** Remove all occurrences of a token in a string ** s string to be processed ** t token to be removed ** returns new string */ i = s.indexOf(t); r = ""; if (i == -1) return s; r += s.substring(0,i) + remove(s.substring(i + t.length), t); return r; } /* funzione cross-browser per ottenere l'oggetto XmlHttpRequest */ function getXmlHttp() { req = null; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } return req; } function Contains( obj ) { for ( i in this ) if ( this[i] == obj ) return true; return false; }//Contains /* fa il trim di una stringa */ function trim(stringa) { reTrim = /\s+$|^\s+/g; return stringa.replace(reTrim,""); } /* fa partire il loading */ function startLoading() { if(document.getElementById("loading")) document.getElementById("loading").style.display = "inline" } /* ferma il loading */ function stopLoading() { if(document.getElementById("loading")) document.getElementById("loading").style.display = "none" } /* controlla il risultato ed eventualmente visualizza il messaggio di chiave duplicata */ function checkPK() { if (req.readyState == 4) { if (req.status == 200) { //alert("checkPK"); var resText = trim(req.responseText); if(resText != null) { var result = resText; if( result.length > 0 ) { document.getElementById("warningMessage").innerHTML=result; document.getElementById("warningMessage").style.display= "block"; window.setTimeout('document.getElementById("warningMessage").style.display="none"',2000); } } } else { //todo: completare la visualizzazione dei messaggi di errore //createErrorMessage( req.responseText ); //alert("stopping..."); stopLoading(); return false; } //alert("stopping..."); stopLoading(); return true; } } /************** QueryResult JS Object *******************************************************************************/ QueryResult = function( columns, data, currentPage, totItems, totPages, searchUrl, sortColumn, mode ) { this.columns = columns; this.data = data; this.currentPage = currentPage; this.totItems = totItems; this.totPages = totPages; this.sortColumn = sortColumn; this.mode = mode; if( searchUrl.indexOf( "?" ) < 0 ) searchUrl += "?"; else searchUrl += "&"; this.searchUrl = searchUrl; } QueryResult.prototype.getSortColumn = function () { return this.sortColumn; } QueryResult.prototype.setMode = function (mode) { this.mode = mode; } QueryResult.prototype.getMode = function () { return this.mode; } QueryResult.prototype.getColumns = function () { return this.columns; } QueryResult.prototype.getData = function () { return this.data; } QueryResult.prototype.getCurrentPage = function () { return this.currentPage; } QueryResult.prototype.getTotItems = function () { return this.totItems; } QueryResult.prototype.getTotPages = function () { return this.totPages; } QueryResult.prototype.getSearchUrl = function () { return this.searchUrl; } QueryResult.prototype.getPaginazione = function () { var orderedSearchUrl = this.searchUrl; //alert(orderedSearchUrl.indexOf("lastSearch=true")); //orderedSearchUrl = remove(orderedSearchUrl, "lastSearch=true"); if( this.getSortColumn() != null && this.getSortColumn() != "" ) { orderedSearchUrl += "of=" + this.getSortColumn(); if( this.getMode() == null ) orderedSearchUrl += "&om=desc"; else orderedSearchUrl += "&om="+this.getMode(); orderedSearchUrl += "&"; //alert(orderedSearchUrl); } var firstLink = orderedSearchUrl + "p=0"; var prevLink = orderedSearchUrl + "p=" + (this.getCurrentPage() - 1); var nextLink = orderedSearchUrl + "p=" + (this.getCurrentPage() + 1); var lastLink = orderedSearchUrl + "p=" + (this.getTotPages() - 1); var result = "
"+ ""+ ""+ ""+ "" + "" + "" + "" + "
"+ "
" + this.getTotItems() + " Risultati
" + "
" + (this.getCurrentPage() > 0 ? "<< prima " : "" ) + (this.getCurrentPage() > 0 ? "< precedente " : "" ) + " Pagina " + (this.getTotPages() > 0 ? this.getCurrentPage()+1 : 0) + " di " + this.getTotPages() + (this.getCurrentPage() < this.getTotPages()-1 ? " successiva >" : "" ) + (this.getCurrentPage() < this.getTotPages()-1 ? " ultima >>" : "" ) + "
" + "
" + "
Vai a: " + "" + "
" + "
" + "
" + "
" + "" + ""+ ""; for ( var i = 0; i " + this.getColumns()[i][0] + ""; else result += ""; else result += ""; else result += " "; result += ""; for ( var i = 0; i < this.data.length; i++) { result += ""; for (var j = 1; j "; } result += ""; } result += "" + "" + "
"; result += "
" + "" + "" + "" + ""+ "" + "" + "" + "
" + "
" + this.getTotItems() + " Risultati
" + "
" + (this.getCurrentPage() > 0 ? "<< prima " : "" ) + (this.getCurrentPage() > 0 ? "< precedente " : "" ) + " Pagina " + (this.getTotPages() > 0 ? this.getCurrentPage()+1 : 0) + " di " + this.getTotPages() + (this.getCurrentPage() < this.getTotPages()-1 ? " successiva >" : "" ) + (this.getCurrentPage() < this.getTotPages()-1 ? " ultima >>" : "" ) + "
" + "
" + "
Vai a: " + "" + "
" + "
" + "
"; return result; }