Add page editing and publish
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
{# Рекурсивные макросы для форм по схеме полей (см. web/admin/forms.py: build_view) #}
|
||||
{% macro bind_box(name, bind) %}
|
||||
<details class='bind'{% if bind %} open{% endif %}>
|
||||
<summary>привязка</summary>
|
||||
<input type='text' name='{{ name }}._bind' value='{{ bind }}' placeholder='entry.title · page.body · site.name'>
|
||||
</details>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro datalist(f) %}
|
||||
{% if f.datalist %}<datalist id='dl-{{ f.name }}'>{% for v in f.datalist %}<option value='{{ v }}'>{% endfor %}</datalist>{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro field(f) %}
|
||||
<div class='field'>
|
||||
{% if f.kind == 'group' %}
|
||||
<fieldset>
|
||||
<legend>{{ f.label }}{% if f.required %} *{% endif %}</legend>
|
||||
{% for c in f.children %}{{ field(c) }}{% endfor %}
|
||||
{{ bind_box(f.name, f.bind) }}
|
||||
</fieldset>
|
||||
{% elif f.kind == 'list' %}
|
||||
<fieldset class='list'>
|
||||
<legend>{{ f.label }}{% if f.required %} *{% endif %}</legend>
|
||||
{% for row in f.rows %}
|
||||
<div class='row{% if row.blank %} blank{% endif %}'>
|
||||
{% if row.item %}{{ field(row.item) }}{% else %}{% for c in row.children %}{{ field(c) }}{% endfor %}{% endif %}
|
||||
{{ bind_box(row.name, row.bind) }}
|
||||
{% if row.blank %}
|
||||
<span class='hint'>Пустая строка: заполните её, чтобы добавить элемент.</span>
|
||||
{% else %}
|
||||
<label class='inline'><input type='checkbox' name='{{ row.name }}._del' value='1'> удалить элемент</label>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
{% elif f.kind == 'link' %}
|
||||
<fieldset class='link'>
|
||||
<legend>{{ f.label }}{% if f.required %} *{% endif %}</legend>
|
||||
{% set kinds = [('page', 'страница'), ('entry', 'запись'), ('url', 'адрес')] %}
|
||||
<select name='{{ f.name }}.kind'>
|
||||
{% for k, title in kinds %}<option value='{{ k }}'{% if f.link_kind == k %} selected{% endif %}>{{ title }}</option>{% endfor %}
|
||||
</select>
|
||||
<input type='text' name='{{ f.name }}.target' value='{{ f.target }}' placeholder='contacts · services/bots · https://…'>
|
||||
<input type='text' name='{{ f.name }}.label' value='{{ f.link_label }}' placeholder='подпись'>
|
||||
<label class='inline'><input type='checkbox' name='{{ f.name }}.new_tab' value='1'{% if f.new_tab %} checked{% endif %}> в новой вкладке</label>
|
||||
{{ bind_box(f.name, f.bind) }}
|
||||
</fieldset>
|
||||
{% elif f.kind == 'query' %}
|
||||
<fieldset class='query'>
|
||||
<legend>{{ f.label }}{% if f.required %} *{% endif %}</legend>
|
||||
<label>Коллекция
|
||||
<select name='{{ f.name }}.collection'>
|
||||
<option value=''>—</option>
|
||||
{% for c in f.collections %}<option value='{{ c }}'{% if c == f.collection %} selected{% endif %}>{{ c }}</option>{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>Сортировка <input type='text' name='{{ f.name }}.sort' value='{{ f.sort }}' placeholder='order или -date'></label>
|
||||
<label>Лимит <input type='text' inputmode='numeric' name='{{ f.name }}.limit' value='{{ f.limit }}'></label>
|
||||
<label>Только эти записи (slug через запятую) <input type='text' name='{{ f.name }}.ids' value='{{ f.ids }}'></label>
|
||||
<label>Фильтр (YAML, например <code>featured: true</code>)
|
||||
<textarea name='{{ f.name }}.where' rows='2'>{{ f.where }}</textarea>
|
||||
</label>
|
||||
{{ bind_box(f.name, f.bind) }}
|
||||
</fieldset>
|
||||
{% elif f.kind == 'multiselect' %}
|
||||
<fieldset>
|
||||
<legend>{{ f.label }}</legend>
|
||||
{% for o in f.options %}
|
||||
<label class='inline'><input type='checkbox' name='{{ f.name }}' value='{{ o.value }}'{% if o.selected %} checked{% endif %}> {{ o.label }}</label>
|
||||
{% endfor %}
|
||||
{{ bind_box(f.name, f.bind) }}
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<label>{{ f.label }}{% if f.required %} *{% endif %}
|
||||
{% if f.kind == 'textarea' %}
|
||||
<textarea name='{{ f.name }}' rows='6'>{{ f.value }}</textarea>
|
||||
{% elif f.kind == 'select' %}
|
||||
<select name='{{ f.name }}'>{% for o in f.options %}<option value='{{ o.value }}'{% if o.selected %} selected{% endif %}>{{ o.label }}</option>{% endfor %}</select>
|
||||
{% elif f.kind == 'date' %}
|
||||
<input type='date' name='{{ f.name }}' value='{{ f.value }}'>
|
||||
{% elif f.kind == 'number' %}
|
||||
<input type='text' inputmode='decimal' name='{{ f.name }}' value='{{ f.value }}'>
|
||||
{% else %}
|
||||
<input type='text' name='{{ f.name }}' value='{{ f.value }}'{% if f.datalist %} list='dl-{{ f.name }}'{% endif %}>
|
||||
{% endif %}
|
||||
</label>
|
||||
{{ datalist(f) }}
|
||||
{% if f.hint %}<small class='hint'>{{ f.hint }}</small>{% endif %}
|
||||
{{ bind_box(f.name, f.bind) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
Reference in New Issue
Block a user