/** * @author Francesco */ try { LLI.callBack("contributo_lib"); } catch (e) {} var destination_div = "content"; function Contributo(mod, istanza, nome) { this.init(mod, istanza, nome); this.script_path += "contributo/"; this.script_page = "contributo.php"; this.visualizza = function() { this.loadform("edt", 1, null); } this.inserisci = function() { this.setDefaults(); this.params["operazione"] = "inserisci"; this.setTarget(this.handleContentResponse); this.setHistory(this.mod, this.istanza, "inserisci", false); this.makeRequest(this.script_path + "forms.php"); } this.loadform = function(tipo, comando, operazione) { this.setDefaults(); switch (tipo) { case "edt" : var items = 0; try { items = parseInt(getById("items_pag").value); if (items < 5) items = 5; } catch (e) { items = 100; } if (this.mod == 6) // Profilo { try { this.params["idg_profilo"] = getVal("idg_profilo"); } catch (e) {} } this.params["operazione"] = "modifica"; this.params["pag"] = parseInt(comando); this.params["items_pag"] = items; var s_opz = "tutti"; try { switch (getById("scad_opz").value) { case "online" : case "scaduti" : case "approvati" : case "non_approvati" : case "bozze" : case "orfani" : s_opz = getVal("scad_opz"); } } catch (e) { s_opz = "tutti"; } this.params["scad_opz"] = s_opz; this.setTarget(this.handleContentResponse); try { this.form_read("visualizza_form"); } catch (e) {} this.makeRequest(this.script_path + "visualizza.php"); break; case "upl" : this.setTarget(getById("add_div")); this.setLoadingTarget(getById("add_div")); this.params["operazione"] = "upload"; this.params["comando"] = comando; this.params["tipo_operazione"] = operazione; this.makeRequest(this.script_path + "forms.php"); break; case "lnk" : this.setTarget(getById("add_div")); this.setLoadingTarget(getById("add_div")); this.params["operazione"] = "addlink"; this.makeRequest(this.script_path + "forms.php"); break; } this.setHistory(this.mod, this.istanza, "loadform", false, tipo, comando, operazione); } this.readform = function() { var tmp = new String(getVal("titolo")); if (tmp.length > 2) { getById("titolo").style.borderColor = "gray"; this.params["titolo"] = getVal("titolo"); } else if (getById("titolo").type == "hidden") this.params["titolo"] = ""; else { getById("titolo").style.borderColor = "#FF0000"; getById("titolo").focus(); throw new Object({id:"titolo",message:"Sono richiesti almeno 2 caratteri."}); } tmp = new String(getVal("abstract")); if (tmp.length == 0 || tmp.length > 2) { document.getElementById("abstract").style.borderColor = "gray"; this.params["abstract"] = getVal("abstract"); } else { getById("abstract").style.borderColor = "#FF0000"; getById("abstract").focus(); throw new Object({id:"abstract",message:"Formato non valido."}); } if (getById("contenuto").type != "hidden") { tmp = new String(tinyMCE.get("contenuto").getContent()); if (tmp.length > 2) this.params["contenuto"] = tmp; else throw new Object({id: "contenuto", message: "Sono richiesti almeno 2 caratteri."}); } else this.params["contenuto"] = ""; if (check("data_cont_g", /^[0-9]{1,2}$/)) this.params["data_cont_g"] = getVal("data_cont_g"); else throw new Object({id:"data_cont_g",message:"Formato non valido."}); if (check("data_cont_m", /^[0-9]{1,2}$/)) this.params["data_cont_m"] = getVal("data_cont_m"); else throw new Object({id:"data_cont_m",message:"Formato non valido."}); if (check("data_cont_a", /^[0-9]{4}$/)) this.params["data_cont_a"] = getVal("data_cont_a"); else throw new Object({id:"data_cont_a",message:"Formato non valido."}); if (check("data_scad_g", /^[0-9]{1,2}$/)) this.params["data_scad_g"] = getVal("data_scad_g"); else throw new Object({id:"data_scad_g",message:"Formato non valido."}); if (check("data_scad_m", /^[0-9]{1,2}$/)) this.params["data_scad_m"] = getVal("data_scad_m"); else throw new Object({id:"data_scad_m",message:"Formato non valido."}); if (check("data_scad_a", /^[0-9]{4}$/)) this.params["data_scad_a"] = getVal("data_scad_a"); else throw new Object({id:"data_scad_a",message:"Formato non valido."}); this.params["approvato"] = getById("approvato").checked; try { this.params["tags"] = getVal("tags"); } catch (e) {} try { this.params["delega"] = getVal("delega"); } catch (e) { this.params["delega"] = "false"; } if (ListaCampi[this.mod] instanceof CampiDinamici) {} else return; // Determinazione campi variabili var id_campi = new String(getById("id_campi").value); var campi = id_campi.split("###"); for (var i in campi) { try { var campo = campi[i].split(":"); var tsel = getVal("tsel_" + campo[0]); var valore = new String(getById("id_label_" + campo[0]).value); if (parseInt(campo[1]) == 1) { if (valore.length < 1 || valore.valueOf() == "no_selection") { var labelname = new String(getById("labelname_" + campo[0]).innerHTML); throw new Object({id:"id_label_" + campo[0],message:"Il campo " + labelname.valueOf() + " e' obbligatorio.",ds:true}); } } switch (tsel) { case "msel" : this.outputSelected(getById("id_label_" + campo[0]).options, "id_label_" + campo[0]); break; case "std" : case "sel" : case "mliv4" : case "radio" : if (getById("id_label_" + campo[0]).value != "no_selection") this.params["id_label_" + campo[0]] = valore; break; case "mliv" : case "mliv2" : this.params["id_label_" + campo[0]] = getVal("sonvalue_" + campo[0]); break; case "mliv3" : this.outputSelected(getById("sonvalue_" + campo[0]).options, "m3_" + campo[0]); break; case "dyn" : var nnc = parseInt(getVal("n_campi_" + campo[0])); this.params["n_campi_" + campo[0]] = nnc; this.params["tipo_uscita_" + campo[0]] = getVal("tipo_uscita_" + campo[0]); for (var z = 1; z <= nnc; z++) this.params[campo[0] + "_campo_" + z] = getVal(campo[0] + "_campo_" + z); break; } } catch (e) { if (e.ds == true) { lightpopup(e.message, e.id); return false; } } } this.params["id_campi"] = id_campi; } this.checkCatId = function() { var old_id, liv = 1, idp_categoria = 0, prefix = new String("sel_cat_"); for (var i = 1; true; i++) { try { old_id = getById(prefix + i).value; } catch (e) { old_id = null; } if (old_id != null && old_id != "no_selection") { liv = i + 1; idp_categoria = old_id; } if (old_id == null || old_id == undefined) break; } return idp_categoria; } this.nuovo_contributo = function(bozza) { try { this.setDefaults(); var idcp = this.checkCatId(); if (this.mod == 1 && idcp <= 0) // Manuali tecnici throw new Object({id:"sel_cat_1",message:"Scegliere una categoria prego."}); this.params["id_categoria"] = idcp; var check_form = this.readform(); if (check_form == false) return; this.params["operazione"] = "inserisci"; this.params["bozza"] = parseInt(bozza); this.makeRequest(this.script_path + this.script_page); } catch (err) { lightpopup(err.message, err.id); } } this.carica = function(id) { this.setDefaults(); this.params["operazione"] = "carica"; this.params["id_cont"] = parseInt(id); this.setTarget(this.handleContentResponse); this.setHistory(this.mod, this.istanza, "carica", false, id); this.makeRequest(this.script_path + "modifica.php"); } this.cancella = function(id) { if (confirm("Vuoi davvero eliminare questo elemento ?")) this.conf_cancella(id); } this.conf_cancella = function(id) { this.setDefaults(); this.params["operazione"] = "cancella"; this.params["id_cont"] = parseInt(id); this.makeRequest(this.script_path + "cancella.php"); } this.read_cond = function() { var cond = document.getElementById('condomini').options; var res = new String(); for (var i = 0; i < cond.length; i++) if (cond[i].selected) res += cond[i].value + ","; return res.substr(0, res.length - 1); } this.modifica = function(id, bozza) { try { this.setDefaults(); var idcp = parseInt(getVal("id_padre")); if (this.mod == 1 && idcp <= 0) // Manuali tecnici throw new Object({id:"sel_cat_1",message:"Scegliere una categoria prego."}); this.params["id_categoria"] = idcp; var check_form = this.readform(); if (check_form == false) return; try { this.params["condomini"] = this.read_cond(); } catch (e) { } this.params["operazione"] = "modifica"; this.params["id_cont"] = parseInt(id); this.params["bozza"] = parseInt(bozza); this.makeRequest(this.script_path + "modifica.php"); } catch (err) { lightpopup(err.message, err.id); } } this.approva = function(id, btnsfx) { this.setDefaults(); this.params["operazione"] = "approva"; this.params["id_cont"] = parseInt(id); this.params["btnsfx"] = btnsfx; destination_div = "approva_btn_" + btnsfx; getById(destination_div).disabled = true; getById(destination_div).value = "Modifica in corso ..."; this.setTarget(this.handleRapidResponse); this.makeRequest(this.script_path + this.script_page, true); } this.salva_bozza = function(id, btnsfx) { this.setDefaults(); this.params["operazione"] = "salva_bozza"; this.params["id_cont"] = parseInt(id); this.params["btnsfx"] = btnsfx; destination_div = "salva_bozza_btn_" + btnsfx; getById(destination_div).disabled = true; getById(destination_div).value = "Modifica in corso ..."; this.setTarget(this.handleRapidResponse); this.makeRequest(this.script_path + this.script_page, true); } this.lista_elementi = function(id) { this.setDefaults(); this.params["operazione"] = "listafile"; this.params["id_cont"] = parseInt(id); destination_div = "lista_elementi"; this.setTarget(getById(destination_div)); this.setLoadingTarget(getById(destination_div)); this.makeRequest(this.script_path + this.script_page); } this.inviaFile = function() { getById("invia_btn").innerHTML = "Invio in corso ..."; getById("form_file").submit(); } this.carica_figli = function(id_label, diretto, ts) { if (diretto == null || diretto == undefined) diretto = "false"; this.setDefaults(); this.setTarget(getById("sons_" + parseInt(id_label))); this.setLoadingTarget(getById("sons_" + parseInt(id_label))); this.params["operazione"] = "carica_figli"; this.params["id_label"] = parseInt(id_label); this.params["id_son"] = parseInt(getVal("id_label_" + parseInt(id_label))); this.params["diretto"] = diretto; this.params["tipo_select"] = ts; this.makeRequest(this.script_path + "forms.php"); } this.associa_link = function(ids) { this.setDefaults(); this.setTarget(getById("add_div")); this.setLoadingTarget(getById("add_div")); this.params["operazione"] = "associa_link"; this.params["id_links"] = ids; var id_links = new String(ids); id_links = id_links.split(","); for (var i = 0; i < id_links.length; i++) { var id = id_links[i]; this.params["link_" + id] = getById("associato_" + id).checked ? "1" : "0"; } this.makeRequest(this.script_path + "link.php"); } this.genera_campi = function(id_label) { n_campi = parseInt(getVal("n_campi")); this.setDefaults(); this.setTarget(getById("add_fields_" + parseInt(id_label))); this.setLoadingTarget(getById("add_fields_" + parseInt(id_label))); this.params["operazione"] = "genera_campi"; this.params["n_campi"] = n_campi; this.params["id_label"] = parseInt(id_label); this.makeRequest(this.script_path + "forms.php"); } this.aggiungi_campo = function(id_label) { var table = getById("tbody_" + id_label); var n_campi = parseInt(getVal("n_campi_" + id_label)); var row = document.createElement("tr"); var td1 = document.createElement("td"); td1.appendChild(document.createTextNode("Campo " + (n_campi + 1) + ": ")); var td2 = document.createElement("td"); var input = document.createElement("input"); input.type = "text"; input.size = 40; input.maxLength = 255; input.id = id_label + "_campo_" + (n_campi + 1); input.name = input.id; td2.appendChild(input); var aaa = document.createElement("a"); aaa.href = "javascript:" + this.istanza + '.elimina_campo("' + id_label + '_campo_' + (n_campi + 1) + '");'; aaa.innerHTML = "[X]"; var td3 = document.createElement("td"); td3.appendChild(aaa); row.appendChild(td1); row.appendChild(td2); row.appendChild(td3); table.appendChild(row); getById("n_campi_" + id_label).value = parseInt(getVal("n_campi_" + id_label)) + 1; } this.elimina_campo = function(campo) { getById(campo).value = ""; var ie = (navigator.appName.indexOf("Internet Explorer") != -1) ? 1 : 0; if (!ie) { var style = 'background-color: #D2D2D2;'; getById(campo).setAttribute("style", style); getById(campo).setAttribute("readonly", true); } else { getById(campo).style.backgroundColor = "#D2D2D2"; getById(campo).readOnly = true; } } this.aggiungi_lettura = function() { this.setDefaults(); this.setTarget(getById("add_letture")); this.setLoadingTarget(getById("add_letture")); this.params["operazione"] = "aggiungi_lettura"; this.makeRequest(this.script_path + "letture_gas.php"); } this.inserisci_lettura = function() { var cod = new String(getVal("cod_lettura")); var val = new String(getVal("val_lettura")); if (cod.length <= 0) { alert("Il Codice lettura e' un campo obbligatorio."); return; } if (val.length <= 0) { alert("Il Valore lettura e' un campo obbligatorio."); return; } this.setDefaults(); this.setTarget(getById("add_letture")); this.setLoadingTarget(getById("add_letture")); this.params["codice_lettura"] = cod.valueOf(); this.params["valore_lettura"] = val.valueOf(); this.params["operazione"] = "inserisci_lettura"; this.makeRequest(this.script_path + "letture_gas.php"); window.location.replace("#letture_ancora"); } this.salva_lettura = function(id_lettura) { var cod = new String(getVal("cod_lettura")); var val = new String(getVal("val_lettura")); if (cod.length <= 0) { alert("Il Codice lettura e' un campo obbligatorio."); return; } if (val.length <= 0) { alert("Il Valore lettura e' un campo obbligatorio."); return; } this.setDefaults(); this.setTarget(getById("add_letture")); this.setLoadingTarget(getById("add_letture")); this.params["codice_lettura"] = cod.valueOf(); this.params["valore_lettura"] = val.valueOf(); this.params["id_lettura"] = parseInt(id_lettura); this.params["operazione"] = "salva_lettura"; this.makeRequest(this.script_path + "letture_gas.php"); window.location.replace("#letture_ancora"); } this.modifica_lettura = function(id_lettura) { this.setDefaults(); this.setTarget(getById("add_letture")); this.setLoadingTarget(getById("add_letture")); this.params["id_lettura"] = parseInt(id_lettura); this.params["operazione"] = "modifica_lettura"; this.makeRequest(this.script_path + "letture_gas.php"); } this.cancella_lettura = function(id_lettura) { if (confirm("Vuoi davvero eliminare la lettura?")) this.conf_cancella_lettura(id_lettura); } this.conf_cancella_lettura = function(id_lettura) { this.setDefaults(); this.setTarget(getById("add_letture")); this.setLoadingTarget(getById("add_letture")); this.params["id_lettura"] = parseInt(id_lettura); this.params["operazione"] = "cancella_lettura"; this.makeRequest(this.script_path + "letture_gas.php"); } this.deleteAssoc = function(idc, idu) { if (confirm("Vuoi davvero cancellare l'associazione?")) this.confDeleteAssoc(idc, idu); } this.confDeleteAssoc = function(idc, idu) { this.setDefaults(); this.setTarget(this.handleDelAssoc); this.setLoadingTarget(getById("condomini_associati")); this.params["idc"] = parseInt(idc); this.params["idu"] = parseInt(idu); this.params["operazione"] = "cancella_associazione"; this.makeRequest(this.script_path + "cancella.php"); } this.handleDelAssoc = function(response) { response = new String(response); response = decodeUrlVars(response); alert(response['message']); document.getElementById('condomini_associati').innerHTML = decodeURIComponent(response['lista']); } this.stampa_letture = function() { this.setDefaults(); this.setTarget(this.handleLetture); this.setLoadingTarget(getById("stampa_letture")); this.params["operazione"] = "stampa_letture"; this.makeRequest(this.script_path + "letture_gas.php"); } this.handleLetture = function(response) { getById("stampa_letture").innerHTML = response; window.location.replace("#letture_ancora"); } this.handleRapidResponse = function(response) { var result = decodeUrlVars(response); switch (result["comando"]) { case "approva" : destination_div = "approva_btn_" + result["btnsfx"]; getById(destination_div).disabled = false; if (parseInt(result["risultato"]) == 1) setVal(destination_div, "Disapprova"); else setVal(destination_div, "Approva"); eval(result["istanza"] + ".loadform('edt', 1, null);"); break; case "salva_bozza" : destination_div = "salva_bozza_btn_" + result["btnsfx"]; getById(destination_div).disabled = false; if (parseInt(result["risultato"]) == 1) setVal(destination_div, "Salva come definitivo"); else setVal(destination_div, "Salva come bozza"); eval(result["istanza"] + ".loadform('edt', 1, null);"); break; } } this.handleContentResponse = function(response) { getById("content").innerHTML = response; if (getById("contenuto") != null && getById("contenuto") != undefined) { if (getById("contenuto").type != "hidden") { tinyMCE.init({mode:"exact", elements:"contenuto", theme:"advanced", plugins:"table,style,layer", theme_advanced_toolbar_location:"top", theme_advanced_layout_manager:"SimpleLayout", theme_advanced_buttons1:"removeformat,bold,italic,underline,strikethrough,separator,bullist,numlist,outdent,indent,separator,sup,sub,separator,forecolor,separator,link,unlink,separator,undo,redo,separator,code", theme_advanced_buttons2:"", language:"it", width:"500"}); } } } } Contributo.prototype = new StandardModule(); Contributo.prototype.constructor = Contributo;