tests: update line numbers in sav file of `error_class_glob`
[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 # Minimum number of input fields for answer
30 var min_answer_fields = 5
31
32 init do
33 header.page_js = """
34 """
35 end
36
37 redef fun rendering do
38 var n_answers = ans.length
39
40 header.page_js = """
41 var nb_answers = {{{n_answers.max(min_answer_fields)}}};
42
43 function new_answer(sender){
44 var ansdiv = $('#answers')
45
46 nb_answers += 1
47 var nb = nb_answers
48
49 ansdiv.append('<div class="form-group">' +
50 '<label for="answer_' + nb + '" class="col-sm-4 control-label">' + nb + '</label>' +
51 '<div class="col-sm-8">' +
52 '<input name="answer_' + nb + '" id="answer_' + nb + '" class="form-control" type="text" placeholder="Another opportunity">' +
53 '</div></div>')
54 }
55 """
56
57 # Do stuff with body before rendering
58 var bdy = new Template
59
60 bdy.add "<div class=\"container\">"
61 bdy.add "<center>"
62
63 if error != null then
64 bdy.add "<p></p>"
65 bdy.add """<div class="alert alert-danger alert-dismissible" role="alert">
66 <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
67 """
68 bdy.add error.as(not null)
69 bdy.add "</div>"
70 end
71
72 bdy.add """
73 <div class="page-header">
74 <center><h1>Create a meetup</h1></center>
75 </div>
76 """
77 bdy.add """<form class="form-horizontal" action="meetup_create" method="POST" role="form">
78 <div class = "form-group">
79 <label for="meetup_name" class="col-sm-4 control-label">Meetup name</label>
80 <div class="col-sm-8">
81 <input name="meetup_name" id="meetup_name" type="text" class="form-control" placeholder="My Event" value="{{{if meet != null then meet.name else ""}}}" />
82 </div>
83 </div>
84 <div class = "form-group">
85 <label for="meetup_date" class="col-sm-4 control-label">When?</label>
86 <div class="col-sm-8">
87 <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 ""}}}">
88 </div>
89 </div>
90 <div class = "form-group">
91 <label for="meetup=place" class="col-sm-4 control-label">Where?</label>
92 <div class="col-sm-8">
93 <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 ""}}}">
94 </div>
95 </div>
96 <h2>Opportunities</h2>
97 <div id="answers">
98 """
99
100 var cnt = 1
101 for v in ans do
102 bdy.add """
103 <div class="form-group">
104 <label for="answer_{{{cnt}}}" class="col-sm-4 control-label">{{{cnt}}}</label>
105 <div class="col-sm-8">
106 <input name="answer_{{{cnt}}}" id="answer_{{{cnt}}}" type="text" class="form-control" value="{{{v}}}"/>
107 </div>
108 </div>
109 """
110 cnt += 1
111 end
112
113 var empties_to_show = min_answer_fields - ans.length
114 if empties_to_show > 0 then
115 for e in [0..empties_to_show[ do
116 var placeholder
117 if cnt == 1 then
118 placeholder = "First opportunity"
119 else placeholder = "Another opportunity"
120
121 bdy.add """
122 <div class="form-group">
123 <label for="answer_{{{cnt}}}" class="col-sm-4 control-label">{{{cnt}}}</label>
124 <div class="col-sm-8">
125 <input name="answer_{{{cnt}}}" id="answer_{{{cnt}}}" type="text" class="form-control" placeholder="{{{placeholder}}}"/>
126 </div>
127 </div>
128 """
129 cnt += 1
130 end
131 end
132
133 bdy.add """
134 </div>
135 <div class="form-group">
136 <button type="button" class="btn btn-lg" onclick="new_answer(this)">Add an opportunity</button>
137 <button type="submit" class="btn btn-lg btn-success">Create meetup</button>
138 </div>
139 </form>
140 </center>
141 </div>
142 """
143 body = bdy
144 super
145 end
146
147 end