Siirrä allekirjoitukset Asiakaspalvelu-välilehdelle + postilaatikoiden piilotus
- Uusi "Omat asetukset" -näkymä Asiakaspalvelu-tabiin (allekirjoitukset + mailbox-näkyvyys) - Uusi user_hidden_mailboxes-taulu piilotettavien postilaatikoiden tallennukseen - API: profile_update + check_auth tukevat hidden_mailboxes-listaa - Tikettilista suodattaa piilotettujen mailboxien tiketit automaattisesti - Reply-formin mailbox-dropdown piilottaa piilotetut postilaatikot - Allekirjoitukset poistettu Oma profiili -modalista (siirretty Asiakaspalvelu-asetuksiin) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
133
script.js
133
script.js
@@ -8,6 +8,7 @@ let currentCompany = null; // {id, nimi}
|
||||
let availableCompanies = []; // [{id, nimi}, ...]
|
||||
let currentTicketCompanyId = ''; // Avatun tiketin yritys (cross-company tuki)
|
||||
let currentUserSignatures = {}; // {mailbox_id: "allekirjoitus teksti"}
|
||||
let currentHiddenMailboxes = []; // ['mailbox_id1', ...] — piilotetut postilaatikot
|
||||
|
||||
// Elements
|
||||
const loginScreen = document.getElementById('login-screen');
|
||||
@@ -142,6 +143,7 @@ async function checkAuth() {
|
||||
availableCompanies = data.companies || [];
|
||||
currentCompany = availableCompanies.find(c => c.id === data.company_id) || availableCompanies[0] || null;
|
||||
currentUserSignatures = data.signatures || {};
|
||||
currentHiddenMailboxes = data.hidden_mailboxes || [];
|
||||
if (data.branding) applyBranding(data.branding);
|
||||
applyModules(data.enabled_modules || []);
|
||||
showDashboard();
|
||||
@@ -164,6 +166,7 @@ loginForm.addEventListener('submit', async (e) => {
|
||||
availableCompanies = data.companies || [];
|
||||
currentCompany = availableCompanies.find(c => c.id === data.company_id) || availableCompanies[0] || null;
|
||||
currentUserSignatures = data.signatures || {};
|
||||
currentHiddenMailboxes = data.hidden_mailboxes || [];
|
||||
showDashboard();
|
||||
} catch (err) {
|
||||
loginError.textContent = err.message;
|
||||
@@ -240,6 +243,8 @@ async function switchCompany(companyId) {
|
||||
if (auth.branding) applyBranding(auth.branding);
|
||||
applyModules(auth.enabled_modules || []);
|
||||
currentUser.company_role = auth.company_role || '';
|
||||
currentUserSignatures = auth.signatures || {};
|
||||
currentHiddenMailboxes = auth.hidden_mailboxes || [];
|
||||
} catch (e2) {}
|
||||
// Päivitä admin-näkyvyys yritysroolin mukaan
|
||||
updateAdminVisibility();
|
||||
@@ -1214,6 +1219,7 @@ document.getElementById('user-form').addEventListener('submit', async (e) => {
|
||||
if (auth.authenticated) {
|
||||
currentUser = { username: auth.username, nimi: auth.nimi, role: auth.role, company_role: auth.company_role || '', id: auth.user_id };
|
||||
currentUserSignatures = auth.signatures || {};
|
||||
currentHiddenMailboxes = auth.hidden_mailboxes || [];
|
||||
}
|
||||
} catch (e) { alert(e.message); }
|
||||
});
|
||||
@@ -1234,43 +1240,14 @@ async function openProfileModal() {
|
||||
document.getElementById('profile-nimi').value = auth.nimi || '';
|
||||
document.getElementById('profile-email').value = auth.email || '';
|
||||
document.getElementById('profile-password').value = '';
|
||||
// Allekirjoitukset
|
||||
const sigSection = document.getElementById('profile-signatures-section');
|
||||
const sigList = document.getElementById('profile-signatures-list');
|
||||
const userSigs = auth.signatures || {};
|
||||
try {
|
||||
const mailboxes = await apiCall('all_mailboxes');
|
||||
if (mailboxes.length === 0) {
|
||||
sigSection.style.display = 'none';
|
||||
} else {
|
||||
sigSection.style.display = '';
|
||||
sigList.innerHTML = mailboxes.map(mb =>
|
||||
`<div style="margin-bottom:0.75rem;">
|
||||
<label style="font-weight:600;font-size:0.85rem;color:#333;">${esc(mb.company_nimi)} — ${esc(mb.nimi)}</label>
|
||||
<textarea class="profile-sig-textarea" data-mailbox-id="${mb.id}" rows="3"
|
||||
style="width:100%;margin-top:0.25rem;padding:8px;border:1px solid #ddd;border-radius:6px;font-size:0.85rem;font-family:inherit;resize:vertical;"
|
||||
placeholder="esim.\nNimi\nYritys Oy\ninfo@yritys.fi">${esc(userSigs[mb.id] || '')}</textarea>
|
||||
</div>`
|
||||
).join('');
|
||||
}
|
||||
} catch {
|
||||
sigSection.style.display = 'none';
|
||||
}
|
||||
profileModal.style.display = 'flex';
|
||||
}
|
||||
|
||||
document.getElementById('profile-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const signatures = {};
|
||||
document.querySelectorAll('.profile-sig-textarea').forEach(ta => {
|
||||
const mbId = ta.dataset.mailboxId;
|
||||
const val = ta.value.trim();
|
||||
if (val) signatures[mbId] = val;
|
||||
});
|
||||
const data = {
|
||||
nimi: document.getElementById('profile-nimi').value,
|
||||
email: document.getElementById('profile-email').value,
|
||||
signatures,
|
||||
};
|
||||
const pw = document.getElementById('profile-password').value;
|
||||
if (pw) data.password = pw;
|
||||
@@ -1281,6 +1258,7 @@ document.getElementById('profile-form').addEventListener('submit', async (e) =>
|
||||
if (auth.authenticated) {
|
||||
currentUser = { username: auth.username, nimi: auth.nimi, role: auth.role, company_role: auth.company_role || '', id: auth.user_id };
|
||||
currentUserSignatures = auth.signatures || {};
|
||||
currentHiddenMailboxes = auth.hidden_mailboxes || [];
|
||||
document.getElementById('user-info').textContent = auth.nimi || auth.username;
|
||||
}
|
||||
profileModal.style.display = 'none';
|
||||
@@ -1325,6 +1303,11 @@ function renderTickets() {
|
||||
const showClosed = document.getElementById('ticket-show-closed').checked;
|
||||
let filtered = tickets;
|
||||
|
||||
// Piilota piilotettujen postilaatikoiden tiketit
|
||||
if (currentHiddenMailboxes.length > 0) {
|
||||
filtered = filtered.filter(t => !currentHiddenMailboxes.includes(String(t.mailbox_id)) && !currentHiddenMailboxes.includes(t.mailbox_id));
|
||||
}
|
||||
|
||||
// Suljetut näkyvät vain kun täppä on päällä
|
||||
if (showClosed) {
|
||||
filtered = filtered.filter(t => t.status === 'suljettu');
|
||||
@@ -1679,6 +1662,7 @@ async function showTicketDetail(id, companyId = '') {
|
||||
document.getElementById('ticket-list-view').style.display = 'none';
|
||||
document.getElementById('ticket-rules-view').style.display = 'none';
|
||||
document.getElementById('ticket-templates-view').style.display = 'none';
|
||||
document.getElementById('ticket-settings-view').style.display = 'none';
|
||||
document.getElementById('ticket-detail-view').style.display = 'block';
|
||||
|
||||
// Reset reply form
|
||||
@@ -1702,7 +1686,12 @@ async function showTicketDetail(id, companyId = '') {
|
||||
if (mbSelect) {
|
||||
try {
|
||||
const mailboxes = await apiCall('all_mailboxes');
|
||||
mbSelect.innerHTML = mailboxes.map(mb =>
|
||||
// Suodata pois piilotetut postilaatikot (paitsi jos tiketin oma mailbox on piilotettu — se näytetään silti)
|
||||
const visibleMailboxes = mailboxes.filter(mb =>
|
||||
mb.id === (ticket.mailbox_id || '') ||
|
||||
(!currentHiddenMailboxes.includes(String(mb.id)) && !currentHiddenMailboxes.includes(mb.id))
|
||||
);
|
||||
mbSelect.innerHTML = visibleMailboxes.map(mb =>
|
||||
`<option value="${esc(mb.id)}" ${mb.id === (ticket.mailbox_id || '') ? 'selected' : ''}>${esc(mb.nimi || mb.smtp_from_email)} <${esc(mb.smtp_from_email)}></option>`
|
||||
).join('');
|
||||
// Vaihda allekirjoitusta kun mailbox vaihtuu
|
||||
@@ -1772,6 +1761,7 @@ function showTicketListView() {
|
||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||
document.getElementById('ticket-rules-view').style.display = 'none';
|
||||
document.getElementById('ticket-templates-view').style.display = 'none';
|
||||
document.getElementById('ticket-settings-view').style.display = 'none';
|
||||
document.getElementById('ticket-list-view').style.display = 'block';
|
||||
currentTicketId = null;
|
||||
// Reset bulk selection
|
||||
@@ -1968,6 +1958,7 @@ function showRulesView() {
|
||||
document.getElementById('ticket-list-view').style.display = 'none';
|
||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||
document.getElementById('ticket-templates-view').style.display = 'none';
|
||||
document.getElementById('ticket-settings-view').style.display = 'none';
|
||||
document.getElementById('ticket-rules-view').style.display = 'block';
|
||||
loadRules();
|
||||
}
|
||||
@@ -2051,6 +2042,7 @@ function showTemplatesView() {
|
||||
document.getElementById('ticket-list-view').style.display = 'none';
|
||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||
document.getElementById('ticket-rules-view').style.display = 'none';
|
||||
document.getElementById('ticket-settings-view').style.display = 'none';
|
||||
document.getElementById('ticket-templates-view').style.display = 'block';
|
||||
hideTplForm();
|
||||
renderTplList();
|
||||
@@ -2129,6 +2121,87 @@ window.deleteTpl = async function(id) {
|
||||
} catch (e) { alert(e.message); }
|
||||
};
|
||||
|
||||
// ==================== OMAT ASETUKSET (TIKETTIEN ASETUKSET) ====================
|
||||
|
||||
async function openTicketSettings() {
|
||||
// Piilota muut näkymät, näytä asetukset
|
||||
document.getElementById('ticket-list-view').style.display = 'none';
|
||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||
document.getElementById('ticket-rules-view').style.display = 'none';
|
||||
document.getElementById('ticket-templates-view').style.display = 'none';
|
||||
document.getElementById('ticket-settings-view').style.display = 'block';
|
||||
|
||||
const sigContainer = document.getElementById('ticket-settings-signatures');
|
||||
const visContainer = document.getElementById('ticket-settings-mailbox-visibility');
|
||||
sigContainer.innerHTML = '<p style="color:#888;font-size:0.85rem;">Ladataan...</p>';
|
||||
visContainer.innerHTML = '';
|
||||
|
||||
try {
|
||||
const mailboxes = await apiCall('all_mailboxes');
|
||||
if (mailboxes.length === 0) {
|
||||
sigContainer.innerHTML = '<p style="color:#888;font-size:0.85rem;">Ei postilaatikoita.</p>';
|
||||
visContainer.innerHTML = '<p style="color:#888;font-size:0.85rem;">Ei postilaatikoita.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Allekirjoitukset per postilaatikko
|
||||
sigContainer.innerHTML = mailboxes.map(mb =>
|
||||
`<div style="margin-bottom:0.75rem;">
|
||||
<label style="font-weight:600;font-size:0.85rem;color:#333;">${esc(mb.company_nimi)} — ${esc(mb.nimi)}</label>
|
||||
<textarea class="ticket-sig-textarea" data-mailbox-id="${mb.id}" rows="3"
|
||||
style="width:100%;margin-top:0.25rem;padding:8px;border:1px solid #ddd;border-radius:6px;font-size:0.85rem;font-family:inherit;resize:vertical;"
|
||||
placeholder="esim.\nJukka\nYritys Oy\ninfo@yritys.fi">${esc(currentUserSignatures[mb.id] || '')}</textarea>
|
||||
</div>`
|
||||
).join('');
|
||||
|
||||
// Postilaatikoiden näkyvyys — checkbox per postilaatikko
|
||||
visContainer.innerHTML = mailboxes.map(mb => {
|
||||
const isHidden = currentHiddenMailboxes.includes(String(mb.id)) || currentHiddenMailboxes.includes(mb.id);
|
||||
return `<label style="display:flex;align-items:center;gap:0.5rem;margin-bottom:0.5rem;font-size:0.9rem;cursor:pointer;">
|
||||
<input type="checkbox" class="mb-visibility-cb" data-mailbox-id="${mb.id}" ${!isHidden ? 'checked' : ''}>
|
||||
<span>${esc(mb.company_nimi)} — ${esc(mb.nimi)} <${esc(mb.smtp_from_email)}></span>
|
||||
</label>`;
|
||||
}).join('');
|
||||
} catch (e) {
|
||||
sigContainer.innerHTML = '<p style="color:red;font-size:0.85rem;">Virhe ladattaessa postilaatikoita.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function closeTicketSettings() {
|
||||
document.getElementById('ticket-settings-view').style.display = 'none';
|
||||
document.getElementById('ticket-list-view').style.display = 'block';
|
||||
}
|
||||
|
||||
document.getElementById('btn-ticket-settings').addEventListener('click', () => openTicketSettings());
|
||||
|
||||
document.getElementById('btn-save-ticket-settings').addEventListener('click', async () => {
|
||||
// Kerää allekirjoitukset
|
||||
const signatures = {};
|
||||
document.querySelectorAll('.ticket-sig-textarea').forEach(ta => {
|
||||
const mbId = ta.getAttribute('data-mailbox-id');
|
||||
signatures[mbId] = ta.value;
|
||||
});
|
||||
|
||||
// Kerää piilotetut postilaatikot (ne joissa checkbox EI ole päällä)
|
||||
const hiddenMailboxes = [];
|
||||
document.querySelectorAll('.mb-visibility-cb').forEach(cb => {
|
||||
if (!cb.checked) {
|
||||
hiddenMailboxes.push(cb.getAttribute('data-mailbox-id'));
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await apiCall('profile_update', 'POST', { signatures, hidden_mailboxes: hiddenMailboxes });
|
||||
// Päivitä lokaalit muuttujat
|
||||
currentUserSignatures = signatures;
|
||||
currentHiddenMailboxes = hiddenMailboxes;
|
||||
closeTicketSettings();
|
||||
// Lataa tiketit uudelleen suodatuksen päivittämiseksi
|
||||
loadTickets();
|
||||
alert('Asetukset tallennettu!');
|
||||
} catch (e) { alert(e.message); }
|
||||
});
|
||||
|
||||
// ==================== BULK ACTIONS ====================
|
||||
|
||||
let bulkSelectedIds = new Set();
|
||||
|
||||
Reference in New Issue
Block a user