Viewport onto your services
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

247 lines
10 KiB

{% macro _render_field_data(field, field_block_id, field_text,
field_block_status, static=False, add_hidden=False) %}
{% set class = ["is_invalid" if kwargs.get("error"),
field.render_kw.get("class", "") if field.render_kw,
kwargs.get("class_", ""),
"form-control"] %}
{% if static or field.flags.static %}
{% if add_hidden or field.flags.add_hidden %}
<input type="hidden" name="{{ field.name }}" id="{{ field_block_id }}" value="{{ field.data }}">
{% endif %}
<p class="form-control-static">
{{ field.data or "No information" }}
</p>
{% else %}
{{ field(class=class|join(" ")|trim, id=field_block_id, placeholder=field_text,
aria_describedby=field_block_status, readonly=field.flags.readonly, **kwargs) | safe }}
{% endif %}
{% endmacro %}
{% macro render_field(field, show_errors=True, btn_class="default", static=False, extra_class=None, btn_group=False) %}
{% set field_id = field.id %}
{% set field_block_id = "{}Block".format(field_id) %}
{% set field_block_status = "{}Status".format(field_id) %}
{% set field_text = field.label.text %}
{% if field.type == "HiddenField" %}
{{ field(class="form-control", id=field_block_id, **kwargs) | safe }}
{% elif field.type == "SubmitField" and btn_group %}
{{ field(class="btn btn-{}".format(btn_class), **kwargs) }}
{% elif field.type == "SubmitField" %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
{{ field(class="btn btn-{}".format(btn_class), **kwargs) }}
</div>
<div class="clearfix"></div>
</div>
{% elif field.type == "FieldList" %}
{{ render_fieldlist(field, show_errors, static=static, **kwargs) }}
{% else %}
<div class="form-group{% if show_errors and field.errors %} has-error has-feedback{% endif -%}
{% if field.flags.required %} required{% endif -%}">
{% if field.type == "BooleanField" %}
<div class="col-sm-offset-2 col-sm-7">
<div class="checkbox">
<label>
<input type="checkbox" name="{{ field.name }}" id="{{ field_block_id }}"
{% if field.data -%} checked{% endif %}> {{ field_text }}
</label>
</div>
</div>
{% elif field.type == "RadioField" %}
{{ field.label(class="control-label col-sm-2", for=field_block_id, **kwargs) | safe }}
<div class="col-sm-7">
<div class="radio">
<label>
{{ field }}
</label>
</div>
</div>
{% elif field.type == "FormField" %}
{% for fl in field %}
{% if fl.type != "CSRFTokenField" %}
{{ render_field(fl) }}
{% endif %}
{% endfor %}
{% else %}
{{ field.label(class="control-label col-sm-2", for=field_block_id, **kwargs) | safe }}
<div class="col-sm-7 {{ extra_class if extra_class else "" }}">
{{ _render_field_data(field, field_block_id, field_text,
field_block_status, static, **kwargs) }}
{% if show_errors and field.errors %}
<span class="form-control-feedback"><i class="fa fa-times" aria-hidden="true"></i></span>
{% endif %}
</div>
{% endif %}
{% if show_errors and field.errors -%}
<span id="{{ field_block_status }}" class="sr-only">(error)</span>
<div id="{{ field.id }}Help" class="help-block col-sm-3">
{% for error in field.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif -%}
</div>
{% if field.type == "FormField" %}
<div class="clearfix"></div>
{% endif %}
{% endif %}
{% endmacro %}
{% macro render_fieldlist(field, show_errors=True, static=False, subform=True,
colgroup=(), actions=True, sortable=False,
sub_fieldlist=None, embed_add=False, headers=True) %}
{% set field_id = field.id %}
{% set field_block_id = "{}Block".format(field_id) %}
{% set field_block_status = "{}Status".format(field_id) %}
{% set field_text = field.label.text %}
{% set sub_fieldlist = sub_fieldlist if sub_fieldlist else kwargs %}
{% if subform %}
{{ field.label(class="control-label col-sm-2", for=field_block_id, **kwargs) | safe }}
<div class="col-sm-9" id="{{ field_block_id }}">
{% for fl in field.entries %}
<div class="form-inline">
{% for sub_field in fl %}
{% set field_id = sub_field.id %}
{% set field_block_id = "{}Block".format(field_id) %}
{% set field_block_status = "{}Status".format(field_id) %}
{% set field_text = sub_field.label.text %}
{% if sub_field.type == "HiddenField" %}
{{ sub_field(class="form-control", id=field_block_id, **kwargs) | safe }}
{% elif sub_field.type == "CSRFTokenField" %}
{# skip #}
{% else %}
{% set field_static = static[sub_field.short_name] if static is iterable else static %}
<div class="{% if show_errors and sub_field.errors %}has-error has-feedback{% endif -%}
{% if sub_field.flags.required %} required{% endif -%}">
{{ _render_field_data(sub_field, field_block_id, field_text,
field_block_status, field_static, **kwargs) }}
{% if show_errors and sub_field.errors %}
<span id="{{ field_block_status }}" class="sr-only">(error)</span>
<div id="{{ field.id }}Help" class="help-block">
{% for error in sub_field.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
</div>
{% else %}
<div class="table-responsive" id="{{ field_id }}">
<table class="table table-hover">
<colgroup>
<col class="col-sm-1">
{% if colgroup %}
{% for col in colgroup %}
<col class="col-sm-{{ col }}">
{% endfor %}
{% endif %}
</colgroup>
{% for fl in field.entries %}
{% set template = "template" in fl.data.get("id") if fl.data.get("id") is iterable else False %}
{% if headers and loop.first %}
<thead>
<th>
{%- if actions and embed_add -%}
<a class="add btn btn-info btn-sm">
<i class="fa fa-plus-circle"></i> Add
</a>
{% endif %}
</th>
{% for sub_field in fl %}
{% if sub_field.type not in ("HiddenField", "CSRFTokenField") %}
<th>{{ sub_field.label }}</th>
{% endif %}
{% endfor %}
</thead>
<tbody>
{% endif %}
{% if template and actions %}
<tr id="template" class="template">
{% else %}
<tr id="{{ fl.id }}">
{% endif %}
<td>
{% if actions %}
<button class="remove btn btn-danger btn-sm" type="button" onclick="return false;" id="delete_{{ fl.id }}">
<i class="fa fa-trash"></i> Delete
</button>
<button class="undo btn btn-info btn-sm" id="undo_{{ fl.id }}" type="button" onclick="return false;">
<i class="fa fa-undo"></i> Undo delete
</button>
{% if sortable %}
<span class="move" id="move_{{ fl.id }}" style="cursor: move; padding: 0 10px;">
<i class="fa fa-ellipsis-v fa-lg fa-fw"></i>
</span>
{% endif %}
{% endif %}
</td>
{% for sub_field in fl %}
{% set field_id = sub_field.id %}
{% set field_block_id = "{}Block".format(field_id) %}
{% set field_block_status = "{}Status".format(field_id) %}
{% set field_text = sub_field.label.text %}
{% if sub_field.type == "HiddenField" %}
{{ sub_field(class="form-control", id=field_block_id, **kwargs) | safe }}
{% if sub_field.flags.show_hidden_data %}
<td class="{% if show_errors and sub_field.errors %}has-error has-feedback{% endif -%}
{% if sub_field.flags.required %} required{% endif -%}">
{{ _render_field_data(sub_field, field_block_id, field_text,
field_block_status, True, **kwargs) }}
</td>
{% endif %}
{% elif sub_field.type == "CSRFTokenField" %}
{# skip #}
{% elif sub_field.type == "FieldList" %}
<td>
{{ render_fieldlist(sub_field, **sub_fieldlist) }}
</td>
{% else %}
{% set field_static = static[sub_field.short_name] if static is iterable else static %}
<td class="{% if show_errors and sub_field.errors %}has-error has-feedback{% endif -%}
{% if sub_field.flags.required %} required{% endif -%}">
{{ _render_field_data(sub_field, field_block_id, field_text,
field_block_status, field_static, **kwargs) }}
{% if show_errors and sub_field.errors %}
<span id="{{ field_block_status }}" class="sr-only">(error)</span>
<div id="{{ field.id }}Help" class="help-block">
{% for error in sub_field.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
</td>
{% endif %}
{% endfor %}
</tr>
{% if loop.last %}
</tbody>
{% endif %}
{% else %}
<tr>
No items.
</tr>
{% endfor %}
</table>
</div>
{% endif %}
<div class="clearfix">&nbsp;</div>
{% endmacro %}
{% macro render_button_group(buttons, label) %}
<div class="btn-group col-sm-offset-2 col-sm-10" role="group" aria-label="{{ label }}">
{% for btn_field, btn_class in buttons %}
{{ btn_field(class="btn btn-{}".format(btn_class), **kwargs) }}
{% endfor %}
</div>
<div class="clearfix"></div>
{% endmacro %}