/* * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ var profiles_list = { "list" : [] }; /* * { * "list" : ["profile1", "profile2" , "profile3", "profile4"], * "profile1" : true, * "profile2" : true, * "profile3" : true, * "profile4" : true * } */ var json_url = "Not set" var sections_list = { "list" : []}; var item_profiles_list = {}; /* * { * "#obj" : ["profile1", "profile2"], * "#obj2" : ["profile3", "profile4"] * } */ var item_list = []; /* * ["#item1", "#item2", "#item3", "#item4"] */ function isEntryVisbile(elem) { return item_profiles_list[elem+"-visible"]; } function isSectionEmpty(id) { var entries = sections_list[id]; console.log("Section '"+id+"'"); for ( var e in entries ) { //console.log("\t "+entries[e]+" : "+isEntryVisbile(entries[e])); if(isEntryVisbile(entries[e])) return false; } return true; } function chk_button_callback(evt) { profiles_list[evt.data]=!profiles_list[evt.data]; for (var i in item_list) { var profiles = item_profiles_list[item_list[i]]; var sum = 0. for (var j in profiles) { for ( var k in profiles_list.list) { if(profiles_list[profiles_list.list[k]] && profiles[j] == profiles_list.list[k]) sum++; } } if (sum==0 && $.inArray("__profiles_all__", profiles)) { $(item_list[i]).hide(400); item_profiles_list[item_list[i]+"-visible"]=false; } else { $(item_list[i]).show(400); item_profiles_list[item_list[i]+"-visible"]=true; } } for (var s in sections_list.list ) { if(isSectionEmpty(sections_list.list[s])) $(sections_list.list[s]).hide(400); else $(sections_list.list[s]).show(400); } } function build_profile(id) { var r = jQuery(""); var b = jQuery(" "+id[1]+""); b.on('change', null, id[0], chk_button_callback); r.append(b); return r; } function build_profiles(obj) { var r = jQuery("
"); //var rr = jQuery("
"); var rrr = jQuery("
"); //------------------ var rr = jQuery("
"); //------------------ if(obj.profiles!=null) { r.append(jQuery("

Profiles:

")); rrr.append(rr); if(Array.isArray(obj.profiles)) { for ( p in obj.profiles) { rr.append(build_profile(obj.profiles[p])); profiles_list.list.push(obj.profiles[p][0]); profiles_list.list.push(obj.profiles[p][0]); profiles_list[obj.profiles[p][0]]=true; } }else { rr.append(build_profile(obj.profiles[p])); profiles_list.list.push(obj.profiles[0]); profiles_list.list.push(obj.profiles[0]); profiles_list[obj.profiles[0]]=true; } r.append(rrr); } return r; } function build_leftbar_section(obj) { var r = jQuery("
"); r.append(jQuery("

"+obj.title+"

")); var rr = jQuery("
"); r.append(rr); for( var s in obj.content ) { var rrr = jQuery(""); if(obj.content[s].length==1) rrr.append("

"+obj.content[s][0]+"

"); else { if(obj.content[s][0]=="Age") { var ageDifMs = Date.now() - obj.content[s][1]*1000; var ageDate = new Date(ageDifMs); rrr.append("

"+obj.content[s][0]+":

"+(ageDate.getUTCFullYear()-1970)+" ans

"); } else { rrr.append("

"+obj.content[s][0]+":

"+obj.content[s][1]+"

"); } } rr.append(rrr); } return r; } function build_leftbar(obj) { var r = jQuery("
"); for (o in obj.leftbar) r.append(build_leftbar_section(obj.leftbar[o])); return r; } function build_image(path) { var r = jQuery(""); r.attr("src", path); r.attr("style", 'width: 100%;'); r.addClass("img-responsive img-rounded"); r.attr("alt", "Ma photo"); return r; } function build_title(title) { var r = jQuery("

"); r.append(title); document.title = title; return r; } function toggle_main(id,i, j) { var obj = $(id); var down = id[0]+"do_"+id.substring(5, id.length); var right = id[0]+"ri_"+id.substring(5, id.length); obj.toggle(400); $(down).toggle(); $(right).toggle(); } function build_main_entry(obj, i, j) { var root = jQuery("
"); var r = jQuery(""); var table = $('
'); var tr1 = $(''); table.append(tr1); r.append(table); if(obj.more != null && obj.more.length>0) { var td1=$(' '); td1.append(jQuery("")); td1.append(jQuery("")); tr1.append(td1); } tr1.append('

'+obj.content+'

'); var td2 = $(''); var ita = $(''); td2.append(ita); if(obj.date) ita.append($('
'+obj.date+'
')); if(obj.location) ita.append($('
'+obj.location+'
')); tr1.append(td2); /* r.append(obj.content+"
"); */ item_list.push("#entry_"+i+"_"+j); item_profiles_list["#entry_"+i+"_"+j]=[]; sections_list["#section_"+i].push("#entry_"+i+"_"+j); if(obj.profiles!=null) { if(Array.isArray(obj.profiles)) { for (var pro in obj.profiles) item_profiles_list["#entry_"+i+"_"+j].push(obj.profiles[pro]); item_profiles_list["#entry_"+i+"_"+j+"-visible"]=true; }else item_profiles_list["#entry_"+i+"_"+j].push(obj.profiles); item_profiles_list["#entry_"+i+"_"+j+"-visible"]=true; }else item_profiles_list["#entry_"+i+"_"+j].push("__profiles_all__"); root.append(r); if(obj.more != null && obj.more.length>0) { var d = jQuery("
"); if(Array.isArray(obj.more)) { for(m in obj.more) { d.append(obj.more[m]+"
"); } } else { d.append(obj.more); } root.append(d); } return root; } function build_main_section(obj, i) { var r = jQuery("
  • "); r.append(jQuery("

    "+obj.title+"

    ")); sections_list["#section_"+i]=[]; sections_list.list.push("#section_"+i); for ( var entry in obj.sections) r.append(build_main_entry(obj.sections[entry], i, entry)); return r; } function build_main(obj) { var r = jQuery("
    "); for ( var section in obj.main) r.append(build_main_section(obj.main[section], section)); return r; } function insert_data(obj) { $("#rootnode").append(build_main(obj)); $("#title").append(build_title(obj.title)); $("#image").append(build_image(obj.photo)); $("#left-bar").append(build_leftbar(obj)); $("#profilesroot").append(build_profiles(obj)); } function getContentYaml(url) { var strReturn = ""; jQuery.ajax({ url: url, success: function(html) { strReturn = html; }, async:false }); return YAML.parse(strReturn); } function getContentJson(url) { var strReturn = ""; jQuery.ajax({ url: url, success: function(html) { strReturn = html; }, async:false }); return strReturn; } function onReady() { var x = getContentJson(json_url); insert_data(x); } function set_json_url(url) { json_url=url; } $( document ).ready(onReady);