Merge branch 'master' into polymorphic_extern_classes
[nit.git] / contrib / benitlux / src / benitlux_view.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # View logic of the Web interface Benitlux
18 module benitlux_view
19
20 import benitlux_model
21 import template
22
23 # Template for the whole Benitlux page
24 class BenitluxDocument
25 super Template
26
27 # Page title
28 var page_title = "Benitlux Mailing List" is writable
29
30 # Page header
31 fun header: Template do return new BenitluxHeader
32
33 # Error or success message content, will be shown in a dismissable panel
34 var message_content: nullable String = null is writable
35
36 # Error or success message level (success/danger/warning/info)
37 var message_level: nullable String = null is writable
38
39 # Lines of the last email sent to subscribers
40 var sample_email_lines: nullable Array[String] = null is writable
41
42 redef fun rendering
43 do
44 add """
45 <!DOCTYPE html>
46 <head>
47 <meta charset="utf-8">
48 <meta http-equiv="X-UA-Compatible" content="IE=edge">
49 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
50 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
51 <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
52 <title>"""
53 add page_title
54 add """</title>
55 </head>
56 <body>
57 """
58 add header
59 add """
60 <div class="container">
61
62 <div class="panel panel-default">
63 <div class="panel-body">
64 <p>Service de diffusion des changements au menu de l'excellente
65 <a href="http://www.brasseriebenelux.com/">Brasserie Bénélux</a>
66 sur la rue Sherbrooke. La liste est mise à jours tous les jours à 14h,
67 le courriel est envoyé au même moment.</p>
68 <form class="form-inline text-center" role="form" method="POST">
69 <div class="form-group">
70 <div class="input-group">
71 <div class="input-group-addon">@</div>
72 <input class="form-control" type="email" name="email" placeholder="Enter email">
73 </div>
74 </div>
75 <button type="submit" class="btn btn-default" name="sub">S'inscrire</button>
76 <button type="submit" class="btn btn-default" name="unsub">Se désinscrire</button>
77 </form>
78 </div>
79 </div>
80 """
81
82 var message_level = message_level
83 var message_content = message_content
84 if message_level != null and message_content != null then
85 add """
86 <div class="alert alert-{{{message_level}}} alert-dismissible" role="alert">
87 <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
88 {{{message_content}}}
89 </div>
90 """
91 end
92
93 var sample_email_lines = sample_email_lines
94 if sample_email_lines != null then
95 add """
96 <div class="panel panel-default">
97 <div class="panel-heading">Dernier courriel envoyé</div>
98 <ul class="list-group">
99 <li class="list-group-item">
100 {{{sample_email_lines.join("</li><li class=\"list-group-item\">")}}}
101 </li>
102 </ul>
103 </div>"""
104 end
105
106 add """
107 </div>
108 </body>
109 </html>"""
110 end
111 end
112
113 # Template for the header of Benitlux (right after the opening of `<body>`)
114 class BenitluxHeader
115 super Template
116
117 redef fun rendering
118 do
119 add """
120 <nav class="navbar navbar-default" role="navigation">
121 <div class="container-fluid">
122 <div class="navbar-header">
123 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
124 <span class="sr-only">Toggle navigation</span>
125 <span class="icon-bar"></span>
126 <span class="icon-bar"></span>
127 <span class="icon-bar"></span>
128 </button>
129 <a class="navbar-brand" href="http://xymus.net/">Xymus.net</a>
130 </div>
131
132 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
133 <ul class="nav navbar-nav">
134 <li><a href="http://pep8.xymus.net/">Pep/8 Analysis</a></li>
135 <li><a href="http://tnitter.xymus.net/">Tnitter</a></li>
136 <li class="active"><a href="http://benitlux.xymus.net/">Benitlux</a></li>
137 </ul>
138 </div>
139 </div>
140 </nav>"""
141 end
142 end