fix: askPassword closure — pw declared inside function (was global ref)
This commit is contained in:
+9
-4
@@ -2474,8 +2474,10 @@ window.toggleEditConsulta = async function() {
|
|||||||
openEditModal(full);
|
openEditModal(full);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Pede senha admin — retorna Promise<boolean>
|
||||||
function askPassword() {
|
function askPassword() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
const pw = config.admin_password;
|
||||||
const overlay = document.createElement('div');
|
const overlay = document.createElement('div');
|
||||||
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
|
overlay.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:999999;display:flex;align-items:center;justify-content:center;';
|
||||||
overlay.id = 'pw-modal';
|
overlay.id = 'pw-modal';
|
||||||
@@ -2485,21 +2487,24 @@ function askPassword() {
|
|||||||
<input type="password" id="pw-input" placeholder="Digite a senha..." style="width:100%;padding:10px;font-size:14px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;margin-bottom:12px" />
|
<input type="password" id="pw-input" placeholder="Digite a senha..." style="width:100%;padding:10px;font-size:14px;border:1px solid #ccc;border-radius:6px;box-sizing:border-box;margin-bottom:12px" />
|
||||||
<div id="pw-error" style="color:#c0272d;font-size:12px;margin-bottom:8px;display:none">Senha incorreta</div>
|
<div id="pw-error" style="color:#c0272d;font-size:12px;margin-bottom:8px;display:none">Senha incorreta</div>
|
||||||
<div style="display:flex;gap:8px;justify-content:center">
|
<div style="display:flex;gap:8px;justify-content:center">
|
||||||
<button onclick="document.getElementById('pw-modal').remove();window._pwResult=false;window._pwResolve&&window._pwResolve(false)" style="padding:8px 16px;background:#888;color:#fff;border:none;border-radius:6px;cursor:pointer">Cancelar</button>
|
<button id="pw-cancel-btn" style="padding:8px 16px;background:#888;color:#fff;border:none;border-radius:6px;cursor:pointer">Cancelar</button>
|
||||||
<button id="pw-ok-btn" style="padding:8px 16px;background:#e65100;color:#fff;border:none;border-radius:6px;cursor:pointer">OK</button>
|
<button id="pw-ok-btn" style="padding:8px 16px;background:#e65100;color:#fff;border:none;border-radius:6px;cursor:pointer">OK</button>
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
document.body.appendChild(overlay);
|
document.body.appendChild(overlay);
|
||||||
const inp = document.getElementById('pw-input');
|
const inp = document.getElementById('pw-input');
|
||||||
inp.focus();
|
inp.focus();
|
||||||
window._pwResolve = resolve;
|
|
||||||
|
document.getElementById('pw-cancel-btn').addEventListener('click', () => {
|
||||||
|
document.getElementById('pw-modal').remove();
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
inp.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('pw-ok-btn').click(); });
|
inp.addEventListener('keydown', e => { if (e.key === 'Enter') document.getElementById('pw-ok-btn').click(); });
|
||||||
document.getElementById('pw-ok-btn').addEventListener('click', () => {
|
document.getElementById('pw-ok-btn').addEventListener('click', () => {
|
||||||
const val = document.getElementById('pw-input').value;
|
const val = document.getElementById('pw-input').value;
|
||||||
if (val === pw) {
|
if (val === pw) {
|
||||||
document.getElementById('pw-modal').remove();
|
document.getElementById('pw-modal').remove();
|
||||||
window._pwResult = true;
|
resolve(true);
|
||||||
window._pwResolve && window._pwResolve(true);
|
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('pw-error').style.display = 'block';
|
document.getElementById('pw-error').style.display = 'block';
|
||||||
inp.value = '';
|
inp.value = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user