Mercurial > farol > farol
comparison farol/templates/macros.j2 @ 0:4a9f23230eba
Initial Release
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Wed, 24 Sep 2014 10:07:49 +0200 |
parents | |
children | 9b0fb5ca7eff |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a9f23230eba |
---|---|
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"> | |
28 <label for="{{ name }}">{{ label }}:{% if required %}<span class="text-danger"> *</span>{% endif %}</label> | |
29 {% if type == "datetime" %}<div class="input-group">{% endif %} | |
30 <input | |
31 type="{{ type }}" | |
32 {%- if type != 'file' %} class="form-control"{% endif %} | |
33 id="{{ name }}" name="{{ name }}" | |
34 placeholder="{{ placeholder }}" | |
35 {%- if value %} value="{{ value }}"{% endif %} | |
36 {%- if required %} required{% endif %} | |
37 {{- extras | xmlattr }}> | |
38 {% if type == "datetime" %} | |
39 <span class="input-group-btn"> | |
40 <button class="btn btn-default" type="button" onclick="{{ name }}.value = new Date().toISOString()">now</button> | |
41 </span> | |
42 </div> | |
43 {% endif %} | |
44 {% if help %} | |
45 <span class="help-block">{{ help }}</span> | |
46 {% endif %} | |
47 </div> | |
48 {% endmacro %} | |
49 | |
50 {% macro textarea(name, label, placeholder="", value=None, rows=10, required=False) %} | |
51 <div class="form-group"> | |
52 <label for="{{ name }}">{{ label }}:{% if required %}<span class="text-danger"> *</span>{% endif %}</label> | |
53 <textarea class="form-control" rows={{ rows }} id="{{ name }}" name="{{ name }}" placeholder="{{ placeholder }}"{% if required %} required{% endif %}>{% if value %}{{ value }}{% endif %}</textarea> | |
54 </div> | |
55 {% endmacro %} | |
56 | |
57 {% macro selectinput(name, label, choices, value) %} | |
58 <div class="form-group"> | |
59 <label for="{{ name }}">{{ label }}:</label> | |
60 <select class="form-control" name="{{name}}", id="{{ name }}"> | |
61 {% for choice in choices %}<option{% if value==choice %} selected{% endif %}>{{ choice }}</option>{% endfor %} | |
62 </select> | |
63 </div> | |
64 {% endmacro %} | |
65 | |
66 {# Big difference with the one above is that the choices are tuple (name, value) #} | |
67 {% macro selectinput2(name, label, choices, value, multiple=False) %} | |
68 {% if not multiple %} | |
69 {% set value= [value] %} | |
70 {% endif %} | |
71 <div class="form-group"> | |
72 <label for="{{ name }}">{{ label }}:</label> | |
73 <select class="form-control" name="{{name}}" id="{{ name }}"{% if multiple %} multiple size="{{ choices | length }}"{% endif %}> | |
74 {% for name, val in choices %}<option value="{{ val }}"{% if val in value %} selected{% endif %}>{{ name }}</option>{% endfor %} | |
75 </select> | |
76 </div> | |
77 {% endmacro %} | |
78 | |
79 {% macro panel(type="default", heading=None, title=0, collapsible=True, extended=False) %} | |
80 {% if not heading %} | |
81 {% set collapsible = False %} | |
82 {% endif %} | |
83 <div class="{{ ["panel", "panel-" + type] | join(" ") }}"> | |
84 {% if heading %} | |
85 <div class="panel-heading"> | |
86 {%- if title %}<h{{ title }} class="panel-title">{% endif -%} | |
87 {%- if collapsible %}<a data-toggle="collapse" href="#{{ heading | secure_filename }}">{% endif -%} | |
88 {{ heading }} | |
89 {%- if collapsible %}</a>{% endif -%} | |
90 {%- if title %}</h{{ title }}>{% endif -%} | |
91 </div> | |
92 {% endif %} | |
93 {% if collapsible %}<div id="{{ heading | secure_filename }}" class="panel-collapse collapse{{ ' in' if extended}}">{% endif %} | |
94 <div class="panel-body"> | |
95 {{ caller() }} | |
96 </div> | |
97 {% if collapsible %}</div>{% endif %} | |
98 </div> | |
99 {% endmacro %} | |
100 | |
101 {# This should be placed inside a .form-horizontal #} | |
102 {% macro label_value(label, value, left=2, right=10) %} | |
103 <div class="form-group"> | |
104 <label class="col-sm-{{ left }} control-label">{{ label }}:</label> | |
105 <div class="col-sm-{{ right }}"> | |
106 <p class="form-control-static">{{ value }}</p> | |
107 </div> | |
108 </div> | |
109 {% endmacro %} |