cv.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. var profiles_list = { "list" : [] };
  14. /*
  15. * {
  16. * "list" : ["profile1", "profile2" , "profile3", "profile4"],
  17. * "profile1" : true,
  18. * "profile2" : true,
  19. * "profile3" : true,
  20. * "profile4" : true
  21. * }
  22. */
  23. var json_url = "Not set"
  24. var sections_list = { "list" : []};
  25. var item_profiles_list = {};
  26. /*
  27. * {
  28. * "#obj" : ["profile1", "profile2"],
  29. * "#obj2" : ["profile3", "profile4"]
  30. * }
  31. */
  32. var item_list = [];
  33. /*
  34. * ["#item1", "#item2", "#item3", "#item4"]
  35. */
  36. function isEntryVisbile(elem)
  37. {
  38. return item_profiles_list[elem+"-visible"];
  39. }
  40. function isSectionEmpty(id)
  41. {
  42. var entries = sections_list[id];
  43. console.log("Section '"+id+"'");
  44. for ( var e in entries )
  45. {
  46. //console.log("\t "+entries[e]+" : "+isEntryVisbile(entries[e]));
  47. if(isEntryVisbile(entries[e])) return false;
  48. }
  49. return true;
  50. }
  51. function chk_button_callback(evt)
  52. {
  53. profiles_list[evt.data]=!profiles_list[evt.data];
  54. for (var i in item_list)
  55. {
  56. var profiles = item_profiles_list[item_list[i]];
  57. var sum = 0.
  58. for (var j in profiles)
  59. {
  60. for ( var k in profiles_list.list)
  61. {
  62. if(profiles_list[profiles_list.list[k]] && profiles[j] == profiles_list.list[k])
  63. sum++;
  64. }
  65. }
  66. if (sum==0 && $.inArray("__profiles_all__", profiles))
  67. {
  68. $(item_list[i]).hide(400);
  69. item_profiles_list[item_list[i]+"-visible"]=false;
  70. }
  71. else
  72. {
  73. $(item_list[i]).show(400);
  74. item_profiles_list[item_list[i]+"-visible"]=true;
  75. }
  76. }
  77. for (var s in sections_list.list )
  78. {
  79. if(isSectionEmpty(sections_list.list[s]))
  80. $(sections_list.list[s]).hide(400);
  81. else
  82. $(sections_list.list[s]).show(400);
  83. }
  84. }
  85. function build_profile(id)
  86. {
  87. var r = jQuery("<label class='btn btn-primary profiles-btn col-md-3 col-sm-5 col-xs-12'></label>");
  88. var b = jQuery("<input class='profiles-ck' type='checkbox' checked='true' autocomplete='off' id='"+id[0]+"'> "+id[1]+"</input>");
  89. b.on('change', null, id[0], chk_button_callback);
  90. r.append(b);
  91. return r;
  92. }
  93. function build_profiles(obj)
  94. {
  95. var r = jQuery("<div class='row '></div>");
  96. //var rr = jQuery("<div class='btn-group' data-toggle='buttons'></div>");
  97. var rrr = jQuery("<div class='input-group col-md-11 col-sm-12 col-xs-12 ' ></div>");
  98. //------------------
  99. var rr = jQuery("<div class='input-group-btn profiles-container row'></div>");
  100. //------------------
  101. if(obj.profiles!=null)
  102. {
  103. r.append(jQuery("<h4 class='col-md-1 col-sm-12 col-xs-12 '> Profiles:</h4>"));
  104. rrr.append(rr);
  105. if(Array.isArray(obj.profiles))
  106. {
  107. for ( p in obj.profiles)
  108. {
  109. rr.append(build_profile(obj.profiles[p]));
  110. profiles_list.list.push(obj.profiles[p][0]);
  111. profiles_list.list.push(obj.profiles[p][0]);
  112. profiles_list[obj.profiles[p][0]]=true;
  113. }
  114. }else
  115. {
  116. rr.append(build_profile(obj.profiles[p]));
  117. profiles_list.list.push(obj.profiles[0]);
  118. profiles_list.list.push(obj.profiles[0]);
  119. profiles_list[obj.profiles[0]]=true;
  120. }
  121. r.append(rrr);
  122. }
  123. return r;
  124. }
  125. function build_leftbar_section(obj)
  126. {
  127. var r = jQuery("<div class=\"list-group-item left-bar-ul-2 color-second\"></div>");
  128. r.append(jQuery("<h2>"+obj.title+"</h2>"));
  129. var rr = jQuery("<table style='width:100%'></table> ");
  130. r.append(rr);
  131. for( var s in obj.content )
  132. {
  133. var rrr = jQuery("<tr></tr>");
  134. if(obj.content[s].length==1)
  135. rrr.append("<th><p>"+obj.content[s][0]+"</p></th>");
  136. else
  137. {
  138. if(obj.content[s][0]=="Age")
  139. {
  140. var ageDifMs = Date.now() - obj.content[s][1]*1000;
  141. var ageDate = new Date(ageDifMs);
  142. rrr.append("<th><p><b>"+obj.content[s][0]+":</b></p></th> <th><p class='left-bar-value'>"+(ageDate.getUTCFullYear()-1970)+" ans</p></th>");
  143. }
  144. else
  145. {
  146. rrr.append("<th><p><b>"+obj.content[s][0]+":</b></p></th> <th><p class='left-bar-value'>"+obj.content[s][1]+"</p></th>");
  147. }
  148. }
  149. rr.append(rrr);
  150. }
  151. return r;
  152. }
  153. function build_leftbar(obj)
  154. {
  155. var r = jQuery("<div class=\"list-group left-bar-ul color-first\" ></div>");
  156. for (o in obj.leftbar)
  157. r.append(build_leftbar_section(obj.leftbar[o]));
  158. return r;
  159. }
  160. function build_image(path)
  161. {
  162. var r = jQuery("<img></img>");
  163. r.attr("src", path);
  164. r.attr("style", 'width: 100%;');
  165. r.addClass("img-responsive img-rounded");
  166. r.attr("alt", "Ma photo");
  167. return r;
  168. }
  169. function build_title(title)
  170. {
  171. var r = jQuery("<h1 align='center'></h1>");
  172. r.append(title);
  173. document.title = title;
  174. return r;
  175. }
  176. function toggle_main(id,i, j)
  177. {
  178. var obj = $(id);
  179. var down = id[0]+"do_"+id.substring(5, id.length);
  180. var right = id[0]+"ri_"+id.substring(5, id.length);
  181. obj.toggle(400);
  182. $(down).toggle();
  183. $(right).toggle();
  184. }
  185. function build_main_entry(obj, i, j)
  186. {
  187. var root = jQuery("<div></div>");
  188. var r = jQuery("<a class=\"list-group-item cv-entry \
  189. color-first\" id='entry_"+i+"_"+j+"' onclick=\"toggle_main('#div_"+i+"_"+j+"', "+i+", "+j+")\"></a>");
  190. var table = $('<table style="width: 100%"></table>');
  191. var tr1 = $('<tr></tr>');
  192. table.append(tr1);
  193. r.append(table);
  194. if(obj.more != null && obj.more.length>0)
  195. {
  196. var td1=$('<td rowspan="2" style="width: 15px"> </td>');
  197. td1.append(jQuery("<span class='glyphicon glyphicon-menu-right li-icon' id='ri_"+i+"_"+j+"'></span>"));
  198. td1.append(jQuery("<span class='glyphicon glyphicon-menu-down li-icon' id='do_"+i+"_"+j+"' style='display:none'></span>"));
  199. tr1.append(td1);
  200. }
  201. tr1.append('<td rowspan="2" pull-left ><h4 style="font-weight: 900; font-size: 16px;" >'+obj.content+'</h4></td>');
  202. var td2 = $('<td class="pull-right small cv-entry-info" rowspan="2" style="font-size: 11px;font-style: italic;"><td>');
  203. var ita = $('<i></i>');
  204. td2.append(ita);
  205. if(obj.date) ita.append($('<div align="right">'+obj.date+'</div>'));
  206. if(obj.location) ita.append($('<div align="right">'+obj.location+'</div>'));
  207. tr1.append(td2);
  208. /*
  209. r.append(obj.content+"<br>");
  210. */
  211. item_list.push("#entry_"+i+"_"+j);
  212. item_profiles_list["#entry_"+i+"_"+j]=[];
  213. sections_list["#section_"+i].push("#entry_"+i+"_"+j);
  214. if(obj.profiles!=null)
  215. {
  216. if(Array.isArray(obj.profiles))
  217. {
  218. for (var pro in obj.profiles)
  219. item_profiles_list["#entry_"+i+"_"+j].push(obj.profiles[pro]);
  220. item_profiles_list["#entry_"+i+"_"+j+"-visible"]=true;
  221. }else
  222. item_profiles_list["#entry_"+i+"_"+j].push(obj.profiles);
  223. item_profiles_list["#entry_"+i+"_"+j+"-visible"]=true;
  224. }else item_profiles_list["#entry_"+i+"_"+j].push("__profiles_all__");
  225. root.append(r);
  226. if(obj.more != null && obj.more.length>0)
  227. {
  228. var d = jQuery("<div class=\"list-group-item cv-entry-dsec \
  229. color-second\" id=\"div_"+i+"_"+j+"\" onclick=\"\"></div>");
  230. if(Array.isArray(obj.more))
  231. {
  232. for(m in obj.more)
  233. {
  234. d.append(obj.more[m]+"<br>");
  235. }
  236. }
  237. else
  238. {
  239. d.append(obj.more);
  240. }
  241. root.append(d);
  242. }
  243. return root;
  244. }
  245. function build_main_section(obj, i)
  246. {
  247. var r = jQuery("<li class=\"list-group-item cv-section transparent\" style=\"border: medium none;\" id='section_"+i+"'></li>");
  248. r.append(jQuery("<h3 class=\"section-title\">"+obj.title+"</h3>"));
  249. sections_list["#section_"+i]=[];
  250. sections_list.list.push("#section_"+i);
  251. for ( var entry in obj.sections)
  252. r.append(build_main_entry(obj.sections[entry], i, entry));
  253. return r;
  254. }
  255. function build_main(obj)
  256. {
  257. var r = jQuery("<div class=\"col-md-9 main-entry col-sm-12 col-xs-12 main\"></div>");
  258. for ( var section in obj.main)
  259. r.append(build_main_section(obj.main[section], section));
  260. return r;
  261. }
  262. function insert_data(obj)
  263. {
  264. $("#rootnode").append(build_main(obj));
  265. $("#title").append(build_title(obj.title));
  266. $("#image").append(build_image(obj.photo));
  267. $("#left-bar").append(build_leftbar(obj));
  268. $("#profilesroot").append(build_profiles(obj));
  269. }
  270. function getContentYaml(url)
  271. {
  272. var strReturn = "";
  273. jQuery.ajax({
  274. url: url,
  275. success: function(html) {
  276. strReturn = html;
  277. },
  278. async:false
  279. });
  280. return YAML.parse(strReturn);
  281. }
  282. function getContentJson(url)
  283. {
  284. var strReturn = "";
  285. jQuery.ajax({
  286. url: url,
  287. success: function(html) {
  288. strReturn = html;
  289. },
  290. async:false
  291. });
  292. return strReturn;
  293. }
  294. function onReady()
  295. {
  296. var x = getContentJson(json_url);
  297. insert_data(x);
  298. }
  299. function set_json_url(url)
  300. {
  301. json_url=url;
  302. }
  303. $( document ).ready(onReady);