d9af51d940dfb42bb34d1429de18068b33090442
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 === "✔"){
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();
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="page-header">
143 <center><h1>{{{name}}}</h1></center>
144 <center><h4>When : {{{date}}}</h4></center>
145 <center><h4>Where : {{{place}}}</h4></center>
147 <table class="table">
150 t
.add
"<th>Participating</th>"
151 for i
in answers
(db
) do
157 for i
in participants
(db
) do
159 t
.add
"""<td class="opportunity-action" style="color: red;" onclick="remove_people(this)" id="remove_{{{i.id}}}"><center>❌</center></td>"""
160 i
.load_answers
(db
, self)
164 for j
,k
in i
.answers
do
165 t
.add
"""<td class="answer" onclick="change_answer(this)" id="answer_{{{j.id}}}_{{{i.id}}}""""
167 t.add " style
=\
"color:green;\""
169 t.add " style
=\
"color:red;\""
177 t.add "</center
></td
>"
183 <td><center><span id="add_
{{{id}}}" onclick="add_part
(this
)" style="color
:green
;" class="action
"><strong>+</strong></span></center></td>
184 <td><input id="new_name
" type="text
" placeholder="Your name
" class="input-large
"></td>
186 for i in answers(db) do
187 t.add "<td
class=\
"answer\" id
=\
"newans_{i.id}\" onclick
=\
"change_temp_answer(this)\" style
=\
"color:red;\"><center
>✘
</center
></td
>"