2026-11-08 03:30:58 +08:00
|
|
|
|
'use strict';
|
2026-12-04 01:30:49 +08:00
|
|
|
|
let pocketEditor = null,
|
|
|
|
|
|
pocketManagerSearch = '';
|
2026-11-08 03:30:58 +08:00
|
|
|
|
let pocketManagerOpen = false,
|
|
|
|
|
|
pocketManagerRows = null,
|
|
|
|
|
|
pocketManagerRequest = 0,
|
|
|
|
|
|
pocketManagerUser = '',
|
|
|
|
|
|
pocketManagerStale = false;
|
|
|
|
|
|
function pocketManagerIdentity() {
|
|
|
|
|
|
return [requestUser(), state?.user?.role || ''].join(':');
|
2026-12-04 01:30:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
function invalidatePocketManager() {
|
|
|
|
|
|
closePocketEditor(true);
|
|
|
|
|
|
++pocketManagerRequest;
|
|
|
|
|
|
pocketManagerRows = null;
|
|
|
|
|
|
pocketManagerOpen = false;
|
|
|
|
|
|
pocketManagerUser = '';
|
|
|
|
|
|
pocketManagerStale = false;
|
2026-11-08 03:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
function pocketManagementOperation(url) {
|
|
|
|
|
|
return url === '/api/pockets' || /^\/api\/pockets\/[^/]+\/update$/.test(url);
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
function pocketManagerPanel() {
|
|
|
|
|
|
if (state.user.role !== 'owner') return '';
|
|
|
|
|
|
if (pocketManagerUser !== pocketManagerIdentity()) {
|
|
|
|
|
|
pocketManagerRows = null;
|
|
|
|
|
|
pocketManagerUser = pocketManagerIdentity();
|
|
|
|
|
|
pocketManagerStale = false;
|
|
|
|
|
|
}
|
2026-12-04 01:30:49 +08:00
|
|
|
|
return `<section class="panel pocket-manager" id="pocket-manager" ${pocketManagerOpen ? '' : 'hidden'}><div class="panel-title"><h2>货盘管理</h2><div class="actions">${button('+ 新增货盘', 'pocket-manager-add', 'primary')}${button('重新读取', 'pocket-manager-reload', 'quiet')}${button('收起', 'pocket-manager-toggle', 'quiet')}</div></div><p class="small muted">新增货盘按自有库存管理。停用后保留库存与历史记录,可重新启用。</p><div id="pocket-manager-content" aria-live="polite">${pocketManagerRows ? pocketManagerContent() : '正在读取货盘…'}</div><div id="pocket-manager-error" aria-live="polite"></div></section>`;
|
2026-11-08 03:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
function pocketManagerContent() {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
return `<label class="pocket-manager-search">搜索货盘<input type="search" id="pocket-manager-search" placeholder="输入货盘名称" value="${e(pocketManagerSearch)}"></label><div id="pocket-manager-list">${pocketManagerListHTML()}</div>`;
|
|
|
|
|
|
}
|
|
|
|
|
|
function pocketManagerListHTML() {
|
|
|
|
|
|
const rows = (pocketManagerRows || []).filter(row =>
|
|
|
|
|
|
row.name.toLocaleLowerCase().includes(pocketManagerSearch.trim().toLocaleLowerCase()),
|
|
|
|
|
|
);
|
|
|
|
|
|
if (!rows.length) return '<p class="empty">没有匹配的货盘。</p>';
|
|
|
|
|
|
return `<div class="table-wrap"><table class="pocket-manager-table"><thead><tr><th>货盘名称</th><th>计数方式</th><th>状态</th><th>操作</th></tr></thead><tbody>${rows.map(row => `<tr><td><strong>${e(row.name)}</strong></td><td>${row.countUnit === 'pair' ? '克重 + 对数' : '仅克重'}</td><td><span class="badge${row.active ? '' : ' warn'}">${row.active ? '已启用' : '已停用'}</span></td><td><div class="actions">${button('编辑', 'pocket-manager-edit', 'quiet', `data-pocket-key="${e(row.key)}"`)}${button(row.active ? '停用' : '启用', 'pocket-manager-status', row.active ? 'quiet' : '', `data-pocket-key="${e(row.key)}" data-active="${row.active ? 'false' : 'true'}"`)}</div></td></tr>`).join('')}</tbody></table></div>`;
|
|
|
|
|
|
}
|
|
|
|
|
|
function pocketEditorDirty() {
|
|
|
|
|
|
return !!pocketEditor?.dirty;
|
|
|
|
|
|
}
|
|
|
|
|
|
function closePocketEditor(force = false) {
|
|
|
|
|
|
if (!force && (busy || pending())) return false;
|
|
|
|
|
|
if (!force && pocketEditorDirty() && !window.confirm('货盘修改尚未保存,放弃修改?')) return false;
|
|
|
|
|
|
pocketEditor = null;
|
|
|
|
|
|
$('#pocket-editor-dialog')?.close();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
function openPocketEditor(key = '') {
|
|
|
|
|
|
requirePocketManagement();
|
|
|
|
|
|
if (!pocketManagerRows) throw new Error('请先读取货盘资料。');
|
|
|
|
|
|
if (!closePocketEditor()) return;
|
|
|
|
|
|
const row = key ? pocketManagerRows.find(item => item.key === key) : null;
|
|
|
|
|
|
if (key && !row) throw new Error('请重新读取货盘后再修改。');
|
|
|
|
|
|
pocketEditor = { user: pocketManagerIdentity(), dirty: false };
|
|
|
|
|
|
let dialog = $('#pocket-editor-dialog');
|
|
|
|
|
|
if (!dialog) {
|
|
|
|
|
|
dialog = document.createElement('dialog');
|
|
|
|
|
|
dialog.id = 'pocket-editor-dialog';
|
|
|
|
|
|
dialog.setAttribute('aria-labelledby', 'pocket-editor-title');
|
|
|
|
|
|
document.body.append(dialog);
|
|
|
|
|
|
dialog.addEventListener('cancel', event => {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
closePocketEditor();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
dialog.innerHTML = `<button type="button" class="dialog-close" data-action="pocket-manager-close" aria-label="关闭货盘编辑">×</button><h2 id="pocket-editor-title">${row ? '编辑货盘' : '新增货盘'}</h2><form ${row ? `class="pocket-rename-form" data-pocket-key="${e(row.key)}" data-revision="${e(row.revision)}"` : 'id="pocket-create-form"'}><label>货盘名称<input name="name" value="${e(row?.name || '')}" required maxlength="40" placeholder="例如:展柜A、备用货盘"></label>${pocketCountSettingsHTML(row)}<div id="pocket-editor-error" aria-live="polite"></div><div class="form-actions">${button('取消', 'pocket-manager-close', 'quiet')}<button type="submit" class="primary">${row ? '保存设置' : '新增货盘'}</button></div></form>`;
|
|
|
|
|
|
dialog.showModal();
|
|
|
|
|
|
dialog.querySelector('[name="name"]').focus();
|
|
|
|
|
|
applyPocketManagerRestrictions();
|
2026-11-08 03:30:58 +08:00
|
|
|
|
}
|
2026-11-08 15:47:07 +08:00
|
|
|
|
function pocketCountSettingsHTML(row) {
|
|
|
|
|
|
if (row?.countUnit === 'pair')
|
|
|
|
|
|
return '<div class="pocket-count-settings"><span class="badge">同时记录对数 · 已启用</span><p class="small muted">一对按1对记录。以后出入库同时记录克重和对数;已启用的计数保留。</p></div>';
|
|
|
|
|
|
return (
|
|
|
|
|
|
'<div class="pocket-count-settings"><label class="check"><input type="checkbox" name="enableCounts">同时记录对数</label><div data-pocket-count-baseline hidden>' +
|
|
|
|
|
|
field(
|
|
|
|
|
|
'实际当前库存数量(对)',
|
|
|
|
|
|
'initialCount',
|
|
|
|
|
|
'',
|
|
|
|
|
|
'number',
|
|
|
|
|
|
'min="0" max="1000000000" step="1" inputmode="numeric" disabled placeholder="先清点实物,一对填1"',
|
2026-12-04 08:58:53 -08:00
|
|
|
|
) +
|
2026-11-08 15:47:07 +08:00
|
|
|
|
'<label class="check"><input name="countVerified" type="checkbox" disabled>已清点当前实际对数,以此作为起始数量</label><p class="small muted">只增加对数基准,已有克重、历史订单与利润保留。启用后出入库须记录对数。</p></div></div>'
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
function syncPocketCountSettings(form) {
|
|
|
|
|
|
const enable = form?.querySelector('[name="enableCounts"]'),
|
|
|
|
|
|
baseline = form?.querySelector('[data-pocket-count-baseline]');
|
|
|
|
|
|
if (!enable || !baseline) return;
|
|
|
|
|
|
baseline.hidden = !enable.checked;
|
|
|
|
|
|
baseline.querySelectorAll('input').forEach(input => {
|
|
|
|
|
|
input.disabled = !enable.checked || busy || !!pending() || pocketManagerStale;
|
|
|
|
|
|
input.required = enable.checked;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
function validatePocketManagerResponse(result) {
|
|
|
|
|
|
if (
|
|
|
|
|
|
!result ||
|
|
|
|
|
|
!Array.isArray(result.catalog) ||
|
|
|
|
|
|
!Array.isArray(result.pockets) ||
|
|
|
|
|
|
!result.catalog.every(
|
|
|
|
|
|
row =>
|
|
|
|
|
|
row &&
|
|
|
|
|
|
typeof row.key === 'string' &&
|
|
|
|
|
|
row.key &&
|
|
|
|
|
|
typeof row.name === 'string' &&
|
|
|
|
|
|
row.name &&
|
|
|
|
|
|
typeof row.active === 'boolean' &&
|
|
|
|
|
|
row.revision != null,
|
|
|
|
|
|
) ||
|
|
|
|
|
|
new Set(result.catalog.map(row => row.key)).size !== result.catalog.length ||
|
|
|
|
|
|
result.pockets.some(key => !result.catalog.some(row => row.key === key && row.active))
|
2026-12-04 08:58:53 -08:00
|
|
|
|
)
|
2026-11-08 03:30:58 +08:00
|
|
|
|
throw new Error('货盘资料未完整返回,请重新读取。');
|
|
|
|
|
|
}
|
|
|
|
|
|
async function loadPocketManager() {
|
|
|
|
|
|
if (state.user.role !== 'owner' || tab !== 'stock' || !pocketManagerOpen) return;
|
|
|
|
|
|
const target = $('#pocket-manager-content'),
|
|
|
|
|
|
user = pocketManagerIdentity(),
|
|
|
|
|
|
request = ++pocketManagerRequest;
|
|
|
|
|
|
if (!target) return;
|
|
|
|
|
|
target.setAttribute('aria-busy', 'true');
|
|
|
|
|
|
target.innerHTML = '<p class="muted">正在读取货盘…</p>';
|
|
|
|
|
|
const current = () =>
|
|
|
|
|
|
request === pocketManagerRequest &&
|
|
|
|
|
|
user === pocketManagerIdentity() &&
|
|
|
|
|
|
tab === 'stock' &&
|
|
|
|
|
|
pocketManagerOpen &&
|
|
|
|
|
|
target === $('#pocket-manager-content');
|
|
|
|
|
|
try {
|
2026-11-14 01:16:35 +08:00
|
|
|
|
const result = await api('/api/pockets');
|
|
|
|
|
|
if (!current()) return;
|
|
|
|
|
|
validatePocketManagerResponse(result);
|
|
|
|
|
|
if (result.canManage !== true) throw new Error('货盘管理由店主账号操作。');
|
2026-11-08 03:30:58 +08:00
|
|
|
|
pocketManagerRows = result.catalog;
|
|
|
|
|
|
pocketManagerUser = user;
|
|
|
|
|
|
pocketManagerStale = false;
|
|
|
|
|
|
target.innerHTML = pocketManagerContent();
|
|
|
|
|
|
target.setAttribute('aria-busy', 'false');
|
|
|
|
|
|
$('#pocket-manager-error').innerHTML = '';
|
|
|
|
|
|
applyPocketManagerRestrictions();
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
if (!current()) return;
|
|
|
|
|
|
pocketManagerRows = null;
|
|
|
|
|
|
target.setAttribute('aria-busy', 'false');
|
|
|
|
|
|
target.innerHTML = `<div class="error">${e(err.message)} ${button('重新读取', 'pocket-manager-reload')}</div>`;
|
|
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
function applyPocketManagerRestrictions() {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
for (const panel of [$('#pocket-manager'), $('#pocket-editor-dialog')]) {
|
|
|
|
|
|
if (!panel) continue;
|
|
|
|
|
|
panel.querySelectorAll('input,select,button').forEach(control => {
|
|
|
|
|
|
const action = control.dataset?.action;
|
|
|
|
|
|
control.disabled =
|
|
|
|
|
|
state.user.role !== 'owner' ||
|
|
|
|
|
|
busy ||
|
|
|
|
|
|
(action === 'retry' ? false : !!pending()) ||
|
|
|
|
|
|
(pocketManagerStale &&
|
|
|
|
|
|
!['pocket-manager-reload', 'pocket-manager-toggle', 'pocket-manager-close', 'retry'].includes(action));
|
|
|
|
|
|
});
|
|
|
|
|
|
panel.querySelectorAll('form').forEach(syncPocketCountSettings);
|
|
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
function pocketManagerName(value) {
|
|
|
|
|
|
const name = String(value ?? '')
|
|
|
|
|
|
.trim()
|
|
|
|
|
|
.normalize('NFKC');
|
|
|
|
|
|
if (!name || name.length > 40 || /[\u0000-\u001f\u007f]/.test(name))
|
|
|
|
|
|
throw new Error('货盘名称请填写1~40字,不含控制字符。');
|
|
|
|
|
|
return name;
|
2026-11-14 01:16:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
function requirePocketManagement() {
|
|
|
|
|
|
if (state.user.role !== 'owner') throw new Error('货盘管理由店主账号操作。');
|
|
|
|
|
|
if (busy || pending()) throw new Error('请先恢复未确认的操作,再管理货盘。');
|
|
|
|
|
|
if (pocketManagerStale) throw new Error('货盘资料已有变化,请重新读取后再修改。');
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
function pocketManagerError(err) {
|
|
|
|
|
|
if (err.code === 'ACCOUNT_CHANGED') return;
|
|
|
|
|
|
if ([403, 404, 409].includes(err.status)) pocketManagerStale = true;
|
2026-12-04 01:30:49 +08:00
|
|
|
|
const target = $('#pocket-editor-dialog')?.open ? $('#pocket-editor-error') : $('#pocket-manager-error');
|
|
|
|
|
|
if (target)
|
|
|
|
|
|
target.innerHTML = `<div class="error">${e(err.message.replace('不要重新开单', '不要重复新增或修改货盘'))}${pending() ? ' ' + button('恢复原操作', 'retry', 'danger') : pocketManagerStale ? ' ' + button('重新读取货盘', 'pocket-manager-reload') : ''}</div>`;
|
2026-11-08 03:30:58 +08:00
|
|
|
|
applyPocketManagerRestrictions();
|
|
|
|
|
|
toast(err.message.replace('不要重新开单', '不要重复新增或修改货盘'), true);
|
|
|
|
|
|
}
|
|
|
|
|
|
async function submitPocketManagement(form) {
|
|
|
|
|
|
try {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
requirePocketManagement();
|
|
|
|
|
|
if (pocketEditor && pocketEditor.user !== pocketManagerIdentity())
|
|
|
|
|
|
throw new Error('账号已变化,请重新打开货盘编辑。');
|
|
|
|
|
|
const create = form.id === 'pocket-create-form',
|
|
|
|
|
|
row = create ? null : pocketManagerRows?.find(row => row.key === form.dataset.pocketKey);
|
|
|
|
|
|
if (!create && !row) throw new Error('请重新读取货盘后再修改。');
|
|
|
|
|
|
const name = pocketManagerName(form.querySelector('[name="name"]').value),
|
|
|
|
|
|
input = {
|
|
|
|
|
|
name,
|
|
|
|
|
|
...(row ? { revision: form.dataset.revision ? Number(form.dataset.revision) : row.revision } : {}),
|
|
|
|
|
|
},
|
|
|
|
|
|
url = create ? '/api/pockets' : '/api/pockets/' + encodeURIComponent(row.key) + '/update';
|
2026-11-08 15:47:07 +08:00
|
|
|
|
if (row?.countUnit !== 'pair' && form.querySelector('[name="enableCounts"]')?.checked) {
|
|
|
|
|
|
input.countUnit = 'pair';
|
|
|
|
|
|
input.initialCount = stockCountValue(form.querySelector('[name="initialCount"]')?.value, {
|
|
|
|
|
|
zero: true,
|
|
|
|
|
|
title: '实际当前库存数量(对)',
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!form.querySelector('[name="countVerified"]')?.checked) throw new Error('请先清点当前实际对数,并勾选确认。');
|
|
|
|
|
|
input.countVerified = true;
|
|
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
$('#pocket-manager-error').innerHTML = '';
|
|
|
|
|
|
const user = pocketManagerIdentity(),
|
|
|
|
|
|
result = await mutate(url, input);
|
|
|
|
|
|
if (user !== pocketManagerIdentity()) return;
|
|
|
|
|
|
await finishPocketManagementSave(url, input, result);
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
pocketManagerError(err);
|
|
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
async function finishPocketManagementSave(url, input, result) {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
closePocketEditor(true);
|
2026-11-08 15:47:07 +08:00
|
|
|
|
const message =
|
|
|
|
|
|
input.countUnit === 'pair'
|
|
|
|
|
|
? '货盘已启用对数,实际清点数量已保存'
|
|
|
|
|
|
: url === '/api/pockets'
|
|
|
|
|
|
? '货盘已新增'
|
|
|
|
|
|
: Object.hasOwn(input, 'active')
|
|
|
|
|
|
? input.active
|
|
|
|
|
|
? '货盘已启用'
|
|
|
|
|
|
: '货盘已停用,已有库存和历史记录保留'
|
|
|
|
|
|
: '货盘名称已保存';
|
2026-11-08 03:30:58 +08:00
|
|
|
|
if (Array.isArray(result.catalog) && Array.isArray(result.pockets)) {
|
|
|
|
|
|
state.pocketCatalog = result.catalog;
|
|
|
|
|
|
state.pockets = result.pockets;
|
|
|
|
|
|
pocketManagerRows = result.catalog;
|
|
|
|
|
|
}
|
|
|
|
|
|
pocketManagerStale = false;
|
|
|
|
|
|
const target = $('#pocket-manager-content');
|
|
|
|
|
|
if (target) target.innerHTML = `<p>${e(message)},正在读取最新库存…</p>`;
|
|
|
|
|
|
try {
|
|
|
|
|
|
await refresh(false);
|
|
|
|
|
|
if (tab === 'stock' && state.user.role === 'owner') {
|
|
|
|
|
|
await renderStock();
|
|
|
|
|
|
if (pocketManagerOpen) await loadPocketManager();
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
toast(message);
|
2026-12-04 08:58:53 -08:00
|
|
|
|
} catch {
|
2026-11-08 03:30:58 +08:00
|
|
|
|
if ($('#pocket-manager-content'))
|
|
|
|
|
|
$('#pocket-manager-content').innerHTML =
|
|
|
|
|
|
`<p>${e(message)}。最新库存暂未读到,请刷新核对。</p>${button('重新读取库存', 'inventory-retry')}`;
|
|
|
|
|
|
toast(message + '。最新页面暂未读到,请刷新核对,不要重复提交。', true);
|
|
|
|
|
|
}
|
2026-12-04 01:30:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
document.addEventListener('change', event => {
|
|
|
|
|
|
if (event.target.name === 'enableCounts') syncPocketCountSettings(event.target.closest('form'));
|
2026-12-04 08:58:53 -08:00
|
|
|
|
});
|
2026-12-04 01:30:49 +08:00
|
|
|
|
async function pocketManagerAction(action, buttonNode) {
|
2026-11-14 01:16:35 +08:00
|
|
|
|
if (state.user.role !== 'owner') throw new Error('货盘管理由店主账号操作。');
|
2026-12-04 01:30:49 +08:00
|
|
|
|
if (action === 'pocket-manager-add') return openPocketEditor();
|
|
|
|
|
|
if (action === 'pocket-manager-edit') return openPocketEditor(buttonNode.dataset.pocketKey);
|
|
|
|
|
|
if (action === 'pocket-manager-close') return closePocketEditor();
|
2026-11-08 03:30:58 +08:00
|
|
|
|
if (action === 'pocket-manager-toggle') {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
if (!closePocketEditor()) return;
|
2026-11-08 03:30:58 +08:00
|
|
|
|
pocketManagerOpen = !pocketManagerOpen;
|
|
|
|
|
|
const panel = $('#pocket-manager');
|
|
|
|
|
|
if (panel) panel.hidden = !pocketManagerOpen;
|
2026-12-04 08:58:53 -08:00
|
|
|
|
document
|
2026-12-04 01:30:49 +08:00
|
|
|
|
.querySelectorAll('[data-action="pocket-manager-toggle"][aria-controls]')
|
2026-11-08 03:30:58 +08:00
|
|
|
|
.forEach(button => button.setAttribute('aria-expanded', String(pocketManagerOpen)));
|
|
|
|
|
|
if (!pocketManagerOpen) {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
++pocketManagerRequest;
|
2026-12-04 08:58:53 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-12-04 01:30:49 +08:00
|
|
|
|
await loadPocketManager();
|
2026-11-08 03:30:58 +08:00
|
|
|
|
panel?.scrollIntoView?.({ behavior: 'smooth', block: 'start' });
|
2026-12-04 08:58:53 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-12-04 01:30:49 +08:00
|
|
|
|
if (action === 'pocket-manager-reload') {
|
|
|
|
|
|
if (!closePocketEditor()) return;
|
2026-11-08 03:30:58 +08:00
|
|
|
|
return await loadPocketManager();
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
if (action === 'pocket-manager-status') {
|
|
|
|
|
|
try {
|
|
|
|
|
|
requirePocketManagement();
|
|
|
|
|
|
const row = pocketManagerRows?.find(row => row.key === buttonNode.dataset.pocketKey);
|
|
|
|
|
|
if (!row) throw new Error('请重新读取货盘后再修改。');
|
|
|
|
|
|
const active = buttonNode.dataset.active === 'true';
|
|
|
|
|
|
if (active === row.active) return;
|
|
|
|
|
|
const input = { revision: row.revision, active },
|
|
|
|
|
|
url = '/api/pockets/' + encodeURIComponent(row.key) + '/update',
|
|
|
|
|
|
user = pocketManagerIdentity(),
|
|
|
|
|
|
result = await mutate(url, input);
|
|
|
|
|
|
if (user !== pocketManagerIdentity()) return;
|
|
|
|
|
|
await finishPocketManagementSave(url, input, result);
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
pocketManagerError(err);
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-11-08 03:30:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-12-04 01:30:49 +08:00
|
|
|
|
|
|
|
|
|
|
document.addEventListener('input', event => {
|
|
|
|
|
|
if (event.target.id === 'pocket-manager-search') {
|
|
|
|
|
|
pocketManagerSearch = event.target.value;
|
|
|
|
|
|
$('#pocket-manager-list').innerHTML = pocketManagerListHTML();
|
|
|
|
|
|
applyPocketManagerRestrictions();
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-12-04 01:30:49 +08:00
|
|
|
|
for (const type of ['input', 'change'])
|
|
|
|
|
|
document.addEventListener(type, event => {
|
|
|
|
|
|
if (pocketEditor && event.target.closest?.('#pocket-editor-dialog')) pocketEditor.dirty = true;
|
2026-12-04 08:58:53 -08:00
|
|
|
|
});
|
2026-12-04 01:30:49 +08:00
|
|
|
|
document.addEventListener(
|
2026-12-04 08:58:53 -08:00
|
|
|
|
'click',
|
|
|
|
|
|
event => {
|
2026-12-04 01:30:49 +08:00
|
|
|
|
const node = event.target.closest?.('button');
|
|
|
|
|
|
if (!pocketEditor || !node) return;
|
2026-12-04 08:58:53 -08:00
|
|
|
|
if (
|
2026-12-04 01:30:49 +08:00
|
|
|
|
node.dataset.tab ||
|
|
|
|
|
|
['logout', 'refresh', 'sync'].includes(node.dataset.action) ||
|
|
|
|
|
|
node.dataset.action?.startsWith('demo-')
|
2026-12-04 08:58:53 -08:00
|
|
|
|
)
|
2026-12-04 01:30:49 +08:00
|
|
|
|
if (!closePocketEditor()) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
|
}
|
2026-12-04 08:58:53 -08:00
|
|
|
|
},
|
|
|
|
|
|
true,
|
|
|
|
|
|
);
|
2026-12-04 01:30:49 +08:00
|
|
|
|
window.addEventListener?.('beforeunload', event => {
|
|
|
|
|
|
if (pocketEditorDirty()) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.returnValue = '';
|
2026-12-04 08:58:53 -08:00
|
|
|
|
}
|
2026-12-04 01:30:49 +08:00
|
|
|
|
});
|