/*
* 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 = $('