/** * @author Francesco */ /** * @class HistoryData */ function HistoryData(m, i, f, h) { this.mod = parseInt(m); this.istanza = i; this.nome_funzione = f; this.html = h; this.htmlCache = ""; this.args = new Array(); } /** * @class HistorySet */ function HistorySet() { this.browserHistory = new Array(); this.viewHistory = function() // Funzione di DEBUG { var tmp = ""; for (var i in this.browserHistory) tmp += (i + " - " + this.browserHistory[i].istanza + "." + this.browserHistory[i].nome_funzione) + "\n"; alert(tmp); } this.getBackHistory = function() { if (this.browserHistory.length <= 1) return; var getNow = new HistoryData(); getNow = this.browserHistory[this.browserHistory.length - 2]; if (getNow.html === true) { document.getElementById("content").innerHTML = getNow.htmlCache; try { this.browserHistory.pop(); } catch (e) {} return; } var istruzione = new String(getNow.istanza + "." + getNow.nome_funzione + "("); for (var k = 0; k < getNow.args.length; k++) { if (getNow.args[k] == "null" || getNow.args[k] == "undefined") istruzione += getNow.args[k]; else istruzione += "'" + getNow.args[k] + "'"; if ((k + 1) < getNow.args.length) istruzione += ","; } istruzione += ");"; try { this.browserHistory.pop();this.browserHistory.pop(); } catch (e) {} eval(istruzione.valueOf()); } } var _historyset = new HistorySet(); /** * @class AjaxModule */ function AjaxModule() {} AjaxModule.prototype.createXMLHttpRequest = function() { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (window.ActiveXObject) { var axoVersions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "Microsoft.XMLHttp"]; for (var i = 0; i < axoVersions.length; i++) { try { var xmlobj = new ActiveXObject(axoVersions[i]); return xmlobj; } catch (e) {} } } throw new Error("Impossibile inizializzare l'oggetto XMLHttp."); } AjaxModule.prototype.loadingSrc = "/immagini/loading2.gif"; AjaxModule.prototype.setLoadingSrc = function(src) { AjaxModule.prototype.loadingSrc = src; } AjaxModule.prototype.loadingTarget = document.body; AjaxModule.prototype.setLoadingTarget = function(target) { var err = new String("Target non valido, impossibile gestire correttamente la risposta!"); if (typeof(target) == "object" || typeof(target) == "function") { try { AjaxModule.prototype.loadingTarget = target; } catch (e) { throw new Error(err); } } else throw new Error(err); } AjaxModule.prototype.loadingGIF = function() { var contentHTML = ''; AjaxModule.prototype.loadingTarget.innerHTML = contentHTML; } AjaxModule.prototype.params = []; AjaxModule.prototype.target = document.body; AjaxModule.prototype.xmlhttp = AjaxModule.prototype.createXMLHttpRequest(); AjaxModule.prototype.clearParams = function() { AjaxModule.prototype.params = []; } AjaxModule.prototype.setTarget = function(target) { var err = new String("Target non valido, impossibile gestire correttamente la risposta!"); if (typeof(target) == "object" || typeof(target) == "function") { try { AjaxModule.prototype.target = target; } catch (e) { throw new Error(err); } } else throw new Error(err); } AjaxModule.prototype.setHistory = function() { var setNow = new HistoryData(); for(var i = 4; i < arguments.length; i++) setNow.args.push(arguments[i]); setNow.mod = arguments[0]; setNow.istanza = arguments[1]; setNow.nome_funzione = arguments[2]; setNow.html = arguments[3]; // Attiva Cache _historyset.browserHistory.push(setNow); } AjaxModule.prototype.sendRequest = function() { var pars = new String(); for (var i in AjaxModule.prototype.params) { pars += encodeURIComponent(i) + "="; pars += encodeURIComponent(AjaxModule.prototype.params[i]) + "&"; } AjaxModule.prototype.clearParams(); pars = pars.substr(0, (pars.length - 1)); AjaxModule.prototype.xmlhttp.send(pars); } AjaxModule.prototype.makeLoading = true; AjaxModule.prototype.makeRequest = function(sPage, mL) { if (mL === true) AjaxModule.prototype.makeLoading = false; else AjaxModule.prototype.makeLoading = true; AjaxModule.prototype.xmlhttp.open("POST", sPage, true); AjaxModule.prototype.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); AjaxModule.prototype.xmlhttp.onreadystatechange = AjaxModule.prototype.handleResponse; AjaxModule.prototype.sendRequest(); } AjaxModule.prototype.handleResponse = function() { if (AjaxModule.prototype.xmlhttp.readyState >= 1 && AjaxModule.prototype.xmlhttp.readyState <= 3) { if (AjaxModule.prototype.makeLoading === true) AjaxModule.prototype.loadingGIF(); } else if (AjaxModule.prototype.xmlhttp.readyState == 4) { if (AjaxModule.prototype.xmlhttp.status == 200) { var indB = _historyset.browserHistory.length - 1; var response = AjaxModule.prototype.xmlhttp.responseText; if (indB >= 0) _historyset.browserHistory[indB].htmlCache = response; if (typeof(AjaxModule.prototype.target) == "object") AjaxModule.prototype.target.innerHTML = response; else if (typeof(AjaxModule.prototype.target) == "function") AjaxModule.prototype.target(response); else throw new Error("Target non valido, impossibile gestire correttamente la risposta!"); } else { try { var contentHTML = "Errore durante il trasferimento dati."; contentHTML += "
" + AjaxModule.prototype.xmlhttp.statusText; contentHTML += " (" + AjaxModule.prototype.xmlhttp.status + ")"; document.getElementById(AjaxModule.prototype.target).innerHTML = contentHTML; } catch (e) {} } } } //--- Metodi per la lettura dinamica delle Form HTML AjaxModule.prototype.getSelected = function(opt) { var selected = new Array(); var index = 0; for (var intLoop = 0; intLoop < opt.length; intLoop++) { if ((opt[intLoop].selected) || (opt[intLoop].checked)) { index = selected.length; selected[index] = new Object; selected[index].value = opt[intLoop].value; selected[index].index = intLoop; } } return selected; } AjaxModule.prototype.outputSelected = function(opt, p) { var sel = AjaxModule.prototype.getSelected(opt); var strSel = ""; var cont = 0; for (var item in sel) { cont++; AjaxModule.prototype.params[p + "_" + cont] = sel[item].value; } AjaxModule.prototype.params["n_" + p] = cont; } AjaxModule.prototype.form_read = function(nome_form) { var oForm = document.getElementById(nome_form); for (var i = 0; i < oForm.elements.length; i++) { var oField = oForm.elements[i]; switch (oField.type) { case "checkbox" : case "radio" : if (oField.checked) AjaxModule.prototype.params[oField.id] = "1"; else AjaxModule.prototype.params[oField.id] = "0"; break; case "text" : case "hidden" : case "password" : case "textarea" : case "select-one" : AjaxModule.prototype.params[oField.id] = oField.value; break; case "select-multiple" : AjaxModule.prototype.outputSelected(oField.options, oField.id); break; } } }