8d0c45a4512ef7bf98aaeeab5538e6855fdcc467
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
29 # Answer mode for the meetup
32 init from_id
(id
: String) do
33 var db
= new OpportunityDB.open
("opportunity")
34 meetup
= db
.find_meetup_by_id
(id
)
36 if meetup
!= null then mode
= meetup
.answer_mode
41 header
.page_js
= "mode = {mode};\n"
43 function change_answer(ele, id){
44 // modify only the currently selected entry
45 if (in_modification_id != id) return;
47 var e = document.getElementById(ele.id);
50 if(i === "<center>✔</center>"){
52 e.innerHTML = "<center>❓</center>"
53 e.style.color = "orange";
54 }else if(i === "<center>❓</center>"){
56 e.innerHTML = "<center>✘</center>"
57 e.style.color = "red";
60 e.innerHTML = "<center>✔</center>";
61 e.style.color = "green";
63 var a = ele.id.split('_')
76 function change_temp_answer(ele){
77 var e = document.getElementById(ele.id);
78 var i = e.innerHTML;"""
81 if(i === "<center>✔</center>"){
82 e.innerHTML = "<center>✘</center>"
83 e.style.color = "red";
85 e.innerHTML = "<center>✔</center>";
86 e.style.color = "green";
91 if(i === "<center>✔</center>"){
92 e.innerHTML = "<center>❓</center>";
93 e.style.color = "orange";
94 }else if(i === "<center>❓</center>"){
95 e.innerHTML = "<center>✘</center>"
96 e.style.color = "red";
98 e.innerHTML = "<center>✔</center>";
99 e.style.color = "green";
103 header
.page_js
+= """
105 function add_part(ele){
106 var e = document.getElementById(ele.id);
107 var pname = document.getElementById("new_name").value;
108 var arr = e.id.split("_");
110 var ans = $('#' + ele.id).parent().parent().parent().children(".answer");
112 for(i=0;i<ans.length;i++){
116 header
.page_js
+= """
117 if(curr[0].innerHTML === "<center>✔</center>"){
118 ansmap[curr.attr('id')] = 1
120 ansmap[curr.attr('id')] = 0
123 header
.page_js
+= """
124 if(curr[0].innerHTML === "<center>✔</center>"){
125 ansmap[curr.attr('id')] = 2
126 }else if(curr[0].innerHTML === "<center>❓</center>"){
127 ansmap[curr.attr('id')] = 1
129 ansmap[curr.attr('id')] = 0
132 header
.page_js
+= """
136 url: "./rest/meetup/new_pers",
140 answers: $.param(ansmap)
143 .done(function(data){
146 .fail(function(data){
147 //TODO: Notify of failure
150 function remove_people(ele){
151 var arr = ele.id.split("_")
153 $('#' + ele.id).parent().parent().parent().remove();
156 url: "./rest/people",
164 // ID of line currently open for modification
165 var in_modification_id = null;
166 function modify_people(ele, id){
167 if (in_modification_id != null) {
168 // reset to normal values
169 $('#modify_'+in_modification_id).text("Modify or delete");
170 $('#modify_'+in_modification_id).attr("class", "btn btn-xs btn-warning");
171 $('#line_'+in_modification_id).css("background-color", "");
172 $('#delete_'+in_modification_id).css("display", "none");
174 if (in_modification_id != id) {
175 // activate modifiable mode
176 $('#modify_'+id).text("Done");
177 $('#modify_'+id).attr("class", "btn btn-xs btn-success");
178 $('#line_'+id).css("background-color", "LightYellow");
179 $('#delete_'+id).show();
181 in_modification_id = id;
183 in_modification_id = null;
189 redef fun rendering
do
190 if meetup
== null then
191 add
((new OpportunityHomePage).write_to_string
)
195 var db
= new OpportunityDB.open
("opportunity")
196 add meetup
.to_html
(db
)
203 # Build the HTML for `self`
204 fun to_html
(db
: OpportunityDB): Streamable do
207 <div class="container">
208 <div class="page-header">
209 <center><h1>{{{name}}}</h1></center>
211 if not date
.is_empty
then t
.add
"""
212 <center><h4>When: {{{date}}}</h4></center>"""
214 if not place
.is_empty
then t
.add
"""
215 <center><h4>Where: {{{place}}}</h4></center>"""
219 <table class="table">
221 t
.add
"<th>Participant name</th>"
222 for i
in answers
(db
) do
223 t
.add
"<th class=\"text-center\
">"
229 for i
in participants
(db
) do
230 i
.load_answers
(db
, self)
231 t
.add
"<tr id=\"line_
{i.id}\
">"
235 for j
, k
in i
.answers
do
237 if answer_mode
== 0 then
252 t
.add
"""<td class="answer" onclick="change_answer(this, {{{i.id}}})" id="answer_{{{j.id}}}_{{{i.id}}}" style="color:{{{color}}}">"""
254 if answer_mode
== 0 then
269 t
.add
"</center></td>"
271 t
.add
"""<td class="opportunity-action"><center><button class="btn btn-xs btn-warning" type="button" onclick="modify_people(this, {{{i.id}}})" id="modify_{{{i.id}}}">Modify or delete</button> """
272 t
.add
"""<button class="btn btn-xs btn-danger" type="button" onclick="remove_people(this)" id="delete_{{{i.id}}}" style="display: none;">Delete</button></center></td>"""
276 <tr id="newrow" style="background-color: LightYellow">
277 <td><input id="new_name" type="text" placeholder="Your name" class="input-large"></td>
279 for i
in answers
(db
) do
280 t
.add
"<td class=\"answer\
" id=\"newans_
{i.id}\
" onclick=\"change_temp_answer
(this
)\
" style=\"color
:red
;\
"><center>✘</center></td>"
283 <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>"""