przebudowa systemu
This commit is contained in:
92
static/js/ustawienia.js
Normal file
92
static/js/ustawienia.js
Normal file
@@ -0,0 +1,92 @@
|
||||
(function () {
|
||||
// IBAN: tylko cyfry, auto-grupowanie co 4 (po prefiksie PL)
|
||||
const iban = document.getElementById('numer_konta');
|
||||
if (iban) {
|
||||
iban.addEventListener('input', () => {
|
||||
const digits = iban.value.replace(/\\D/g, '').slice(0, 26); // 26 cyfr po "PL"
|
||||
const chunked = digits.replace(/(.{4})/g, '$1 ').trim();
|
||||
iban.value = chunked;
|
||||
});
|
||||
}
|
||||
|
||||
// Telefon BLIK: tylko cyfry, format 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 — helpery
|
||||
const ta = document.getElementById('allowed_login_hosts');
|
||||
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');
|
||||
|
||||
function parseList(text) {
|
||||
// akceptuj przecinki, średniki i nowe linie; trimuj; usuń puste
|
||||
return text
|
||||
.split(/[\\n,;]+/)
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
function formatList(arr) {
|
||||
return arr.join('\\n');
|
||||
}
|
||||
function 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;
|
||||
}
|
||||
function updateCount() {
|
||||
if (!ta || !count) return;
|
||||
count.textContent = parseList(ta.value).length.toString();
|
||||
}
|
||||
function addEntry(val) {
|
||||
if (!ta || !val) return;
|
||||
const list = dedupe([...parseList(ta.value), val]);
|
||||
ta.value = formatList(list);
|
||||
updateCount();
|
||||
}
|
||||
|
||||
if (ta) {
|
||||
ta.addEventListener('input', updateCount);
|
||||
// inicjalny przelicznik
|
||||
updateCount();
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
const dedupeBtn = document.getElementById('btn-dedupe');
|
||||
if (dedupeBtn && ta) {
|
||||
dedupeBtn.addEventListener('click', () => {
|
||||
ta.value = formatList(dedupe(parseList(ta.value)));
|
||||
updateCount();
|
||||
});
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user