leilukin-tumbleblog/admin/partials/post_fields.twig

208 lines
8.8 KiB
Twig
Raw Normal View History

2024-06-20 14:10:42 +00:00
{{ trigger.call("before_post_fields", feather) }}
{% for field in feather.fields %}
{% if attribute(post, field.attr) is defined %}
{% set field_value = attribute(post, field.attr) %}
{% else %}
{% set field_value = field.value is defined ? field.value : "" %}
{% endif %}
{% set field_count = field_value is iterable ? field_value | length : 1 %}
{% set field_preview = field.preview is defined and field.preview ? " data-preview" : "" %}
{% set field_multiple = field.multiple is defined and field.multiple ? " multiple" : "" %}
{% set field_accept = field.accept is defined ? ' accept="' ~ (field.accept | fix(true)) ~ '"' : "" %}
{% if site.enable_markdown %}
{% set field_markdown = field.filters is defined and (field.filters | contains("markup_text")) ? " data-markdown" : "" %}
{% else %}
{% set field_markdown = "" %}
{% endif %}
{% if post is not defined %}
{% set field_required = field.optional is defined and field.optional ? "" : " required" %}
{% else %}
{% set field_required = field.type == "file" or field.optional is defined and field.optional ? "" : " required" %}
{% endif %}
{% set field_id = (field.attr ~ "_field") | fix(true) %}
{% set field_name = (field_multiple is not empty ? field.attr ~ "[]" : field.attr) | fix(true) %}
<p class="main_options">
<label for="{{ field_id }}">
{{ field.label }}
{% if field.note is defined %}
{{ field.note }}
{% endif %}
{% if field.help is defined %}
<a href="{{ url('help/id/' ~ (field.help | url_encode)) }}" rel="help" target="_blank" class="help emblem">
{{- icon_img("help.svg", "help" | translate) -}}
</a>
{% endif %}
</label>
{% if field.type == "text" %}
<input id="{{ field_id }}" class="text" type="text" name="{{ field_name }}"{{ field_markdown ~ field_required }} value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "url" %}
<input id="{{ field_id }}" class="text" type="url" name="{{ field_name }}"{{ field_required }} value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "email" %}
<input id="{{ field_id }}" class="text" type="email" name="{{ field_name }}"{{ field_required }} value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "file" %}
<input id="{{ field_id }}" type="file" name="{{ field_name }}"{{ field_accept ~ field_multiple ~ field_required }} value="">
{% if field_value is not empty %}
<span id="{{ field_name }}_field_tray" class="options_tray" role="note">
{{ "%d file previously uploaded with this post." | translate_plural("%d files previously uploaded with this post.", field_count) | format(field_count) }}
</span>
{% endif %}
{% elseif field.type == "text_block" %}
<span id="{{ field_name }}_field_toolbar" class="options_toolbar" role="toolbar">
{% if field_markdown is not empty %}<a href="{{ url('help/id/markdown') }}" target="_blank" class="help emblem markdown">
{{- icon_img("markdown.svg", "Markdown" | translate) -}}
</a>
{% endif %}</span>
<textarea id="{{ field_id }}" name="{{ field_name }}" rows="12"{{ field_preview ~ field_markdown ~ field_required }}>{{ field_value | fix(false, true) }}</textarea>
<span id="{{ field_name }}_field_tray" class="options_tray" role="status"></span>
{% elseif field.type == "checkbox" %}
<input id="{{ field_id }}" type="checkbox" name="{{ field_name }}"{{ field.checked | checked }}>
{% elseif field.type == "select" %}
<select id="{{ field_id }}" name="{{ field_name }}">
{% for value, name in field.options %}
{% set option_selected = attribute(post, field.attr) is defined ? value | selected(attribute(post, field.attr)) : "" %}
<option value="{{ value | fix(true) }}"{{ option_selected }}>
{{ name | fix }}
</option>
{% endfor %}
</select>
{% endif %}
{% if field.extra is defined %}
{{ field.extra }}
{% endif %}
</p>
{% endfor %}
{{ trigger.call("after_post_fields", feather) }}
<div id="more_options" class="more_options">
{% if visitor.group.can("add_post") %}
<p class="more_options_option">
<label for="status">{{ "Status" | translate }}</label>
<select id="status" name="status">
{% set option_selected = post is defined ? post.status | selected("draft") : "" %}
<option value="draft"{{ option_selected }}>
{{ "Draft" | translate }}
</option>
{% set option_selected = post is defined ? post.status | selected("public") : " selected" %}
<option value="public"{{ option_selected }}>
{{ "Public" | translate }}
</option>
{% set option_selected = post is defined ? post.status | selected("private") : "" %}
<option value="private"{{ option_selected }}>
{{ "Private" | translate }}
</option>
{% set option_selected = post is defined ? post.status | selected("scheduled") : "" %}
<option value="scheduled"{{ option_selected }}>
{{ "Scheduled" | translate }}
</option>
<optgroup label="{{ 'Visible only to a group of users:' | translate }}">
{% set option_selected = post is defined ? post.status | selected("registered_only") : "" %}
<option value="registered_only"{{ option_selected }}>
{{ "All registered users" | translate }}
</option>
{% if groups is not empty %}
{% for group in groups %}
{% set option_selected = post is defined ? post.status | selected("{" ~ group.id ~ "}") : "" %}
<option value="{{ '{' ~ group.id ~ '}' }}"{{ option_selected }}>
{{ group.name | fix }}
</option>
{% endfor %}
{% endif %}
</optgroup>
</select>
</p>
{% endif %}
<p class="more_options_option">
<label for="pinned">
{{ "Pinned?" | translate }}
{{ "(shows this post above all others)" | translate }}
</label>
<input id="pinned" type="checkbox" name="pinned"{{ post is defined ? post.pinned | checked : "" }}>
</p>
<p class="more_options_option">
<label for="slug">
{{ "Slug" | translate }}
<a href="{{ url('help/id/slugs') }}" rel="help" target="_blank" class="help emblem">
{{- icon_img("help.svg", "help" | translate) -}}
</a>
</label>
<input id="slug" class="text" type="text" name="slug" value="{{ post is defined ? post.clean | fix(true) : '' }}" maxlength="80">
</p>
<p class="more_options_option">
<label for="created_at">{{ "Timestamp" | translate }}</label>
{% set post_created = post is defined and post.status != "draft" ? post.created_at : now %}
<input id="created_at" class="text" type="text" name="created_at" value="{{ post_created | dateformat('Y-m-d H:i:s') | fix(true) }}">
</p>
{% for field in options %}
{% set field_value = field.value is defined ? field.value : "" %}
{% set field_multiple = field.multiple is defined and field.multiple ? " multiple" : "" %}
{% set field_accept = field.accept is defined ? ' accept="' ~ (field.accept | fix(true)) ~ '"' : "" %}
{% set field_id = ((field.attr | replace({"[": "_", "]": ''})) ~ "_field") | fix(true) %}
{% set field_name = (field_multiple is not empty ? field.attr ~ "[]" : field.attr) | fix(true) %}
<p class="more_options_option">
<label for="{{ field_id }}">
{{ field.label }}
{% if field.note is defined %}
{{ field.note }}
{% endif %}
{% if field.help is defined %}
<a href="{{ url('help/id/' ~ (field.help | url_encode)) }}" rel="help" target="_blank" class="help emblem">
{{- icon_img("help.svg", "help" | translate) -}}
</a>
{% endif %}
</label>
{% if field.type == "text" %}
<input id="{{ field_id }}" class="text" type="text" name="{{ field_name }}" value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "url" %}
<input id="{{ field_id }}" class="text" type="url" name="{{ field_name }}" value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "email" %}
<input id="{{ field_id }}" class="text" type="email" name="{{ field_name }}" value="{{ field_value | fix(true, true) }}">
{% elseif field.type == "file" %}
<input id="{{ field_id }}" type="file" name="{{ field_name }}"{{ field_accept ~ field_multiple }} value="">
{% elseif field.type == "text_block" %}
<textarea id="{{ field_id }}" name="{{ field_name }}" rows="12">{{ field_value | fix(false, true) }}</textarea>
{% elseif field.type == "checkbox" %}
<input id="{{ field_id }}" type="checkbox" name="{{ field_name }}"{{ field.checked | checked }}>
{% elseif field.type == "select" %}
<select id="{{ field_id }}" name="{{ field_name }}">
{% for option in field.options %}
{% set option_selected = option.selected | selected(true) %}
<option value="{{ option.value | fix(true) }}"{{ option_selected }}>
{{ option.name | fix }}
</option>
{% endfor %}
</select>
{% endif %}
{% if field.extra is defined %}
{{ field.extra }}
{% endif %}
</p>
{% endfor %}
</div>
<div class="buttons confirmation">
{% if route.action == "edit_post" %}
{% if visitor.group.can("add_post") and post.status == "draft" %}
<button type="submit" class="yay" name="publish" value="true">
{{ "Publish" | translate }}
</button>
<button type="submit">
{{ "Save" | translate }}
</button>
{% else %}
<button type="submit">
{{ "Save" | translate }}
</button>
<button type="submit" class="boo" name="cancel" value="true" data-confirm="">
{{ "Cancel" | translate }}
</button>
{% endif %}
{% else %}
{% if visitor.group.can("add_post") %}
<button type="submit" class="yay">
{{ "Publish" | translate }}
</button>
{% endif %}
<button type="submit" name="draft" value="true">
{{ "Save" | translate }}
</button>
{% endif %}
</div>