#include msgbox.jsx #include comments/api.js const MszCommentsOptionsLockAction = function(catInfo, reinit) { const element = ; const setLocked = state => { $removeChildren(element); if(state) { element.appendChild(); element.appendChild(Unlock); } else { element.appendChild(); element.appendChild(Lock); } }; setLocked(catInfo.locked); element.onclick = async () => { element.disabled = true; try { if(!catInfo.locked && !await MszShowConfirmBox(`Are you sure you want to lock comments category ${catInfo.name}?`, 'Locked a comment section')) return; const result = await MszCommentsApi.updateCategory(catInfo.name, { lock: catInfo.locked ? '0' : '1' }); if('locked' in result) { if(result.locked) catInfo.locked = result.locked; else delete catInfo.locked; } setLocked(catInfo.locked); reinit(); } catch(ex) { console.error(ex); } finally { element.disabled = false; } }; return { get element() { return element; }, }; }; const MszCommentsOptionsRetryAction = function(section) { const element = ; element.onclick = async () => { element.disabled = true; try { await section.reload(); } catch(ex) { console.error(ex); } finally { element.disabled = false; } }; return { get element() { return element; }, }; }; const MszCommentsOptions = function() { const actions =
; const element = ; const hideIfNoChildren = () => { element.classList.toggle('hidden', actions.childElementCount < 1); }; hideIfNoChildren(); return { get element() { return element; }, reset() { $removeChildren(actions); hideIfNoChildren(); }, appendAction(action) { actions.appendChild(action.element); hideIfNoChildren(); }, }; };