72503cf58ab52578de0d3f8e82338f0e1fd86d33
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, id){
39 // modify only the currently selected entry
40 if (in_modification_id != id) return;
42 var e = document.getElementById(ele.id);
45 if(i === "<center>✔</center>"){
47 e.innerHTML = "<center>✘</center>"
48 e.style.color = "red";
50 e.innerHTML = "<center>✔</center>";
51 e.style.color = "green";
53 var a = ele.id.split('_')
66 function change_temp_answer(ele){
67 var e = document.getElementById(ele.id);
70 if(i === "<center>✔</center>"){
72 e.innerHTML = "<center>✘</center>";
73 e.style.color = "red";
75 e.innerHTML = "<center>✔</center>";
76 e.style.color = "green";
79 function add_part(ele){
80 var e = document.getElementById(ele.id);
81 var pname = document.getElementById("new_name").value;
82 var arr = e.id.split("_");
84 var ans = $('#' + ele.id).parent().parent().parent().children(".answer");
86 for(i=0;i<ans.length;i++){
88 if(curr[0].innerHTML === "<center>✔</center>"){
89 ansmap[curr.attr('id')] = true
91 ansmap[curr.attr('id')] = false
96 url: "./rest/meetup/new_pers",
100 answers: $.param(ansmap)
103 .done(function(data){
106 .fail(function(data){
107 //TODO: Notify of failure
110 function remove_people(ele){
111 var arr = ele.id.split("_")
113 $('#' + ele.id).parent().parent().parent().remove();
116 url: "./rest/people",
124 // ID of line currently open for modification
125 var in_modification_id = null;
126 function modify_people(ele, id){
127 if (in_modification_id != null) {
128 // reset to normal values
129 $('#modify_'+in_modification_id).text("Modify or delete");
130 $('#modify_'+in_modification_id).attr("class", "btn btn-xs btn-warning");
131 $('#line_'+in_modification_id).css("background-color", "");
132 $('#delete_'+in_modification_id).css("display", "none");
134 if (in_modification_id != id) {
135 // activate modifiable mode
136 $('#modify_'+id).text("Done");
137 $('#modify_'+id).attr("class", "btn btn-xs btn-success");
138 $('#line_'+id).css("background-color", "LightYellow");
139 $('#delete_'+id).show();
141 in_modification_id = id;
143 in_modification_id = null;
149 redef fun rendering
do
150 if meetup
== null then
151 add
((new OpportunityHomePage).write_to_string
)
155 var db
= new OpportunityDB.open
("opportunity")
156 add meetup
.to_html
(db
)
163 # Build the HTML for `self`
164 fun to_html
(db
: OpportunityDB): Streamable do
167 <div class="container">
168 <div class="page-header">
169 <center><h1>{{{name}}}</h1></center>
171 if not date
.is_empty
then t
.add
"""
172 <center><h4>When: {{{date}}}</h4></center>"""
174 if not place
.is_empty
then t
.add
"""
175 <center><h4>Where: {{{place}}}</h4></center>"""
179 <table class="table">
181 t
.add
"<th>Participant name</th>"
182 for i
in answers
(db
) do
183 t
.add
"<th class=\"text-center\
">"
189 for i
in participants
(db
) do
190 i
.load_answers
(db
, self)
191 t
.add
"<tr id=\"line_
{i.id}\
">"
195 for j
,k
in i
.answers
do
201 t
.add
"""<td class="answer" onclick="change_answer(this, {{{i.id}}})" id="answer_{{{j.id}}}_{{{i.id}}}" style="color:{{{color}}}">"""
208 t
.add
"</center></td>"
210 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> """
211 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>"""
215 <tr id="newrow" style="background-color: LightYellow">
216 <td><input id="new_name" type="text" placeholder="Your name" class="input-large"></td>
218 for i
in answers
(db
) do
219 t
.add
"<td class=\"answer\
" id=\"newans_
{i.id}\
" onclick=\"change_temp_answer
(this
)\
" style=\"color
:red
;\
"><center>✘</center></td>"
222 <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>"""