opportunity: prettier meetup creation
[nit.git] / contrib / opportunity / src / templates / meetup_creation.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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
14
15 module meetup_creation
16
17 import boilerplate
18 import opportunity_model
19
20 class MeetupCreationPage
21 super OpportunityPage
22
23 var meet: nullable Meetup = null is writable
24
25 var error: nullable String = null is writable
26
27 var ans: Set[String] = new HashSet[String] is writable
28
29 init do
30 header.page_js = """
31 """
32 end
33
34 redef fun rendering do
35 var n_answers = ans.length + 1
36 if n_answers == 1 then n_answers = 2
37
38 header.page_js = """
39 var nb_answers = {{{n_answers}}};
40
41 function new_answer(sender){
42 var ansdiv = $('#answers')
43
44 var nb = nb_answers
45 nb_answers += 1
46
47 ansdiv.append('<div class="form-group">' +
48 '<label for="answer_' + nb + '" class="col-sm-4 control-label">' + nb + '</label>' +
49 '<div class="col-sm-8">' +
50 '<input name="answer_' + nb + '" id="answer_' + nb + '" class="form-control" type="text" placeholder="Another opportunity">' +
51 '</div></div>')
52 }
53 """
54
55 # Do stuff with body before rendering
56 var bdy = new Template
57
58 bdy.add "<div class=\"container\">"
59 bdy.add "<center>"
60
61 if error != null then
62 bdy.add "<p></p>"
63 bdy.add """<div class="alert alert-danger alert-dismissible" role="alert">
64 <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
65 """
66 bdy.add error.as(not null)
67 bdy.add "</div>"
68 end
69
70 bdy.add """
71 <div class="page-header">
72 <center><h1>Create a meetup</h1></center>
73 </div>
74 """
75 bdy.add """<form class="form-horizontal" action="meetup_create" method="POST" role="form">
76 <div class = "form-group">
77 <label for="meetup_name" class="col-sm-4 control-label">Meetup name</label>
78 <div class="col-sm-8">
79 <input name="meetup_name" id="meetup_name" type="text" class="form-control" placeholder="My Event" value="{{{if meet != null then meet.name else ""}}}" />
80 </div>
81 </div>
82 <div class = "form-group">
83 <label for="meetup_date" class="col-sm-4 control-label">When?</label>
84 <div class="col-sm-8">
85 <input name="meetup_date" id="meetup_date" type="text" class="form-control" placeholder="Time of the event" value="{{{if meet != null then meet.date else ""}}}">
86 </div>
87 </div>
88 <div class = "form-group">
89 <label for="meetup=place" class="col-sm-4 control-label">Where?</label>
90 <div class="col-sm-8">
91 <input name="meetup_place" id="meetup_place" type="text" class="form-control" placeholder="Place of the event" value="{{{if meet != null then meet.place else ""}}}">
92 </div>
93 </div>
94 <h2>Opportunities</h2>
95 <div id="answers">
96 """
97
98 if ans.is_empty then
99 bdy.add """
100 <div class="form-group">
101 <label for="answer_1" class="col-sm-4 control-label">1</label>
102 <div class="col-sm-8">
103 <input name="answer_1" id="answer_1" type="text" class="form-control" placeholder="First opportunity">
104 </div>
105 </div>
106 """
107 else
108 var cnt = 1
109 for v in ans do
110 bdy.add """
111 <div class="form-group">
112 <label for="answer_{{{cnt}}}" class="col-sm-4 control-label">{{{cnt}}}</label>
113 <div class="col-sm-8">
114 <input name="answer_{{{cnt}}}" id="answer_{{{cnt}}}" type="text" class="form-control" value="{{{v}}}"/>
115 </div>
116 </div>
117 """
118 cnt += 1
119 end
120 end
121
122 bdy.add """
123 </div>
124 <div class="form-group">
125 <button type="button" class="btn btn-lg" onclick="new_answer(this)">Add an opportunity</button>
126 <button type="submit" class="btn btn-lg btn-success">Create meetup</button>
127 </div>
128 </form>
129 </center>
130 </div>
131 """
132 body = bdy
133 super
134 end
135
136 end