X-Git-Url: http://nitlanguage.org diff --git a/contrib/opportunity/src/templates/meetup.nit b/contrib/opportunity/src/templates/meetup.nit index d9af51d..07a5f66 100644 --- a/contrib/opportunity/src/templates/meetup.nit +++ b/contrib/opportunity/src/templates/meetup.nit @@ -26,33 +26,110 @@ class OpportunityMeetupPage # Meetup the page is supposed to show var meetup: nullable Meetup = null + # Answer mode for the meetup + var mode = 0 init from_id(id: String) do var db = new OpportunityDB.open("opportunity") meetup = db.find_meetup_by_id(id) db.close + if meetup != null then mode = meetup.answer_mode + init end init do - header.page_js = """ - function change_answer(ele){ + header.page_js = "mode = {mode};\n" + header.page_js += """ + function update_scores(){ + var anss = $('.answer'); + var count = {}; + var scores = {}; + var answers = []; + var maxscore = 0; + for(i=0; i < anss.length; i++){ + var incscore = 0; + var inccount = 0; + var idparts = anss[i].id.split("_"); + var ansid = idparts[1]; + var html = anss[i].innerHTML; + if(html === "
✔
"){ + inccount = 1; + incscore = 2; + }else if(html === "
❓
"){ + incscore = 1; + } + var intansid = parseInt(ansid) + if(answers.indexOf(intansid) == -1){ + answers.push(intansid); + } + if(ansid in count){ + count[ansid] += inccount; + }else{ + count[ansid] = inccount; + } + if(ansid in scores){ + scores[ansid] += incscore; + }else{ + scores[ansid] = incscore; + } + if(scores[ansid] > maxscore){ + maxscore = scores[ansid]; + } + } + for(i=0; i < answers.length; i++){ + var ansid = answers[i].toString(); + var el = $('#total'+ansid)[0]; + var ins = "
"+count[ansid]; + if(scores[ansid] >= maxscore){ + ins += "
★"; + } + ins += "
"; + el.innerHTML = ins; + } + } + function change_answer(ele, id){ + // modify only the currently selected entry + if (in_modification_id != id) return; + var e = document.getElementById(ele.id); var i = e.innerHTML; - var ans = true; + var ans = true;""" + if mode == 0 then + header.page_js += """ if(i === "
✔
"){ - ans = false; + ans = 0; e.innerHTML = "
✘
" e.style.color = "red"; }else{ + ans = 1; e.innerHTML = "
✔
"; e.style.color = "green"; - } + }""" + + else + header.page_js += """ + if(i === "
✔
"){ + ans = 1; + e.innerHTML = "
❓
" + e.style.color = "#B8860B"; + }else if(i === "
❓
"){ + ans = 0; + e.innerHTML = "
✘
" + e.style.color = "red"; + }else{ + ans = 2; + e.innerHTML = "
✔
"; + e.style.color = "green"; + }""" + end + header.page_js += """ var a = ele.id.split('_') var pid = a[1] var aid = a[2] + update_scores(); $.ajax({ type: "POST", - url: "/rest/answer", + url: "./rest/answer", data: { answer_id: aid, pers_id: pid, @@ -62,16 +139,33 @@ class OpportunityMeetupPage } function change_temp_answer(ele){ var e = document.getElementById(ele.id); - var i = e.innerHTML; - var ans = true; + var i = e.innerHTML;""" + if mode == 0 then + header.page_js += """ + if(i === "
✔
"){ + e.innerHTML = "
✘
" + e.style.color = "red"; + }else{ + e.innerHTML = "
✔
"; + e.style.color = "green"; + } + """ + else + header.page_js += """ if(i === "
✔
"){ - ans = false; - e.innerHTML = "
✘
"; + e.innerHTML = "
❓
"; + e.style.color = "#B8860B"; + }else if(i === "
❓
"){ + e.innerHTML = "
✘
" e.style.color = "red"; }else{ e.innerHTML = "
✔
"; e.style.color = "green"; } + """ + end + header.page_js += """ + update_scores(); } function add_part(ele){ var e = document.getElementById(ele.id); @@ -82,15 +176,29 @@ class OpportunityMeetupPage ansmap = {}; for(i=0;i✔"){ + ansmap[curr.attr('id')] = 1 }else{ - ansmap[curr.attr('id')] = false - } + ansmap[curr.attr('id')] = 0 + }""" + else + header.page_js += """ + if(curr[0].innerHTML === "
✔
"){ + ansmap[curr.attr('id')] = 2 + }else if(curr[0].innerHTML === "
❓
"){ + ansmap[curr.attr('id')] = 1 + }else{ + ansmap[curr.attr('id')] = 0 + }""" + end + header.page_js += """ } $.ajax({ type: "POST", - url: "/rest/meetup/new_pers", + url: "./rest/meetup/new_pers", data: { meetup_id: mid, persname: pname, @@ -107,20 +215,42 @@ class OpportunityMeetupPage function remove_people(ele){ var arr = ele.id.split("_") var pid = arr[1] - $('#' + ele.id).parent().remove(); + $('#' + ele.id).parent().parent().parent().remove(); + update_scores(); $.ajax({ type: "POST", - url: "/rest/people", + url: "./rest/people", data: { method: "DELETE", p_id: pid } }); } + // ID of line currently open for modification + var in_modification_id = null; + function modify_people(ele, id){ + if (in_modification_id != null) { + // reset to normal values + $('#modify_'+in_modification_id).text("Modify or delete"); + $('#modify_'+in_modification_id).attr("class", "btn btn-xs btn-warning"); + $('#line_'+in_modification_id).css("background-color", ""); + $('#delete_'+in_modification_id).css("display", "none"); + } + if (in_modification_id != id) { + // activate modifiable mode + $('#modify_'+id).text("Done"); + $('#modify_'+id).attr("class", "btn btn-xs btn-success"); + $('#line_'+id).css("background-color", "LightYellow"); + $('#delete_'+id).show(); + + in_modification_id = id; + } else { + in_modification_id = null; + } + } """ end - redef fun rendering do if meetup == null then add((new OpportunityHomePage).write_to_string) @@ -136,58 +266,111 @@ end redef class Meetup # Build the HTML for `self` - fun to_html(db: OpportunityDB): Streamable do + fun to_html(db: OpportunityDB): Writable do var t = new Template t.add """ +
""" - t.add "" - t.add "" + t.add "" for i in answers(db) do - t.add "" end + t.add "" t.add "" for i in participants(db) do - t.add "" - t.add """""" i.load_answers(db, self) + t.add "" t.add "" - for j,k in i.answers do - t.add """" end + t.add """""" t.add "" end t.add """ - - + """ for i in answers(db) do t.add "" end + t.add """ + """ t.add "" + # Compute score for each answer + var scores = new HashMap[Int, Int] + var maxsc = 0 + for i in answers(db) do + scores[i.id] = i.score(db) + if scores[i.id] > maxsc then maxsc = scores[i.id] + end + t.add """ + + + """ + for i in answers(db) do + t.add """" + end + t.add "" + t.add """ + +""" t.add "
ParticipatingParticipant name" + t.add "" t.add i.to_s t.add "
❌
" t.add i.to_s t.add "
" - if k then - t.add "✔" + t.add """
""" + t.add "
" + if answer_mode == 0 then + if k == 1 then + t.add "✔" + else + t.add "✘" + end else - t.add "✘" + if k == 2 then + t.add "✔" + else if k == 1 then + t.add "❓" + else + t.add "✘" + end end t.add "
 """ + t.add """
+
✘
Total ({{{participants(db).length}}})
{{{i.count(db)}}}""" + if scores.has_key(i.id) and scores[i.id] >= maxsc then + t.add """
★""" + end + t.add "
" + t.add "
" return t end end