rozbicie na moduły, poprawki i komendy cli
This commit is contained in:
92
zbiorka_app/static/js/ustawienia.js
Normal file
92
zbiorka_app/static/js/ustawienia.js
Normal file
@@ -0,0 +1,92 @@
|
||||
// static/js/ustawienia.js
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// Formatowanie IBAN (PL)
|
||||
const iban = document.getElementById('numer_konta');
|
||||
if (iban) {
|
||||
iban.addEventListener('input', () => {
|
||||
const digits = iban.value.replace(/\D/g, '').slice(0, 26);
|
||||
const chunked = digits.replace(/(.{4})/g, '$1 ').trim();
|
||||
iban.value = chunked;
|
||||
});
|
||||
}
|
||||
|
||||
// Telefon BLIK 3-3-3
|
||||
const tel = document.getElementById('numer_telefonu_blik');
|
||||
if (tel) {
|
||||
tel.addEventListener('input', () => {
|
||||
const digits = tel.value.replace(/\D/g, '').slice(0, 9);
|
||||
const parts = [];
|
||||
if (digits.length > 0) parts.push(digits.substring(0, 3));
|
||||
if (digits.length > 3) parts.push(digits.substring(3, 6));
|
||||
if (digits.length > 6) parts.push(digits.substring(6, 9));
|
||||
tel.value = parts.join(' ');
|
||||
});
|
||||
}
|
||||
|
||||
// Biała lista IP/hostów
|
||||
const ta = document.getElementById('dozwolone_hosty_logowania');
|
||||
const count = document.getElementById('hostsCount');
|
||||
const addBtn = document.getElementById('btn-add-host');
|
||||
const addMyBtn = document.getElementById('btn-add-my-ip');
|
||||
const input = document.getElementById('host_input');
|
||||
const dedupeBtn = document.getElementById('btn-dedupe');
|
||||
|
||||
const parseList = (text) =>
|
||||
text
|
||||
.split(/[\r\n,;]+/) // \r?\n, przecinek, średnik
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const formatList = (arr) => arr.join('\n');
|
||||
|
||||
const dedupe = (arr) => {
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
for (const v of arr) {
|
||||
const k = v.toLowerCase();
|
||||
if (!seen.has(k)) { seen.add(k); out.push(v); }
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
const updateCount = () => {
|
||||
if (!ta || !count) return;
|
||||
count.textContent = String(parseList(ta.value).length);
|
||||
};
|
||||
|
||||
const addEntry = (val) => {
|
||||
if (!ta || !val) return;
|
||||
const list = dedupe([...parseList(ta.value), val]);
|
||||
ta.value = formatList(list);
|
||||
updateCount();
|
||||
};
|
||||
|
||||
if (ta) {
|
||||
ta.addEventListener('input', updateCount);
|
||||
updateCount(); // inicjalne przeliczenie
|
||||
}
|
||||
|
||||
if (addBtn && input) {
|
||||
addBtn.addEventListener('click', () => {
|
||||
const val = (input.value || '').trim();
|
||||
if (!val) return;
|
||||
addEntry(val);
|
||||
input.value = '';
|
||||
input.focus();
|
||||
});
|
||||
}
|
||||
|
||||
if (addMyBtn) {
|
||||
addMyBtn.addEventListener('click', () => {
|
||||
const ip = addMyBtn.dataset.myIp || '';
|
||||
if (ip) addEntry(ip);
|
||||
});
|
||||
}
|
||||
|
||||
if (dedupeBtn && ta) {
|
||||
dedupeBtn.addEventListener('click', () => {
|
||||
ta.value = formatList(dedupe(parseList(ta.value)));
|
||||
updateCount();
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user