Mercurial > farol > farol
diff 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 |
line wrap: on
line diff
--- a/farol/templates/macros.j2 Mon Oct 06 11:44:01 2014 +0200 +++ b/farol/templates/macros.j2 Mon Oct 06 14:09:57 2014 +0200 @@ -25,13 +25,22 @@ {% macro textinput(name, label, placeholder="", value=None, required=False, type="text", extras={}, help='') %} <div class="form-group"> - <label for="{{ name }}">{{ label }}:{% if required %}<span class="text-danger"> *</span>{% endif %}</label> + {% if caller %} + {% set content=caller () %} + {% call modal(name + "_modal", label) %} + {{ content }} + {% endcall %} + {% endif %} + <label for="{{ name }}">{{ label }}: + {% if required %}<span class="text-danger"> *</span>{% endif %} + {% if caller %}<a href="#{{ name }}_modal" data-toggle="modal">?</a>{% endif %} + </label> {% if type == "datetime" %}<div class="input-group">{% endif %} <input type="{{ type }}" {%- if type != 'file' %} class="form-control"{% endif %} id="{{ name }}" name="{{ name }}" - placeholder="{{ placeholder }}" + {%- if placeholder %} placeholder="{{ placeholder }}"{% endif %} {%- if value %} value="{{ value }}"{% endif %} {%- if required %} required{% endif %} {{- extras | xmlattr }}> @@ -47,6 +56,26 @@ </div> {% endmacro %} +{% macro modal(id, title, size=None) %} +<div class="modal fade" id="{{ id }}" tabindex="-1" role="dialog" aria-labelledby="{{ id }}_title" aria-hidden="true"> + <div class="modal-dialog{{ ' modal-%s' % size if size}}"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> + <h4 class="modal-title" id="{{ id }}_title">{{ title }}</h4> + </div> + <div class="modal-body"> + {{ caller() }} + </div>{# We don't need a footer yet ... + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> + <button type="button" class="btn btn-primary">Save changes</button> + </div>#} + </div>{# /.modal-content #} + </div>{# /.modal-dialog #} +</div>{# /.modal #} +{% endmacro %} + {% macro textarea(name, label, placeholder="", value=None, rows=10, required=False) %} <div class="form-group"> <label for="{{ name }}">{{ label }}:{% if required %}<span class="text-danger"> *</span>{% endif %}</label> @@ -107,3 +136,25 @@ </div> </div> {% endmacro %} + +{% macro examples(list) %} +{% if False %} +<dl> + <dt>Example{{ 's' if list | length > 1 }}:</dt> + {% for elem in list %} + <dd><samp>{{ elem }}</samp></dd> + {% endfor %} +</dl> +{% else %} +<p><strong>Example{{ 's' if list | length > 1 }}:</strong></p> +{% if list | length == 1 %} +<samp>{{ list[0] }}</samp> +{% else %} +<ul> + {%- for elem in list %} + <li><samp>{{ elem }}</samp></li> + {%- endfor %} +</ul> +{% endif %} +{% endif %} +{% endmacro %}