Mercurial > farol > farol
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/farol/templates/macros.j2 Wed Sep 24 10:07:49 2014 +0200 @@ -0,0 +1,109 @@ +{# +# Description: +# Web Template used in Farol Design +# +# Authors: +# BenoƮt Allard <benoit.allard@greenbone.net> +# +# Copyright: +# Copyright (C) 2014 Greenbone Networks GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +-#} + +{% 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 type == "datetime" %}<div class="input-group">{% endif %} + <input + type="{{ type }}" + {%- if type != 'file' %} class="form-control"{% endif %} + id="{{ name }}" name="{{ name }}" + placeholder="{{ placeholder }}" + {%- if value %} value="{{ value }}"{% endif %} + {%- if required %} required{% endif %} + {{- extras | xmlattr }}> + {% if type == "datetime" %} + <span class="input-group-btn"> + <button class="btn btn-default" type="button" onclick="{{ name }}.value = new Date().toISOString()">now</button> + </span> + </div> + {% endif %} + {% if help %} + <span class="help-block">{{ help }}</span> + {% endif %} +</div> +{% 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> + <textarea class="form-control" rows={{ rows }} id="{{ name }}" name="{{ name }}" placeholder="{{ placeholder }}"{% if required %} required{% endif %}>{% if value %}{{ value }}{% endif %}</textarea> +</div> +{% endmacro %} + +{% macro selectinput(name, label, choices, value) %} +<div class="form-group"> + <label for="{{ name }}">{{ label }}:</label> + <select class="form-control" name="{{name}}", id="{{ name }}"> + {% for choice in choices %}<option{% if value==choice %} selected{% endif %}>{{ choice }}</option>{% endfor %} + </select> +</div> +{% endmacro %} + +{# Big difference with the one above is that the choices are tuple (name, value) #} +{% macro selectinput2(name, label, choices, value, multiple=False) %} +{% if not multiple %} + {% set value= [value] %} +{% endif %} +<div class="form-group"> + <label for="{{ name }}">{{ label }}:</label> + <select class="form-control" name="{{name}}" id="{{ name }}"{% if multiple %} multiple size="{{ choices | length }}"{% endif %}> + {% for name, val in choices %}<option value="{{ val }}"{% if val in value %} selected{% endif %}>{{ name }}</option>{% endfor %} + </select> +</div> +{% endmacro %} + +{% macro panel(type="default", heading=None, title=0, collapsible=True, extended=False) %} +{% if not heading %} + {% set collapsible = False %} +{% endif %} +<div class="{{ ["panel", "panel-" + type] | join(" ") }}"> + {% if heading %} + <div class="panel-heading"> + {%- if title %}<h{{ title }} class="panel-title">{% endif -%} + {%- if collapsible %}<a data-toggle="collapse" href="#{{ heading | secure_filename }}">{% endif -%} + {{ heading }} + {%- if collapsible %}</a>{% endif -%} + {%- if title %}</h{{ title }}>{% endif -%} + </div> + {% endif %} + {% if collapsible %}<div id="{{ heading | secure_filename }}" class="panel-collapse collapse{{ ' in' if extended}}">{% endif %} + <div class="panel-body"> + {{ caller() }} + </div> + {% if collapsible %}</div>{% endif %} +</div> +{% endmacro %} + +{# This should be placed inside a .form-horizontal #} +{% macro label_value(label, value, left=2, right=10) %} +<div class="form-group"> + <label class="col-sm-{{ left }} control-label">{{ label }}:</label> + <div class="col-sm-{{ right }}"> + <p class="form-control-static">{{ value }}</p> + </div> +</div> +{% endmacro %}