Mercurial > farol > farol
annotate farol/templates/macros.j2 @ 35:537d25b1593c
Add Descriptions to the fields of the edit_publisher page
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Mon, 06 Oct 2014 14:24:25 +0200 |
parents | 22d89f53e34c |
children | df5182d0787f |
rev | line source |
---|---|
0 | 1 {# |
2 # Description: | |
3 # Web Template used in Farol Design | |
4 # | |
5 # Authors: | |
6 # BenoƮt Allard <benoit.allard@greenbone.net> | |
7 # | |
8 # Copyright: | |
9 # Copyright (C) 2014 Greenbone Networks GmbH | |
10 # | |
11 # This program is free software; you can redistribute it and/or | |
12 # modify it under the terms of the GNU General Public License | |
13 # as published by the Free Software Foundation; either version 2 | |
14 # of the License, or (at your option) any later version. | |
15 # | |
16 # This program is distributed in the hope that it will be useful, | |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 # GNU General Public License for more details. | |
20 # | |
21 # You should have received a copy of the GNU General Public License | |
22 # along with this program; if not, write to the Free Software | |
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
24 -#} | |
25 | |
26 {% macro textinput(name, label, placeholder="", value=None, required=False, type="text", extras={}, help='') %} | |
27 <div class="form-group"> | |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
28 {% if caller %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
29 {% set content=caller () %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
30 {% call modal(name + "_modal", label) %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
31 {{ content }} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
32 {% endcall %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
33 {% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
34 <label for="{{ name }}">{{ label }}: |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
35 {% if required %}<span class="text-danger"> *</span>{% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
36 {% if caller %}<a href="#{{ name }}_modal" data-toggle="modal">?</a>{% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
37 </label> |
0 | 38 {% if type == "datetime" %}<div class="input-group">{% endif %} |
39 <input | |
40 type="{{ type }}" | |
41 {%- if type != 'file' %} class="form-control"{% endif %} | |
42 id="{{ name }}" name="{{ name }}" | |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
43 {%- if placeholder %} placeholder="{{ placeholder }}"{% endif %} |
0 | 44 {%- if value %} value="{{ value }}"{% endif %} |
45 {%- if required %} required{% endif %} | |
46 {{- extras | xmlattr }}> | |
47 {% if type == "datetime" %} | |
48 <span class="input-group-btn"> | |
49 <button class="btn btn-default" type="button" onclick="{{ name }}.value = new Date().toISOString()">now</button> | |
50 </span> | |
51 </div> | |
52 {% endif %} | |
53 {% if help %} | |
54 <span class="help-block">{{ help }}</span> | |
55 {% endif %} | |
56 </div> | |
57 {% endmacro %} | |
58 | |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
59 {% macro modal(id, title, size=None) %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
60 <div class="modal fade" id="{{ id }}" tabindex="-1" role="dialog" aria-labelledby="{{ id }}_title" aria-hidden="true"> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
61 <div class="modal-dialog{{ ' modal-%s' % size if size}}"> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
62 <div class="modal-content"> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
63 <div class="modal-header"> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
64 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
65 <h4 class="modal-title" id="{{ id }}_title">{{ title }}</h4> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
66 </div> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
67 <div class="modal-body"> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
68 {{ caller() }} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
69 </div>{# We don't need a footer yet ... |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
70 <div class="modal-footer"> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
71 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
72 <button type="button" class="btn btn-primary">Save changes</button> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
73 </div>#} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
74 </div>{# /.modal-content #} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
75 </div>{# /.modal-dialog #} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
76 </div>{# /.modal #} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
77 {% endmacro %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
78 |
0 | 79 {% macro textarea(name, label, placeholder="", value=None, rows=10, required=False) %} |
80 <div class="form-group"> | |
35
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
81 {% if caller %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
82 {% set content=caller () %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
83 {% call modal(name + "_modal", label) %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
84 {{ content }} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
85 {% endcall %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
86 {% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
87 <label for="{{ name }}"> |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
88 {{ label }}: |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
89 {% if required %}<span class="text-danger"> *</span>{% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
90 {% if caller %}<a href="#{{ name }}_modal" data-toggle="modal">?</a>{% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
91 </label> |
0 | 92 <textarea class="form-control" rows={{ rows }} id="{{ name }}" name="{{ name }}" placeholder="{{ placeholder }}"{% if required %} required{% endif %}>{% if value %}{{ value }}{% endif %}</textarea> |
93 </div> | |
94 {% endmacro %} | |
95 | |
96 {% macro selectinput(name, label, choices, value) %} | |
97 <div class="form-group"> | |
35
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
98 {% if caller %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
99 {% set content=caller () %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
100 {% call modal(name + "_modal", label) %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
101 {{ content }} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
102 {% endcall %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
103 {% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
104 <label for="{{ name }}">{{ label }}: |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
105 {% if caller %}<a href="#{{ name }}_modal" data-toggle="modal">?</a>{% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
106 </label> |
0 | 107 <select class="form-control" name="{{name}}", id="{{ name }}"> |
108 {% for choice in choices %}<option{% if value==choice %} selected{% endif %}>{{ choice }}</option>{% endfor %} | |
109 </select> | |
110 </div> | |
111 {% endmacro %} | |
112 | |
113 {# Big difference with the one above is that the choices are tuple (name, value) #} | |
114 {% macro selectinput2(name, label, choices, value, multiple=False) %} | |
115 {% if not multiple %} | |
116 {% set value= [value] %} | |
117 {% endif %} | |
118 <div class="form-group"> | |
119 <label for="{{ name }}">{{ label }}:</label> | |
120 <select class="form-control" name="{{name}}" id="{{ name }}"{% if multiple %} multiple size="{{ choices | length }}"{% endif %}> | |
121 {% for name, val in choices %}<option value="{{ val }}"{% if val in value %} selected{% endif %}>{{ name }}</option>{% endfor %} | |
122 </select> | |
123 </div> | |
124 {% endmacro %} | |
125 | |
32
9b0fb5ca7eff
Replace the (%d)s with badges
Benoît Allard <benoit.allard@greenbone.net>
parents:
0
diff
changeset
|
126 {% macro panel(type="default", heading=None, badge=None, title=0, collapsible=True, extended=False) %} |
0 | 127 {% if not heading %} |
128 {% set collapsible = False %} | |
129 {% endif %} | |
130 <div class="{{ ["panel", "panel-" + type] | join(" ") }}"> | |
131 {% if heading %} | |
132 <div class="panel-heading"> | |
133 {%- if title %}<h{{ title }} class="panel-title">{% endif -%} | |
134 {%- if collapsible %}<a data-toggle="collapse" href="#{{ heading | secure_filename }}">{% endif -%} | |
32
9b0fb5ca7eff
Replace the (%d)s with badges
Benoît Allard <benoit.allard@greenbone.net>
parents:
0
diff
changeset
|
135 {{ heading }}{% if badge is not none %}<span class="pull-right badge">{{ badge }}</span>{% endif %} |
0 | 136 {%- if collapsible %}</a>{% endif -%} |
137 {%- if title %}</h{{ title }}>{% endif -%} | |
138 </div> | |
139 {% endif %} | |
140 {% if collapsible %}<div id="{{ heading | secure_filename }}" class="panel-collapse collapse{{ ' in' if extended}}">{% endif %} | |
141 <div class="panel-body"> | |
142 {{ caller() }} | |
143 </div> | |
144 {% if collapsible %}</div>{% endif %} | |
145 </div> | |
146 {% endmacro %} | |
147 | |
148 {# This should be placed inside a .form-horizontal #} | |
149 {% macro label_value(label, value, left=2, right=10) %} | |
150 <div class="form-group"> | |
151 <label class="col-sm-{{ left }} control-label">{{ label }}:</label> | |
152 <div class="col-sm-{{ right }}"> | |
153 <p class="form-control-static">{{ value }}</p> | |
154 </div> | |
155 </div> | |
156 {% endmacro %} | |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
157 |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
158 {% macro examples(list) %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
159 {% if False %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
160 <dl> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
161 <dt>Example{{ 's' if list | length > 1 }}:</dt> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
162 {% for elem in list %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
163 <dd><samp>{{ elem }}</samp></dd> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
164 {% endfor %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
165 </dl> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
166 {% else %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
167 <p><strong>Example{{ 's' if list | length > 1 }}:</strong></p> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
168 {% if list | length == 1 %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
169 <samp>{{ list[0] }}</samp> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
170 {% else %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
171 <ul> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
172 {%- for elem in list %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
173 <li><samp>{{ elem }}</samp></li> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
174 {%- endfor %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
175 </ul> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
176 {% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
177 {% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
178 {% endmacro %} |