Files
FamilyBook/templates/calendar/_settings_menu.php
T

118 lines
6.5 KiB
PHP
Raw Normal View History

<?php
/**
* 日程模块的「设置」下拉(v24 用户 2026-10-03 第 4、5 条)
*
* 用户原话:「日程模块,左侧的日历本显示与否,去掉,让日历充满整个宽度。
* 在右侧,也加一个设置按钮,设置中,可以设置哪些日历本显示,
* 调整日历的颜色,导入日历等功能,都放在这个设置下。」
* 「在日程的设置中,可以设置默认显示的视图模式,月视图还是周视图还是日视图。
* 把日历本这个按钮的功能,收到设置中。」
*
* 所以这个 ☰ 是**原来左边那一栏 + 「日历本」按钮**的合并去处。
* 外观与观影 / 任务的设置下拉完全一致(只留图标、排最右、条目带小图标),
* 三处同一个手势,用户不用记第二套。
*
* 两件**个人偏好**(默认视图 / 显示哪些本子)就地用表单提交;
* 其余的(颜色、共享、导入、CalDAV)是**页面级**的操作,
* 跳到「日历本」管理页 —— 那里本来就有全套,没必要在这儿再写一遍。
*
* 用法(require 前 set 好):
* $setCurrent 当前页 key('view'),用来高亮
* $cals 我可见的日历本(带 perm / color);可能为空
* $view 当前视图(回跳时保持)
* $anchor 当前锚定日(周/日视图回跳时保持)
*/
$setCurrent = (string)($setCurrent ?? '');
$setOn = static function (string $key) use ($setCurrent): string {
return $setCurrent === $key ? ' class="on"' : '';
};
$setIcon = static function (string $name): string {
$paths = [
'view' => '<rect x="2" y="3.2" width="12" height="10.4" rx="1.6"/><path d="M2 6.4h12M5.4 1.6v3.2M10.6 1.6v3.2"/>',
'books' => '<path d="M2.6 3.2h4v9.6h-4zM9.4 3.2h4v9.6h-4z"/>',
'import' => '<path d="M8 2.6v7.2M5 6.8l3 3 3-3M3.2 13.4h9.6"/>',
'dav' => '<circle cx="8" cy="8" r="5.6"/><path d="M2.4 8h11.2M8 2.4c1.8 2 2.6 3.7 2.6 5.6S9.8 12 8 13.6C6.2 11.6 5.4 9.9 5.4 8S6.2 4.4 8 2.4z"/>',
];
$d = $paths[$name] ?? '';
if ($d === '') {
return '';
}
return '<svg class="mi" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"'
. ' fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"'
. ' stroke-linejoin="round">' . $d . '</svg>';
};
$myCals = (array)($cals ?? []);
$hiddenIds = array_map('intval', (array)($hiddenCals ?? []));
$curView = (string)($view ?? 'month');
$backView = $curView;
?>
<details class="movie-set menu cal-set">
<summary class="btn btn-icon" title="日程设置" aria-label="日程设置"><svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"><path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/></svg></summary>
<div class="menu-list cal-set-list">
<?php /* ---- 默认视图 + 显示哪些本子(个人偏好,就地提交)---- */ ?>
<form method="post" action="<?= e(url('calendar/prefs')) ?>" class="cal-set-form">
<?= csrf_field() ?>
<input type="hidden" name="back_view" value="<?= e($backView) ?>">
<div class="cal-set-block">
<div class="cal-set-h">默认打开时看</div>
<div class="cal-set-views">
<?php foreach (\App\Calendar::VIEWS as $vk => $vw): ?>
<label class="cal-set-view">
<input type="radio" name="view" value="<?= e($vk) ?>"
<?= \App\Calendar::defaultView((int)\App\Auth::personId()) === $vk ? 'checked' : '' ?>>
<span><?= e($vw) ?>视图</span>
</label>
<?php endforeach; ?>
</div>
</div>
<div class="cal-set-block">
<div class="cal-set-h">显示哪些日历本</div>
<?php /* ⚠️ 这个隐藏标记是**必须**的:HTML 里"一个都没勾"会让浏览器
整个省掉 `show[]` 键,服务端就分不清「用户想全关掉」与
「这次请求没打算改显隐」—— 没有它的话,将来任何只改默认视图的
提交都会把所有日历本静默藏掉。 */ ?>
<input type="hidden" name="show_present" value="1">
<?php if (!$myCals): ?>
<p class="small muted" style="margin:0">还没有日历本。</p>
<?php else: ?>
<?php foreach ($myCals as $c): $cid = (int)$c['id']; ?>
<label class="cal-set-book">
<input type="checkbox" name="show[]" value="<?= $cid ?>"
<?= in_array($cid, $hiddenIds, true) ? '' : 'checked' ?>>
<span class="color-preview" style="background: <?= e((string)$c['color']) ?>;"></span>
<span class="cal-name"><?= e((string)$c['name']) ?></span>
<?php if ((string)$c['kind'] !== 'custom'): ?>
<span class="node-badge">系统</span>
<?php elseif ((int)$c['shared'] === 1): ?>
<span class="node-badge"><?= ($c['perm'] ?? '') === 'write' ? '共享·可写' : '共享·只读' ?></span>
<?php endif; ?>
</label>
<?php endforeach; ?>
<?php endif; ?>
<p class="small muted" style="margin:6px 0 0">
观影、旅行、有截止时间的任务会自动出现在这里,不用另建本子。
</p>
</div>
<div class="cal-set-foot">
<button class="btn btn-sm" type="submit">保存显示设置</button>
</div>
</form>
<?php /* ---- 页面级操作:颜色/新建/共享/导入/CalDAV 都在「日历本」管理页 ---- */ ?>
<div class="cal-set-links">
<a href="<?= e(url('calendar/calendars')) ?>"<?= $setOn('books') ?>><?= $setIcon('books') ?><span>日历本 · 颜色 / 共享 / 导入</span></a>
<a href="<?= e(url('calendar/calendars')) ?>#caldav"><?= $setIcon('dav') ?><span>CalDAV 订阅(在手机日历里看)</span></a>
<?php /* v24 第 22 批:口令改成通用 DAV 口令(日历 + 通讯录共用)。这条不再直接跳
日历本页那个卡片,而是跳到**口令管理**页 —— 用户从这里点进来十有八九
是"要配同步",那就该落到能生成口令的地方(日历本页现在只有地址)。 */ ?>
<a href="<?= e(url('settings/me', [], 'dav')) ?>"><?= $setIcon('dav') ?><span>DAV 口令(日历 + 通讯录)</span></a>
</div>
</div>
</details>
<?php
unset($setCurrent, $setOn, $setIcon, $myCals, $hiddenIds, $curView, $backView);