Mercurial > farol > farol
annotate farol/templates/macros.j2 @ 34:22d89f53e34c
Add macro to display a description for the input fields
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Mon, 06 Oct 2014 14:09:57 +0200 |
parents | 9b0fb5ca7eff |
children | 537d25b1593c |
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"> | |
81 <label for="{{ name }}">{{ label }}:{% if required %}<span class="text-danger"> *</span>{% endif %}</label> | |
82 <textarea class="form-control" rows={{ rows }} id="{{ name }}" name="{{ name }}" placeholder="{{ placeholder }}"{% if required %} required{% endif %}>{% if value %}{{ value }}{% endif %}</textarea> | |
83 </div> | |
84 {% endmacro %} | |
85 | |
86 {% macro selectinput(name, label, choices, value) %} | |
87 <div class="form-group"> | |
88 <label for="{{ name }}">{{ label }}:</label> | |
89 <select class="form-control" name="{{name}}", id="{{ name }}"> | |
90 {% for choice in choices %}<option{% if value==choice %} selected{% endif %}>{{ choice }}</option>{% endfor %} | |
91 </select> | |
92 </div> | |
93 {% endmacro %} | |
94 | |
95 {# Big difference with the one above is that the choices are tuple (name, value) #} | |
96 {% macro selectinput2(name, label, choices, value, multiple=False) %} | |
97 {% if not multiple %} | |
98 {% set value= [value] %} | |
99 {% endif %} | |
100 <div class="form-group"> | |
101 <label for="{{ name }}">{{ label }}:</label> | |
102 <select class="form-control" name="{{name}}" id="{{ name }}"{% if multiple %} multiple size="{{ choices | length }}"{% endif %}> | |
103 {% for name, val in choices %}<option value="{{ val }}"{% if val in value %} selected{% endif %}>{{ name }}</option>{% endfor %} | |
104 </select> | |
105 </div> | |
106 {% endmacro %} | |
107 | |
32
9b0fb5ca7eff
Replace the (%d)s with badges
Benoît Allard <benoit.allard@greenbone.net>
parents:
0
diff
changeset
|
108 {% macro panel(type="default", heading=None, badge=None, title=0, collapsible=True, extended=False) %} |
0 | 109 {% if not heading %} |
110 {% set collapsible = False %} | |
111 {% endif %} | |
112 <div class="{{ ["panel", "panel-" + type] | join(" ") }}"> | |
113 {% if heading %} | |
114 <div class="panel-heading"> | |
115 {%- if title %}<h{{ title }} class="panel-title">{% endif -%} | |
116 {%- 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
|
117 {{ heading }}{% if badge is not none %}<span class="pull-right badge">{{ badge }}</span>{% endif %} |
0 | 118 {%- if collapsible %}</a>{% endif -%} |
119 {%- if title %}</h{{ title }}>{% endif -%} | |
120 </div> | |
121 {% endif %} | |
122 {% if collapsible %}<div id="{{ heading | secure_filename }}" class="panel-collapse collapse{{ ' in' if extended}}">{% endif %} | |
123 <div class="panel-body"> | |
124 {{ caller() }} | |
125 </div> | |
126 {% if collapsible %}</div>{% endif %} | |
127 </div> | |
128 {% endmacro %} | |
129 | |
130 {# This should be placed inside a .form-horizontal #} | |
131 {% macro label_value(label, value, left=2, right=10) %} | |
132 <div class="form-group"> | |
133 <label class="col-sm-{{ left }} control-label">{{ label }}:</label> | |
134 <div class="col-sm-{{ right }}"> | |
135 <p class="form-control-static">{{ value }}</p> | |
136 </div> | |
137 </div> | |
138 {% endmacro %} | |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
139 |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
140 {% 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
|
141 {% if False %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
142 <dl> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
143 <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
|
144 {% 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
|
145 <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
|
146 {% endfor %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
147 </dl> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
148 {% else %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
149 <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
|
150 {% 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
|
151 <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
|
152 {% else %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
153 <ul> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
154 {%- 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
|
155 <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
|
156 {%- endfor %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
157 </ul> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
158 {% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
159 {% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
160 {% endmacro %} |