4a55cec861dd690494bea276b20d7129a7a72d49
1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License
15 # Shows a meetup and allows to modify its participants
18 import opportunity_model
23 # Shows a meetup and allows to modify its participants
24 class OpportunityMeetupPage
27 # Meetup the page is supposed to show
28 var meetup
: nullable Meetup = null
30 init from_id
(id
: String) do
31 var db
= new OpportunityDB.open
("opportunity")
32 meetup
= db
.find_meetup_by_id
(id
)
38 function change_answer(ele){
39 var e = document.getElementById(ele.id);
42 if(i === "<center>✔</center>"){
44 e.innerHTML = "<center>✘</center>"
45 e.style.color = "red";
47 e.innerHTML = "<center>✔</center>";
48 e.style.color = "green";
50 var a = ele.id.split('_')
63 function change_temp_answer(ele){
64 var e = document.getElementById(ele.id);
67 if(i === "<center>✔</center>"){
69 e.innerHTML = "<center>✘</center>";
70 e.style.color = "red";
72 e.innerHTML = "<center>✔</center>";
73 e.style.color = "green";
76 function add_part(ele){
77 var e = document.getElementById(ele.id);
78 var pname = document.getElementById("new_name").value;
79 var arr = e.id.split("_");
81 var ans = $('#' + ele.id).parent().parent().parent().children(".answer");
83 for(i=0;i<ans.length;i++){
85 if(curr[0].innerHTML === "<center>✔</center>"){
86 ansmap[curr.attr('id')] = true
88 ansmap[curr.attr('id')] = false
93 url: "./rest/meetup/new_pers",
97 answers: $.param(ansmap)
100 .done(function(data){
103 .fail(function(data){
104 //TODO: Notify of failure
107 function remove_people(ele){
108 var arr = ele.id.split("_")
110 $('#' + ele.id).parent().remove();
113 url: "./rest/people",
124 redef fun rendering
do
125 if meetup
== null then
126 add
((new OpportunityHomePage).write_to_string
)
130 var db
= new OpportunityDB.open
("opportunity")
131 add meetup
.to_html
(db
)
138 # Build the HTML for `self`
139 fun to_html
(db
: OpportunityDB): Streamable do
142 <div class="container">
143 <div class="page-header">
144 <center><h1>{{{name}}}</h1></center>
146 if not date
.is_empty
then t
.add
"""
147 <center><h4>When: {{{date}}}</h4></center>"""
149 if not place
.is_empty
then t
.add
"""
150 <center><h4>Where: {{{place}}}</h4></center>"""
154 <table class="table">
156 t
.add
"<th>Participant name</th>"
157 for i
in answers
(db
) do
158 t
.add
"<th class=\"text-center\
">"
164 for i
in participants
(db
) do
166 i
.load_answers
(db
, self)
170 for j
,k
in i
.answers
do
171 t
.add
"""<td class="answer" onclick="change_answer(this)" id="answer_{{{j.id}}}_{{{i.id}}}""""
173 t.add " style
=\
"color:green;\""
175 t.add " style
=\
"color:red;\""
183 t.add "</center
></td
>"
185 t.add """<td class="opportunity-action
" style="color
: red
;" onclick="remove_people
(this
)" id="remove_
{{{i.id}}}"><center><button class="btn btn-xs btn-danger
" type="button
">Remove</button></center></td>"""
190 <td><input id="new_name
" type="text
" placeholder="Your name
" class="input-large
"></td>
192 for i in answers(db) do
193 t.add "<td
class=\
"answer\" id
=\
"newans_{i.id}\" onclick
=\
"change_temp_answer(this)\" style
=\
"color:red;\"><center
>✘
</center
></td
>"
196 <td><center><span id="add_
{{{id}}}" onclick="add_part
(this
)" style="color
:green
;" class="action
"><button class="btn btn-xs btn-success
" type="button
">Done</button></span></center></td>"""