/* * javascrp super class * to be used as follows * function some_extenson_class_name(name,parent){ * general.call(this,name,parent); * ... * ... * //if the method needs extenstion than, or it can be overwritten from scrach * this.init = function(){new general(this.name).init.call(this); ...} * this.show = function(){new general(this.name).show.call(this); ...} * } */ function general(name, parent){ this.name = name; this.parent = parent; this.inner = make_name(this.name)+"_inner"; this.inner_status = make_name(this.name)+"_inner_status"; this.init = function(){ this.data = new Array(); this.data.sg = new general("tmp").sg; } this.load = function(what){ // alert("general load "+this.prefix()); this.sg("what",[],what); for(var i in what){ this.data.sg(i,"",e(what[i])); } this.loaded(true); } this.loaded = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_loaded", false, value):this.sg("_loaded", false);}; this.to_send = function(){ try{ if(this.data.sg_var) return this.data.sg_var; return o2a(this.data); }catch(err){alert("general.to_send() "+err);} // return o2a(this.data); } this.after_get = function(what){if(what && what["status"] && what["status"]==1){this.load(what["data"]);} else {this.load([]);} this.loaded(true);this.show();} this.after_save = function(what){if(what && what["status"] && what["status"]==1){this.load(what["data"]);};this.show();} this.show = function(){ if(innerHTML(this.inner,this.draw())){ show(this.inner); } } this.show_inactive = function(what){ if(get_element(this.inner)){ var p = getElementPosition(this.inner); innerHTML("inactive_inner","
"+what+"
"); get_element("inactive_inner").style.width = p.width+"px"; get_element("inactive_inner").style.height = p.height+"px"; show("inactive_inner",p.left,p.top); } } this.to_show_status = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_to_show_status", true, value):this.sg("_to_show_status", true);}; this.show_status = function(value){ if(get_element(this.inner_status) && this.to_show_status()){ innerHTML(this.inner_status,value); } } this.hide_inactive = function(){ hide("inactive_inner"); } this.draw = function(){ var r = ""; r += draw_analized_object(this); return r; } /** * sg stands for setter getter */ this.sg = function(feild,default_value,value){ try{ if(typeof(this)=="object" && feild!="sg" && feild!="asg" && feild!="sg_var"){ if(typeof(this.sg_var)=="undefined") this.sg_var = []; if(typeof(value)!="undefined"){ this.sg_var[feild] = value; } if(typeof(default_value)=="undefined"){ default_value = ""; } if(typeof(this.sg_var[feild])=="undefined") return default_value; return this.sg_var[feild]; } }catch(err){alert("general.sg() "+err);} } this.f = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_f", "af.php", value):this.sg("_f", "af.php");} this.prefix = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_prefix", "", value):this.sg("_prefix", "");} this.gl = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_gl", "", value):this.sg("_gl", "");} this.count = function(value){return parseInt((typeof(value)!="undefined" && value!=null)?this.sg("_count", 0, value):this.sg("_count", 0));}; this.limit1 = function(value){return parseInt((typeof(value)!="undefined" && value!=null)?this.sg("_limit1", 0, value):this.sg("_limit1", 0));}; this.limit2 = function(value){return parseInt((typeof(value)!="undefined" && value!=null)?this.sg("_limit2", 5, value):this.sg("_limit2", 5));}; this.order = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_order", [], value):this.sg("_order", []);}; this.client_registry_id = function(){ try{return this.parent.client_registry_id();}catch(err){alert("general.client_registry_id() "+err)} return 0;} this.client_id = function(){ try{return this.parent.client_id()}catch(err){alert("general.client_id() "+err)}; return 0;} this.recipients_client_list_table_name = function(){ try{ return this.parent.recipients_client_list_table_name()}catch(err){ alert("general.recipients_client_list_table_name() "+err)}; return '';} this.contactbook_client_lists_id = function(){ try{ return this.parent.contactbook_client_lists_id()}catch(err){ alert("general.contactbook_client_lists_id() "+err)}; return '';} this.web_auth_id = function(){ try{ return this.parent.web_auth_id()}catch(err){ alert("general.web_auth_id() "+err)}; return '';} this.session = function(){ try{ return this.parent.session()}catch(err){ alert("general.session() "+err)}; return '';} this.host = function(){ try{ return document_host }catch(err){ alert("general.host() "+err)}; return '';} this.logout = function(){ try{ if(this.parent && this.parent.logout && typeof(this.parent.logout)=="function"){return this.parent.logout();} }catch(err){ alert("general.logout() "+err)}; return;} this.pagination = function(){ var r=""; if(this.count()>0){ r += "
"; if(this.limit1()<=0){ this.limit1(0); r += "
«
"; } else { r += "
«
"; } r += "
("+(this.limit1()+1)+"-"+(this.limit1()+this.limit2())+")/"+this.count()+"
"; if((this.limit1()+this.limit2())>=this.count()){ r += "
»
"; } else { r += "
»
"; } r += "
"; } return r; } this.prepare_data = function(forma){ //alert("prepare_data 1"); if(this.data_type && forma){ //alert("prepare_data 2"); for(var i in this.data_type){ //alert("prepare_data 3"); if(this.data_type[i].editable()=="true"){ switch(this.data_type[i].type()){ case "atext": var tmp = unserialize(d((this.data.sg(this.data_type[i].field())!="")?this.data.sg(this.data_type[i].field()):this.data_type[i].default_value())); for(var j in tmp){ if(forma[this.data_type[i].field()+"_"+j]){ tmp[j] = (forma[this.data_type[i].field()+"_"+j].value); } } this.data.sg(this.data_type[i].field(),"",e(serialize(tmp))); break; case "set": var tmp = new Array(); if(forma[this.data_type[i].field()]){ for (var j = 0; j < forma[this.data_type[i].field()].options.length; j++){ if(forma[this.data_type[i].field()].options[j].selected){ tmp[tmp.length] = forma[this.data_type[i].field()].options[j].value; } } } this.data.sg(this.data_type[i].field(),"",e(tmp.join(","))); break; case "radio":case "checkbox": if(this.data_type[i].type()=="checkbox" && typeof(this.data_type[i].length_set())=="object" && count(o2a(this.data_type[i].length_set()))==2 ){ var set = o2a(this.data_type[i].length_set()); var tmp = []; for(var j in set) tmp.push(j); this.data.sg(this.data_type[i].field(),"",set[tmp[0]]); if(forma[this.data_type[i].field()]) if(forma[this.data_type[i].field()].checked) this.data.sg(this.data_type[i].field(),"",set[tmp[1]]); } else { var tmp = new Array(); if(forma[this.data_type[i].field()]){ if(forma[this.data_type[i].field()].checked){ tmp[tmp.length] = forma[this.data_type[i].field()].value; } else { for (var j = 0; j < forma[this.data_type[i].field()].length; j++){ if(forma[this.data_type[i].field()][j].checked){ tmp[tmp.length] = forma[this.data_type[i].field()][j].value; } } } } this.data.sg(this.data_type[i].field(),"",e(tmp.join(","))); } break; default: if(forma[this.data_type[i].field()]){ this.data.sg(this.data_type[i].field(),"",e(forma[this.data_type[i].field()].value)); } break; } } } } } this.load_data_type = function(what){ this.data_type = new Array(); for(var i in what){ this.data_type[i] = new myforma(this.name+".data_type['"+i+"']",this); this.data_type[i].load(what[i]); } } this.get_data_type = function(field){ if(this.data_type && this.data_type[field]){ return this.data_type[field]; }else {alert("Error trying to retreive non existing field "+field+" from data_type of the object "+this.name);} return new myforma("tmp",this); } this.getting_data_types = function(value){ if(typeof(value)!="undefined" && value!=null){ if(value==true){ this.show_inactive("

getting

"); } else { this.hide_inactive(); } } return (typeof(value)!="undefined" && value!=null)?this.sg("_getting_data_types", false, value):this.sg("_getting_data_types", false); }; this.getting = function(value){ if(typeof(value)!="undefined" && value!=null){ if(value==true){ this.show_inactive("

getting

"); } else { this.hide_inactive(); } } return (typeof(value)!="undefined" && value!=null)?this.sg("_getting", false, value):this.sg("_getting", false); }; this.checking = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_checking", false, value):this.sg("_checking", false);}; this.saving = function(value){ if(typeof(value)!="undefined" && value!=null){ if(value==true){ this.show_inactive("

saving

"); } else { this.hide_inactive(); } } return (typeof(value)!="undefined" && value!=null)?this.sg("_saving", false, value):this.sg("_saving", false); }; this.get_data_types = function(){ this.getting_data_types(true); kd(this.f()+"?f=get_"+this.prefix()+"_data_types&p="+e(a.serialize(o2a({"id":"new"})))+"&wi="+this.web_auth_id()+"&ws="+this.session()+"&host="+this.host(), function(g,aaa){ eval("var what="+g+";"); aaa.getting_data_types(false); if(what){ if(what["status"]==1){ aaa.load_data_type(what["data"]); aaa.show(); } handle_status(what["status"],what["mesg"]); } }, this); } this.get = function(){ try{ this.getting(true); kd(this.f()+"?f=get_"+this.prefix()+"&p="+e(a.serialize(this.to_send()))+"&wi="+this.web_auth_id()+"&ws="+this.session()+"&host="+this.host(), function(g,aaa){ try{ eval("var what="+g+";"); aaa.getting(false); //should be set in after_get if(what){ if(what["status"]<=-1000) { alert(what["mesg"]); aaa.logout(); return;} aaa.after_get(what); handle_status(what["status"],what["mesg"]); } else aaa.getting(false); }catch(err){alert("general.get.return.function() "+err)} }, this); }catch(err){alert("general.get() "+err)} }; this.check_for_uniqueness = function(field, value){ value = trim(value); if(value=="") return; this.checking(true); kd(this.f()+"?f=check_"+this.prefix()+"&p="+e(a.serialize(o2a({"field":e(field),"value":e(value),"id":this.data.sg("id")})))+"&wi="+this.web_auth_id()+"&ws="+this.session()+"&host="+this.host(), function(g,aaa){ try{ eval("var what="+g+";"); if(what){ if(what["status"]<=-1000) { aaa.checking(false); alert(what["mesg"]); aaa.logout(); return;} if(what["status"]==1){ innerHTML(aaa.get_data_type(field).inner_status, "");//HEAVY CHECK MARK aaa.checked.sg(field,false,true); } else { innerHTML(aaa.get_data_type(field).inner_status,"/,"")+"» χρησιμοποιείται, πρέπει να εσάγετε διαφορετικό «"+aaa.get_data_type(field).onoma().replace(//,"")+"»\">χρησιμοποιείται "); aaa.checked.sg(field,false,false); } handle_status(what["status"],what["mesg"]); } aaa.checking(false); }catch(err){alert("general.check_for_uniqueness.return.function() "+err)} }, this); } this.can_save = function(forma){ if(this.checked){ for(var i in this.checked.sg_var){ if(this.checked.sg(i,true)==false){ alert("checking_correct_problems"); if(forma && forma[i]) forma[i].focus(); return false; } } } return true; }; this.change = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_change", "", value):this.sg("_change", "");}; this.cross_check_with_original = function(){ if(this.data && this.original){ var change = this.change(); if(this.data_type){ for(var i in this.data.sg_var){ if(this.data_type[i]){ if(this.data.sg(i,"")!=this.original.sg(i,"") && this.get_data_type(i).type()!="hidden" && this.get_data_type(i).type()!="password" && this.get_data_type(i).type()!="image"){ var original = d(this.original.sg(i,"")); if((this.get_data_type(i).type()=="select" || this.get_data_type(i).type()=="radio") && o2a(this.get_data_type(i).length_set())[original]){ original = o2a(this.get_data_type(i).length_set())[original] } if(this.get_data_type(i).type()=="atext"){ original = this.static_astring(original,this.get_data_type(i).gl()); } var modified = d(this.data.sg(i,"")); if((this.get_data_type(i).type()=="select" || this.get_data_type(i).type()=="radio") && o2a(this.get_data_type(i).length_set())[modified]){ modified = o2a(this.get_data_type(i).length_set())[modified] } if(this.get_data_type(i).type()=="atext"){ modified = this.static_astring(modified,this.get_data_type(i).gl()); } if(this.data.sg(i,"")=="") change+=" διαγράψατε το περιεχόμενο του πεδίου "+this.get_data_type(i).onoma().replace(//,"")+" που ήταν «"+original+"»\n"; else if (this.original.sg(i,"")=="") change+=" συμπληρώσατε το πεδίο "+this.get_data_type(i).onoma().replace(//,"")+" με «"+modified+"»\n"; else change+=" το πεδίο "+this.get_data_type(i).onoma().replace(//,"")+" ήταν «"+original+"» καί έγινε «"+modified+"»\n"; } } } } this.change(change); if(this.change()==""){ return confirm("Δεν κάνατε καμία αλλαγή να αποθηκευτεί παρόλα αυτά;"); } else { return confirm("Έχετε αλλάξει τα εξείς:\n"+this.change()+"Να γίνει αποθήκευση;"); } } return true; } this.save = function(forma){ this.prepare_data(forma); if(this.can_save(forma)){ this.saving(true); var tosend = new Array(); tosend["f"] = "save_"+this.prefix()+""; tosend["p"] = a.serialize(this.to_send()); tosend["wi"] = this.web_auth_id(); tosend["ws"] = this.session(); tosend["host"] = this.host(); kd(this.f(), function(g,aaa){ try{ eval("var what="+g+";"); aaa.saving(false);//should be set in after_save if(what["status"]<=-1000) { alert(what["mesg"]); aaa.logout(); return;} if(what){ aaa.after_save(what); handle_status(what["status"],what["mesg"]); }else aaa.saving(false); }catch(err){alert("general.save.return.function() "+err)} }, this, "POST", tosend); } else { this.saving(false);} }; //this.init(); } /* * javascript super class for sets based on general * to be used as follows * function some_extenson_class_name(name,parent){ * synolo.call(this,name,parent); * ... * ... * //if the method needs extenstion than, or it can be overwritten from scrach * this.select = function(value){new synolo(this.name).select.call(this,value); ...} * } */ function synolo(name, parent){ general.call(this,name,parent); this.inner_set = make_name(this.name)+"_inner_set"; this.init = function(){ new general(this.name).init.call(this); this.set = new Array(); this.selected_i = -1; this.creterea = new Array(); this.creterea.sg = new general("tmp").sg; } this.to_send = function(){ try{ if(this.creterea.sg_var) return this.creterea.sg_var; return o2a(this.creterea); }catch(err){alert("synolo.to_send() "+err);} // return o2a(this.creterea); } this.load = function(what){ this.set = new Array(); for(var i in what){ this.add_to_set(what[i]); } this.loaded(true); } this.add_to_set = function(what){ var length = this.set.length; this.set[length] = what; } this.select = function(i){ this.selected_i = i; if(this.set[this.selected_i] && this.set[this.selected_i].select){ this.set[this.selected_i].select(); } } this.clfts = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_clfts", "link bold", value):this.sg("_clfts", "link bold");} this.clfts_notorderable = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_clfts_notorderable", "bold", value):this.sg("_clfts_notorderable", "bold");} this.clfts_over = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_clfts_over", "bg_lightgrey bold link", value):this.sg("_clfts_over", "bg_lightgrey bold link");} this.stfts_order_asc_header = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_stfts_order_asc_header", "background-color: #beffbe;", value):this.sg("_stfts_order_asc_header", "background-color: #beffbe;");} this.stfts_order_desc_header = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_stfts_order_desc_header", "background-color: #e1bebe;", value):this.sg("_stfts_order_desc_header", "background-color: #e1bebe;");} this.stfts_order_asc = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_stfts_order_asc", "background-color: #beffbe;", value):this.sg("_stfts_order_asc", "background-color: #beffbe;");} this.stfts_order_desc = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_stfts_order_desc", "background-color: #e1bebe;", value):this.sg("_stfts_order_desc", "background-color: #e1bebe;");} this.show_set = function(data_style){if(innerHTML(this.inner_set,this.draw_set(data_style))){show(this.inner_set);}} this.draw_set = function(data_style){ var r = "";var title=""; r += "
"; var b = ""; for(var j in this.fts){ if(this.fts[j].orderable()){ var field_name = ((this.fts[j].field_name_title()!="")?this.fts[j].field_name_title():this.fts[j].field_name()) title = ((this.fts[j].order()=="")?"Αυξουσά ταξινόμηση του πεδίου {field}".replace("{field}", field_name):((this.fts[j].order()=="ASC")?"Φθίνουσα ταξινόμηση του πεδίου {field}".replace("{field}", field_name):"Αφαίρεση ταξινόμησης από το πεδίο {field}".replace("{field}", field_name))); r += "
"+this.fts[j].draw()+"
"; } else { title = this.fts[j].field_name_title(); r += "
"+this.fts[j].draw()+"
"; } b = "border-left: 1px solid #bbb;" } r += "
"; r += "
"; r += "
"; for(var i in this.set){ if(!this.set[i].filter || (typeof(this.set[i].filter)=="function" && this.set[i].filter())){; var inner = make_name(this.name)+"_"+make_name(i+"")+"_inner"; r += "
"+this.draw_set_element(i)+"
\n"; } } r += "
"; r += this.pagination(); r += "
"; return r; } this.show_set_element = function(i){ try{ if(this.set[i]) { var inner = make_name(this.name)+"_"+make_name(i+"")+"_inner"; if(get_element(inner) && innerHTML(inner,this.draw_set_element(i))){ show(inner); return true;}; } }catch(err){alert("synolo.show_set_element("+i+") "+err)} return false; } this.clelement = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_clelement", "", value):this.sg("_clelement", "");} this.clelement_over = function(value){return (typeof(value)!="undefined" && value!=null)?this.sg("_clelement_over", "bg_lightgrey blue", value):this.sg("_clelement_over", "bg_lightgrey blue");} this.element_onmouseover = function(i){var more=(typeof(this.set[i].select)=="function")?"link":""; return "this.className='"+more+" "+this.clelement_over()+"';";} this.element_onmouseout = function(i){var more=(typeof(this.set[i].select)=="function")?"link":""; return "this.className='"+more+" "+this.clelement()+"';";} this.draw_set_element = function(i){ try{ var r = "";var title=""; var style=""; var value=""; if(typeof(this.set[i].style)=="function") style = this.set[i].style(); if(typeof(this.set[i].title)=="function") title = this.set[i].title(); if(typeof(this.set[i].select)=="function") r += "