# This file is part of NIT ( http://www.nitlanguage.org ). # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License # Shows a meetup and allows to modify its participants module meetup import opportunity_model import boilerplate import welcome import template # Shows a meetup and allows to modify its participants class OpportunityMeetupPage super OpportunityPage # Meetup the page is supposed to show var meetup: nullable Meetup = null init from_id(id: String) do var db = new OpportunityDB.open("opportunity") meetup = db.find_meetup_by_id(id) db.close end init do header.page_js = """ function change_answer(ele){ var e = document.getElementById(ele.id); var i = e.innerHTML; var ans = true; if(i === "
"){ ans = false; e.innerHTML = "
" e.style.color = "red"; }else{ e.innerHTML = "
"; e.style.color = "green"; } var a = ele.id.split('_') var pid = a[1] var aid = a[2] $.ajax({ type: "POST", url: "/rest/answer", data: { answer_id: aid, pers_id: pid, answer: ans } }); } function change_temp_answer(ele){ var e = document.getElementById(ele.id); var i = e.innerHTML; var ans = true; if(i === "
"){ ans = false; e.innerHTML = "
"; e.style.color = "red"; }else{ e.innerHTML = "
"; e.style.color = "green"; } } function add_part(ele){ var e = document.getElementById(ele.id); var pname = document.getElementById("new_name").value; var arr = e.id.split("_"); var mid = arr[1]; var ans = $('#' + ele.id).parent().parent().parent().children(".answer"); ansmap = {}; for(i=0;i✔"){ ansmap[curr.attr('id')] = true }else{ ansmap[curr.attr('id')] = false } } $.ajax({ type: "POST", url: "/rest/meetup/new_pers", data: { meetup_id: mid, persname: pname, answers: $.param(ansmap) } }) .done(function(data){ location.reload(); }) .fail(function(data){ //TODO: Notify of failure }); } function remove_people(ele){ var arr = ele.id.split("_") var pid = arr[1] $('#' + ele.id).parent().remove(); $.ajax({ type: "POST", url: "/rest/people", data: { method: "DELETE", p_id: pid } }); } """ end redef fun rendering do if meetup == null then add((new OpportunityHomePage).write_to_string) return end add header var db = new OpportunityDB.open("opportunity") add meetup.to_html(db) db.close add footer end end redef class Meetup # Build the HTML for `self` fun to_html(db: OpportunityDB): Streamable do var t = new Template t.add """ """ t.add "" t.add "" for i in answers(db) do t.add "" end t.add "" for i in participants(db) do t.add "" t.add """""" i.load_answers(db, self) t.add "" for j,k in i.answers do t.add """" end t.add "" end t.add """ """ for i in answers(db) do t.add "" end t.add "" t.add "
Participating" t.add i.to_s t.add "
" t.add i.to_s t.add "
" if k then t.add "✔" else t.add "✘" end t.add "
" return t end end