123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
- 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("<label class='btn btn-primary profiles-btn col-md-3 col-sm-5 col-xs-12'></label>");
- var b = jQuery("<input class='profiles-ck' type='checkbox' checked='true' autocomplete='off' id='"+id[0]+"'> "+id[1]+"</input>");
- b.on('change', null, id[0], chk_button_callback);
- r.append(b);
- return r;
- }
- function build_profiles(obj)
- {
- var r = jQuery("<div class='row '></div>");
- //var rr = jQuery("<div class='btn-group' data-toggle='buttons'></div>");
- var rrr = jQuery("<div class='input-group col-md-11 col-sm-12 col-xs-12 ' ></div>");
- //------------------
- var rr = jQuery("<div class='input-group-btn profiles-container row'></div>");
- //------------------
- if(obj.profiles!=null)
- {
- r.append(jQuery("<h4 class='col-md-1 col-sm-12 col-xs-12 '> Profiles:</h4>"));
- 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("<div class=\"list-group-item left-bar-ul-2 color-second\"></div>");
- r.append(jQuery("<h2>"+obj.title+"</h2>"));
- var rr = jQuery("<table style='width:100%'></table> ");
- r.append(rr);
- for( var s in obj.content )
- {
- var rrr = jQuery("<tr></tr>");
- if(obj.content[s].length==1)
- rrr.append("<th><p>"+obj.content[s][0]+"</p></th>");
- else
- {
- if(obj.content[s][0]=="Age")
- {
- var ageDifMs = Date.now() - obj.content[s][1]*1000;
- var ageDate = new Date(ageDifMs);
- rrr.append("<th><p><b>"+obj.content[s][0]+":</b></p></th> <th><p class='left-bar-value'>"+(ageDate.getUTCFullYear()-1970)+" ans</p></th>");
- }
- else
- {
- rrr.append("<th><p><b>"+obj.content[s][0]+":</b></p></th> <th><p class='left-bar-value'>"+obj.content[s][1]+"</p></th>");
- }
- }
- rr.append(rrr);
- }
- return r;
- }
- function build_leftbar(obj)
- {
- var r = jQuery("<div class=\"list-group left-bar-ul color-first\" ></div>");
- for (o in obj.leftbar)
- r.append(build_leftbar_section(obj.leftbar[o]));
- return r;
- }
- function build_image(path)
- {
- var r = jQuery("<img></img>");
- 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("<h1 align='center'></h1>");
- 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("<div></div>");
- var r = jQuery("<a class=\"list-group-item cv-entry \
- color-first\" id='entry_"+i+"_"+j+"' onclick=\"toggle_main('#div_"+i+"_"+j+"', "+i+", "+j+")\"></a>");
- var table = $('<table style="width: 100%"></table>');
- var tr1 = $('<tr></tr>');
- table.append(tr1);
- r.append(table);
-
-
- if(obj.more != null && obj.more.length>0)
- {
- var td1=$('<td rowspan="2" style="width: 15px"> </td>');
- td1.append(jQuery("<span class='glyphicon glyphicon-menu-right li-icon' id='ri_"+i+"_"+j+"'></span>"));
- td1.append(jQuery("<span class='glyphicon glyphicon-menu-down li-icon' id='do_"+i+"_"+j+"' style='display:none'></span>"));
- tr1.append(td1);
- }
-
- tr1.append('<td rowspan="2" pull-left ><h4 style="font-weight: 900; font-size: 16px;" >'+obj.content+'</h4></td>');
- var td2 = $('<td class="pull-right small cv-entry-info" rowspan="2" style="font-size: 11px;font-style: italic;"><td>');
- var ita = $('<i></i>');
- td2.append(ita);
- if(obj.date) ita.append($('<div align="right">'+obj.date+'</div>'));
- if(obj.location) ita.append($('<div align="right">'+obj.location+'</div>'));
- tr1.append(td2);
-
- /*
-
- r.append(obj.content+"<br>");
- */
- 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("<div class=\"list-group-item cv-entry-dsec \
- color-second\" id=\"div_"+i+"_"+j+"\" onclick=\"\"></div>");
- if(Array.isArray(obj.more))
- {
- for(m in obj.more)
- {
- d.append(obj.more[m]+"<br>");
- }
- }
- else
- {
- d.append(obj.more);
- }
- root.append(d);
- }
- return root;
- }
- function build_main_section(obj, i)
- {
- var r = jQuery("<li class=\"list-group-item cv-section transparent\" style=\"border: medium none;\" id='section_"+i+"'></li>");
- r.append(jQuery("<h3 class=\"section-title\">"+obj.title+"</h3>"));
- 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("<div class=\"col-md-9 main-entry col-sm-12 col-xs-12 main\"></div>");
- 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);
|