Mercurial > farol > farol
annotate farol/templates/macros.j2 @ 105:09915cbdf549
Unify the add / edit / delete buttons
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Tue, 14 Oct 2014 14:36:31 +0200 |
parents | 0e0572780aff |
children | e0830bcab004 |
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 | |
59 {% macro textarea(name, label, placeholder="", value=None, rows=10, required=False) %} | |
60 <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
|
61 {% if caller %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
62 {% 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
|
63 {% 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
|
64 {{ content }} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
65 {% endcall %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
66 {% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
67 <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
|
68 {{ label }}: |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
69 {% 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
|
70 {% 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
|
71 </label> |
0 | 72 <textarea class="form-control" rows={{ rows }} id="{{ name }}" name="{{ name }}" placeholder="{{ placeholder }}"{% if required %} required{% endif %}>{% if value %}{{ value }}{% endif %}</textarea> |
73 </div> | |
74 {% endmacro %} | |
75 | |
76 {% macro selectinput(name, label, choices, value) %} | |
77 <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
|
78 {% if caller %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
79 {% 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
|
80 {% 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
|
81 {{ content }} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
82 {% endcall %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
83 {% endif %} |
537d25b1593c
Add Descriptions to the fields of the edit_publisher page
Benoît Allard <benoit.allard@greenbone.net>
parents:
34
diff
changeset
|
84 <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
|
85 {% 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
|
86 </label> |
0 | 87 <select class="form-control" name="{{name}}", id="{{ name }}"> |
88 {% for choice in choices %}<option{% if value==choice %} selected{% endif %}>{{ choice }}</option>{% endfor %} | |
89 </select> | |
90 </div> | |
91 {% endmacro %} | |
92 | |
93 {# Big difference with the one above is that the choices are tuple (name, value) #} | |
94 {% macro selectinput2(name, label, choices, value, multiple=False) %} | |
95 {% if not multiple %} | |
96 {% set value= [value] %} | |
97 {% endif %} | |
98 <div class="form-group"> | |
99 <label for="{{ name }}">{{ label }}:</label> | |
100 <select class="form-control" name="{{name}}" id="{{ name }}"{% if multiple %} multiple size="{{ choices | length }}"{% endif %}> | |
101 {% for name, val in choices %}<option value="{{ val }}"{% if val in value %} selected{% endif %}>{{ name }}</option>{% endfor %} | |
102 </select> | |
103 </div> | |
104 {% endmacro %} | |
105 | |
32
9b0fb5ca7eff
Replace the (%d)s with badges
Benoît Allard <benoit.allard@greenbone.net>
parents:
0
diff
changeset
|
106 {% macro panel(type="default", heading=None, badge=None, title=0, collapsible=True, extended=False) %} |
0 | 107 {% if not heading %} |
108 {% set collapsible = False %} | |
109 {% endif %} | |
110 <div class="{{ ["panel", "panel-" + type] | join(" ") }}"> | |
111 {% if heading %} | |
112 <div class="panel-heading"> | |
113 {%- if title %}<h{{ title }} class="panel-title">{% endif -%} | |
114 {%- if collapsible %}<a data-toggle="collapse" href="#{{ heading | secure_filename }}">{% endif -%} | |
44
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
115 {{ heading }} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
116 {%- if badge is not none %}<span class="pull-right badge">{{ badge }}</span>{% endif %} |
0 | 117 {%- if collapsible %}</a>{% endif -%} |
118 {%- if title %}</h{{ title }}>{% endif -%} | |
119 </div> | |
120 {% endif %} | |
121 {% if collapsible %}<div id="{{ heading | secure_filename }}" class="panel-collapse collapse{{ ' in' if extended}}">{% endif %} | |
122 <div class="panel-body"> | |
123 {{ caller() }} | |
124 </div> | |
125 {% if collapsible %}</div>{% endif %} | |
126 </div> | |
127 {% endmacro %} | |
128 | |
44
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
129 {% macro modal(id, title, size=None) %} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
130 <div class="modal fade" id="{{ id }}" tabindex="-1" role="dialog" aria-labelledby="{{ id }}_title" aria-hidden="true"> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
131 <div class="modal-dialog{{ ' modal-%s' % size if size}}"> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
132 <div class="modal-content"> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
133 <div class="modal-header"> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
134 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
135 <h4 class="modal-title" id="{{ id }}_title">{{ title }}</h4> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
136 </div> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
137 <div class="modal-body"> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
138 {{ caller() }} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
139 </div>{# We don't need a footer yet ... |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
140 <div class="modal-footer"> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
141 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
142 <button type="button" class="btn btn-primary">Save changes</button> |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
143 </div>#} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
144 </div>{# /.modal-content #} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
145 </div>{# /.modal-dialog #} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
146 </div>{# /.modal #} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
147 {% endmacro %} |
df5182d0787f
Some macro cleanups
Benoît Allard <benoit.allard@greenbone.net>
parents:
35
diff
changeset
|
148 |
0 | 149 {# This should be placed inside a .form-horizontal #} |
150 {% macro label_value(label, value, left=2, right=10) %} | |
151 <div class="form-group"> | |
152 <label class="col-sm-{{ left }} control-label">{{ label }}:</label> | |
153 <div class="col-sm-{{ right }}"> | |
154 <p class="form-control-static">{{ value }}</p> | |
155 </div> | |
156 </div> | |
157 {% endmacro %} | |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
158 |
53
249b3ad750b1
Add Descriptions for the Threat fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
44
diff
changeset
|
159 {% macro examples(list, title='') %} |
249b3ad750b1
Add Descriptions for the Threat fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
44
diff
changeset
|
160 <p><strong>{{ title + ' ' if title }}Example{{ 's' if list | length > 1 }}:</strong></p> |
34
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
161 {% 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
|
162 <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
|
163 {% else %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
164 <ul> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
165 {%- 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
|
166 <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
|
167 {%- endfor %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
168 </ul> |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
169 {% endif %} |
22d89f53e34c
Add macro to display a description for the input fields
Benoît Allard <benoit.allard@greenbone.net>
parents:
32
diff
changeset
|
170 {% endmacro %} |
69
42915aaa6888
Move the delete_button to the common macros
Benoît Allard <benoit.allard@greenbone.net>
parents:
53
diff
changeset
|
171 |
101
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
172 {% macro POST_button(url, text, fields, out=False, style='btn-default') %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
173 {% if caller and out %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
174 {{ caller('$(this).next()') }} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
175 {% endif %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
176 <form class="inlined-form" action="{{ url }}" method="POST"{{ ' style="display:none"' if out}}> |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
177 {% for elem in fields %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
178 <input type=hidden name="{{ elem }}", value="{{ fields[elem] }}"> |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
179 {% endfor %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
180 {% if caller %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
181 {{ caller('parentNode') if not out }} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
182 {% else %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
183 <button type="submit" class="btn {{ style }}">{{ text }}</button> |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
184 {% endif %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
185 </form> |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
186 {% endmacro %} |
21a1a69b4525
Introduce a POST_button macro and use it in the delete_button one.
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
187 |
105
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
188 {% macro edit_button(url, text="edit") -%} |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
189 <a href="{{ url }}" class="btn btn-default btn-xs" role="btn">{{ text }}</a> |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
190 {%- endmacro %} |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
191 |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
192 {% macro add_button(url, text="add") -%} |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
193 <a href="{{ url }}" class="btn btn-success btn-xs" role="btn">{{ text }}</a> |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
194 {%- endmacro %} |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
195 |
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
196 {% macro delete_button(url, hiddens={}, text="delete") -%} |
104
0e0572780aff
Make the delete_button be a real button, and not a danger label in an anchor
Benoît Allard <benoit.allard@greenbone.net>
parents:
101
diff
changeset
|
197 {{ POST_button(url, text, hiddens, style="btn-danger btn-xs") }} |
105
09915cbdf549
Unify the add / edit / delete buttons
Benoît Allard <benoit.allard@greenbone.net>
parents:
104
diff
changeset
|
198 {%- endmacro %} |