1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00
AdvLabDB/advlabdb/templates/admin/lib.html

293 lines
10 KiB
HTML
Raw Normal View History

2021-05-17 19:34:49 +00:00
{% import 'admin/static.html' as admin_static with context %}
{# ---------------------- Pager -------------------------- #}
{% macro pager(page, pages, generator) -%}
{% if pages > 1 %}
<ul class="pagination">
{% set min = page - 3 %}
{% set max = page + 3 + 1 %}
{% if min < 0 %}
{% set max = max - min %}
{% endif %}
{% if max >= pages %}
{% set min = min - max + pages %}
{% endif %}
{% if min < 0 %}
{% set min = 0 %}
{% endif %}
{% if max >= pages %}
{% set max = pages %}
{% endif %}
{% if min > 0 %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
<a class="page-link" href="{{ generator(0) }}">&laquo;</a>
2021-05-17 19:34:49 +00:00
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item disabled">
<a class="page-link" href="javascript:void(0)">&laquo;</a>
2021-05-17 19:34:49 +00:00
</li>
{% endif %}
{% if page > 0 %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
<a class="page-link" href="{{ generator(page-1) }}">&lt;</a>
2021-05-17 19:34:49 +00:00
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item disabled">
<a class="page-link" href="javascript:void(0)">&lt;</a>
2021-05-17 19:34:49 +00:00
</li>
{% endif %}
{% for p in range(min, max) %}
{% if page == p %}
2022-03-02 22:35:20 +00:00
<li class="page-item active">
<a class="page-link" href="javascript:void(0)">{{ p + 1 }}</a>
2021-05-17 19:34:49 +00:00
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
<a class="page-link" href="{{ generator(p) }}">{{ p + 1 }}</a>
2021-05-17 19:34:49 +00:00
</li>
{% endif %}
{% endfor %}
{% if page + 1 < pages %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
<a class="page-link" href="{{ generator(page + 1) }}">&gt;</a>
2021-05-17 19:34:49 +00:00
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item disabled">
<a class="page-link" href="javascript:void(0)">&gt;</a>
2021-05-17 19:34:49 +00:00
</li>
{% endif %}
{% if max < pages %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
<a class="page-link" href="{{ generator(pages - 1) }}">&raquo;</a>
2021-05-17 19:34:49 +00:00
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item disabled">
<a class="page-link" href="javascript:void(0)">&raquo;</a>
2021-05-17 19:34:49 +00:00
</li>
{% endif %}
</ul>
{% endif %}
{%- endmacro %}
{% macro simple_pager(page, have_next, generator) -%}
<ul class="pagination">
{% if page > 0 %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
2021-05-17 19:34:49 +00:00
<a href="{{ generator(page - 1) }}">&lt;</a>
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item disabled">
2021-05-17 19:34:49 +00:00
<a href="{{ generator(0) }}">&lt;</a>
</li>
{% endif %}
{% if have_next %}
2022-03-02 22:35:20 +00:00
<li class="page-item">
2021-05-17 19:34:49 +00:00
<a href="{{ generator(page + 1) }}">&gt;</a>
</li>
{% else %}
2022-03-02 22:35:20 +00:00
<li class="page-item disabled">
2021-05-17 19:34:49 +00:00
<a href="{{ generator(page) }}">&gt;</a>
</li>
{% endif %}
</ul>
{%- endmacro %}
{# ---------------------- Modal Window ------------------- #}
{% macro add_modal_window(modal_window_id='fa_modal_window', modal_label_id='fa_modal_label') %}
<div class="modal fade" id="{{ modal_window_id }}" tabindex="-1" role="dialog" aria-labelledby="{{ modal_label_id }}">
2022-03-02 22:35:20 +00:00
<div class="modal-dialog modal-xl" role="document">
2021-05-17 19:34:49 +00:00
{# bootstrap version > 3.1.0 required for this to work #}
<div class="modal-content">
</div>
</div>
</div>
{% endmacro %}
{% macro add_modal_button(url='', title='', content='', modal_window_id='fa_modal_window', btn_class='icon') %}
<a class="{{ btn_class }}" data-target="#{{ modal_window_id }}" title="{{ title }}" href="{{ url }}" data-toggle="modal">
{{ content|safe }}
</a>
{% endmacro %}
{# ---------------------- Forms -------------------------- #}
{% macro render_field(form, field, kwargs={}, caller=None) %}
{% set direct_error = h.is_field_error(field.errors) %}
2022-03-02 22:35:20 +00:00
{% set prepend = kwargs.pop('prepend', None) %}
{% set append = kwargs.pop('append', None) %}
<div class="form-group {{ kwargs.get('column_class', '') }}">
<label for="{{ field.id }}" class="control-label" {% if field.widget.input_type == 'checkbox' %}style="display: block"{% endif %}>{{ field.label.text }}
2021-05-17 19:34:49 +00:00
{% if h.is_required_form_field(field) %}
<strong style="color: red">&#42;</strong>
{%- else -%}
&nbsp;
{%- endif %}
</label>
2022-03-02 22:35:20 +00:00
{% if prepend or append %}
<div class="input-group">
{%- if prepend -%}
<div class="input-group-prepend">
{{ prepend }}
</div>
{%- endif -%}
{% endif %}
{% if field.widget.input_type == 'checkbox' %}
{% set _class = kwargs.setdefault('class', 'form-control-lg') %}
{% elif field.widget.input_type == 'file' %}
{% set _class = kwargs.setdefault('class', 'form-control-file') %}
{% else %}
{% set _class = kwargs.setdefault('class', 'form-control') %}
2021-05-17 19:34:49 +00:00
{% endif %}
2022-03-02 22:35:20 +00:00
{%- if direct_error %} {% set _ = kwargs.update({'class': kwargs['class'] ~ ' is-invalid'}) %} {% endif -%}
{{ field(**kwargs) | safe }}
{%- if append -%}
<div class="input-group-append">
{{ append }}
</div>
{%- endif -%}
2021-05-17 19:34:49 +00:00
{% if direct_error %}
2022-03-02 22:35:20 +00:00
<div class="invalid-feedback">
<ul class="help-block">
{% for e in field.errors if e is string %}
<li>{{ e }}</li>
{% endfor %}
</ul>
</div>
{% elif field.description %}
<div class="help-block">{{ field.description|safe }}</div>
2021-05-17 19:34:49 +00:00
{% endif %}
2022-03-02 22:35:20 +00:00
{% if prepend or append %}
2021-05-17 19:34:49 +00:00
</div>
2022-03-02 22:35:20 +00:00
{% endif %}
2021-05-17 19:34:49 +00:00
{% if caller %}
{{ caller(form, field, direct_error, kwargs) }}
{% endif %}
</div>
{% endmacro %}
{% macro render_header(form, text) %}
<h3>{{ text }}</h3>
{% endmacro %}
{% macro render_form_fields(form, form_opts=None) %}
{% if form.hidden_tag is defined %}
{{ form.hidden_tag() }}
{% else %}
{% if csrf_token %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
{% endif %}
{% for f in form if f.widget.input_type == 'hidden' %}
{{ f }}
{% endfor %}
{% endif %}
{% if form_opts and form_opts.form_rules %}
{% for r in form_opts.form_rules %}
{{ r(form, form_opts=form_opts) }}
{% endfor %}
{% else %}
{% for f in form if f.widget.input_type != 'hidden' %}
{% if form_opts %}
{% set kwargs = form_opts.widget_args.get(f.short_name, {}) %}
{% else %}
{% set kwargs = {} %}
{% endif %}
{{ render_field(form, f, kwargs) }}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro form_tag(form=None, action=None) %}
2022-03-02 22:35:20 +00:00
<form action="{{ action or '' }}" method="POST" role="form" class="admin-form" enctype="multipart/form-data">
<fieldset>
2021-05-17 19:34:49 +00:00
{{ caller() }}
2022-03-02 22:35:20 +00:00
</fieldset>
2021-05-17 19:34:49 +00:00
</form>
{% endmacro %}
{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %}
2022-03-02 22:35:20 +00:00
{% if is_modal %}
<input type="submit" class="btn btn-primary" value="{{ _gettext('Save') }}" />
{% if extra %}
{{ extra }}
{% endif %}
{% if cancel_url %}
<a href="{{ cancel_url }}" class="btn btn-danger" role="button" {% if is_modal %}data-dismiss="modal"{% endif %}>{{ _gettext('Cancel') }}</a>
{% endif %}
{% else %}
2021-05-17 19:34:49 +00:00
<hr>
<div class="form-group">
<div class="col-md-offset-2 col-md-10 submit-row">
<input type="submit" class="btn btn-primary" value="{{ _gettext('Save') }}" />
{% if extra %}
{{ extra }}
{% endif %}
{% if cancel_url %}
<a href="{{ cancel_url }}" class="btn btn-danger" role="button" {% if is_modal %}data-dismiss="modal"{% endif %}>{{ _gettext('Cancel') }}</a>
{% endif %}
</div>
</div>
2022-03-02 22:35:20 +00:00
{% endif %}
2021-05-17 19:34:49 +00:00
{% endmacro %}
{% macro render_form(form, cancel_url, extra=None, form_opts=None, action=None, is_modal=False) -%}
{% call form_tag(action=action) %}
{{ render_form_fields(form, form_opts=form_opts) }}
{{ render_form_buttons(cancel_url, extra, is_modal) }}
{% endcall %}
{% endmacro %}
{% macro form_css() %}
2022-03-02 22:35:20 +00:00
<link href="{{ admin_static.url(filename='vendor/select2/select2.css', v='4.2.1') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/select2/select2-bootstrap4.css', v='1.4.6') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker-bs4.css', v='1.3.22') }}" rel="stylesheet">
2021-05-17 19:34:49 +00:00
{% if config.MAPBOX_MAP_ID %}
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.css', v='1.0.2') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.css', v='0.4.6') }}" rel="stylesheet">
{% endif %}
{% if editable_columns %}
2022-03-02 22:35:20 +00:00
<link href="{{ admin_static.url(filename='vendor/x-editable/css/bootstrap4-editable.css', v='1.5.1.1') }}" rel="stylesheet">
2021-05-17 19:34:49 +00:00
{% endif %}
{% endmacro %}
{% macro form_js() %}
{% if config.MAPBOX_MAP_ID %}
<script>
window.MAPBOX_MAP_ID = "{{ config.MAPBOX_MAP_ID }}";
{% if config.MAPBOX_ACCESS_TOKEN %}
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_ACCESS_TOKEN }}";
{% endif %}
{% if config.DEFAULT_CENTER_LAT and config.DEFAULT_CENTER_LONG %}
window.DEFAULT_CENTER_LAT = "{{ config.DEFAULT_CENTER_LAT }}";
window.DEFAULT_CENTER_LONG = "{{ config.DEFAULT_CENTER_LONG }}";
{% endif %}
</script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.js', v='1.0.2') }}"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.js', v='0.4.6') }}"></script>
{% if config.MAPBOX_SEARCH %}
<script>
window.MAPBOX_SEARCH = "{{ config.MAPBOX_SEARCH }}";
</script>
<script src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places&key={{ config.get('GOOGLE_MAPS_API_KEY') }}"></script>
{% endif %}
{% endif %}
<script src="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker.js', v='1.3.22') }}"></script>
{% if editable_columns %}
2022-03-02 22:35:20 +00:00
<script src="{{ admin_static.url(filename='vendor/x-editable/js/bootstrap4-editable.min.js', v='1.5.1.1') }}"></script>
2021-05-17 19:34:49 +00:00
{% endif %}
<script src="{{ admin_static.url(filename='admin/js/form.js', v='1.0.1') }}"></script>
{% endmacro %}
{% macro extra() %}
{% if admin_view.can_create %}
2022-03-02 22:35:20 +00:00
<input name="_add_another" type="submit" class="btn btn-secondary" value="{{ _gettext('Save and Add Another') }}" />
2021-05-17 19:34:49 +00:00
{% endif %}
{% if admin_view.can_edit %}
2022-03-02 22:35:20 +00:00
<input name="_continue_editing" type="submit" class="btn btn-secondary" value="{{ _gettext('Save and Continue Editing') }}" />
2021-05-17 19:34:49 +00:00
{% endif %}
{% endmacro %}