{# The inline add (src/handlers/categories.rs add_slot): a `+` tile that
swaps to a form, which swaps to the new card plus a fresh `+` (or back to
the `+` on Cancel / Escape). `add` is an AddSlot. Every request targets the
slot itself, never the boosted #content. #}
{% set slot_id = "cat-add-" ~ (add.parent or "root") %}
{% set slot_url = "/admin/categories/slot?parent=" ~ add.parent if add.parent else "/admin/categories/slot?" %}
{% if not add.adding %}
<button type="button" id="{{ slot_id }}"
hx-get="{{ slot_url }}&form=1" hx-target="this" hx-select="unset" hx-swap="outerHTML"
title="{% if add.parent_name %}Add a subcategory to {{ add.parent_name }}{% else %}Add a category{% endif %}"
aria-label="{% if add.parent_name %}Add a subcategory to {{ add.parent_name }}{% else %}Add a category{% endif %}"
class="flex items-center justify-center gap-2 rounded-box border-2 border-dashed border-base-300 text-base-content/50 transition-all hover:-translate-y-0.5 hover:border-primary/60 hover:text-primary focus-visible:outline-2 focus-visible:outline-primary
{% if add.depth == 1 %}min-h-40 text-3xl{% elif add.depth == 2 %}min-h-24 text-2xl{% else %}min-h-14 text-xl{% endif %}">
<i class="fas fa-plus" aria-hidden="true"></i>
{% if add.depth == 1 %}<span class="text-sm font-medium">Add category</span>{% endif %}
</button>
{% else %}
<form id="{{ slot_id }}" hx-post="/admin/categories/inline" hx-target="this" hx-select="unset" hx-swap="outerHTML"
hx-on:keydown="if (event.key === 'Escape') { event.preventDefault(); this.querySelector('[data-cancel]').click(); }"
class="flex flex-col gap-2 rounded-box border-2 border-primary/60 bg-base-100 p-3 shadow-md">
<input type="hidden" name="parent_id" value="{{ add.parent }}">
<p class="text-xs font-semibold opacity-70">
{% if add.parent_name %}New subcategory in {{ add.parent_name }}{% else %}New category{% endif %}
</p>
<input type="text" name="name" value="{{ add.name }}" required autofocus maxlength="100"
placeholder="Name" aria-label="Name" class="input input-sm input-bordered w-full">
<div class="flex items-center gap-2">
<input type="color" name="color" value="{{ add.color }}" aria-label="Colour" title="Colour"
class="h-8 w-10 shrink-0 cursor-pointer rounded border border-base-300 bg-transparent">
<select name="min_trust_level" aria-label="Who can see it" class="select select-sm select-bordered min-w-0 flex-1">
{% for v, label in [("public", "Public"), ("0", "Logged-in"), ("1", "TL1+"), ("2", "TL2+"), ("3", "TL3+"), ("4", "TL4+")] %}
<option value="{{ v }}" {% if add.min_trust == v %}selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>
</div>
<div class="grid grid-cols-2 gap-2">
<label class="form-control">
<span class="label-text-alt opacity-70">Start topics</span>
<select name="topic_rule" aria-label="Who can start topics" class="select select-xs select-bordered">
{% for v, label in rule_options %}<option value="{{ v }}" {% if add.topic_rule == v %}selected{% endif %}>{{ label }}</option>{% endfor %}
</select>
</label>
<label class="form-control">
<span class="label-text-alt opacity-70">Reply</span>
<select name="reply_rule" aria-label="Who can reply" class="select select-xs select-bordered">
{% for v, label in rule_options %}<option value="{{ v }}" {% if add.reply_rule == v %}selected{% endif %}>{{ label }}</option>{% endfor %}
</select>
</label>
</div>
<label class="form-control">
<span class="label-text-alt opacity-70">Reactions</span>
{# A subcategory starts with its parent's; "only some" keeps the parent's
set (change it in the full form). #}
<select name="reactions" aria-label="Reactions" class="select select-xs select-bordered">
<option value="all" {% if add.reactions == "all" %}selected{% endif %}>All reactions</option>
{% if add.reaction_keys %}<option value="some" {% if add.reactions == "some" %}selected{% endif %}>Only {{ add.reaction_keys | join(", ") }} (as the parent)</option>{% endif %}
<option value="none" {% if add.reactions == "none" %}selected{% endif %}>No reactions</option>
</select>
{% for k in add.reaction_keys %}<input type="hidden" name="rk_{{ k }}" value="on">{% endfor %}
</label>
{% if add.error %}<p class="text-xs text-error" role="alert">{{ add.error }}</p>{% endif %}
<div class="flex justify-end gap-1">
<button type="button" data-cancel class="btn btn-ghost btn-xs"
hx-get="{{ slot_url }}" hx-target="closest form" hx-select="unset" hx-swap="outerHTML">Cancel</button>
<button type="submit" class="btn btn-primary btn-xs"><i class="fas fa-plus mr-1"></i>Add</button>
</div>
</form>
{% endif %}
neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
4.7 KiB · text
History
263b40b