Files
FamilyBook/templates/trips/types.php
T

78 lines
3.4 KiB
PHP
Raw Normal View History

<?php
/**
* 节点类型设置(v24 第 16 批 用户第 8 条)。
*
* 用户第 7 条要求照 TripLog 的添加节点功能,TripLog 的节点类型是**可自定义的**:
* 内置几种(游玩/用餐/赶路/住宿/其他)+ 用户自己加。
*
* ⚠️ 内置的不许删(删了会被自动预置回来,看起来像"删不掉");
* 还在被行程使用的也不许删(行程里存的是名字,删了那些行程就显示成"其他")。
*
* @param array $types NodeType::all()(带 used 计数)
*/
$canWrite = \App\Auth::canWrite();
$types = $types ?? [];
$back = url('trips');
?>
<div class="page-head">
<h1>节点类型</h1>
<span class="sub">行程分几类,你自己定</span>
<div class="actions">
<a class="btn btn-ghost" href="<?= e($back) ?>">返回旅程</a>
<?php $trSetCurrent = 'types'; require __DIR__ . '/_settings_menu.php'; ?>
</div>
</div>
<?php if (!$canWrite): ?>
<div class="card card-pad"><p class="empty-hint">只读账号不能改设置。</p></div>
<?php else: ?>
<div class="card card-pad">
<h2 class="cinema-h2">现有类型</h2>
<ul class="type-list">
<?php foreach ($types as $t): ?>
<li class="type-row">
<form class="inline-form type-form" method="post" action="<?= e(url('trips/types_save')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$t['id'] ?>">
<input class="input type-ico" name="icon" maxlength="4"
value="<?= e((string)($t['icon'] ?? '')) ?>" aria-label="图标">
<input class="input" name="name" value="<?= e((string)$t['name']) ?>"
required aria-label="类型名">
<?php if ((int)$t['is_system'] === 1): ?>
<span class="type-tag">内置</span>
<?php else: ?>
<span class="type-tag type-tag-custom">自定义</span>
<?php endif; ?>
<span class="type-used small muted">
<?= (int)($t['used'] ?? 0) ?> 段在用
</span>
<button class="btn btn-sm" type="submit">保存</button>
</form>
<?php if ((int)$t['is_system'] === 0): ?>
<form class="inline-form" method="post" action="<?= e(url('trips/types_del')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$t['id'] ?>">
<button class="btn btn-ghost btn-sm" type="submit"
onclick="return confirm('删掉类型「<?= e((string)$t['name']) ?>」?')">删</button>
</form>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<p class="small muted">
内置的几种不能删(可以改名)。已经有行程在用的类型也不能删 ——
先到那些行程里把它们改成别的类型。
</p>
</div>
<div class="card card-pad">
<h2 class="cinema-h2">加一个类型</h2>
<form class="inline-form type-form type-add" method="post" action="<?= e(url('trips/types_save')) ?>">
<?= csrf_field() ?>
<input class="input type-ico" name="icon" maxlength="4" placeholder="🎣" aria-label="图标">
<input class="input" name="name" placeholder="类型名,如「赶海」" required aria-label="类型名">
<button class="btn btn-sm" type="submit">加进类型库</button>
</form>
<p class="tip">图标填一个表情符号就行(如 🎣 🏖 🍜)。</p>
</div>
<?php endif; ?>