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:
4
api.php
4
api.php
@@ -1461,6 +1461,7 @@ switch ($action) {
|
|||||||
'signatures' => $userSignatures,
|
'signatures' => $userSignatures,
|
||||||
'branding' => $branding,
|
'branding' => $branding,
|
||||||
'enabled_modules' => $enabledModules,
|
'enabled_modules' => $enabledModules,
|
||||||
|
'hidden_mailboxes' => $u ? ($u['hidden_mailboxes'] ?? []) : [],
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(['authenticated' => false]);
|
echo json_encode(['authenticated' => false]);
|
||||||
@@ -1756,6 +1757,9 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
$u['signatures'] = $sigs;
|
$u['signatures'] = $sigs;
|
||||||
}
|
}
|
||||||
|
if (isset($input['hidden_mailboxes']) && is_array($input['hidden_mailboxes'])) {
|
||||||
|
$u['hidden_mailboxes'] = array_map('strval', $input['hidden_mailboxes']);
|
||||||
|
}
|
||||||
dbSaveUser($u);
|
dbSaveUser($u);
|
||||||
// Päivitä session nimi
|
// Päivitä session nimi
|
||||||
$_SESSION['nimi'] = $u['nimi'];
|
$_SESSION['nimi'] = $u['nimi'];
|
||||||
|
|||||||
21
db.php
21
db.php
@@ -159,6 +159,13 @@ function initDatabase(): void {
|
|||||||
UNIQUE KEY udx_user_mailbox (user_id, mailbox_id)
|
UNIQUE KEY udx_user_mailbox (user_id, mailbox_id)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
|
||||||
|
|
||||||
|
"CREATE TABLE IF NOT EXISTS user_hidden_mailboxes (
|
||||||
|
user_id VARCHAR(20) NOT NULL,
|
||||||
|
mailbox_id VARCHAR(20) NOT NULL,
|
||||||
|
PRIMARY KEY (user_id, mailbox_id),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
|
||||||
|
|
||||||
"CREATE TABLE IF NOT EXISTS config (
|
"CREATE TABLE IF NOT EXISTS config (
|
||||||
config_key VARCHAR(100) PRIMARY KEY,
|
config_key VARCHAR(100) PRIMARY KEY,
|
||||||
config_value TEXT
|
config_value TEXT
|
||||||
@@ -776,6 +783,8 @@ function dbGetUser(string $id): ?array {
|
|||||||
}
|
}
|
||||||
$u['signatures'] = $sigs;
|
$u['signatures'] = $sigs;
|
||||||
|
|
||||||
|
$u['hidden_mailboxes'] = _dbFetchColumn("SELECT mailbox_id FROM user_hidden_mailboxes WHERE user_id = ?", [$id]);
|
||||||
|
|
||||||
return $u;
|
return $u;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -797,6 +806,8 @@ function dbGetUserByUsername(string $username): ?array {
|
|||||||
}
|
}
|
||||||
$u['signatures'] = $sigs;
|
$u['signatures'] = $sigs;
|
||||||
|
|
||||||
|
$u['hidden_mailboxes'] = _dbFetchColumn("SELECT mailbox_id FROM user_hidden_mailboxes WHERE user_id = ?", [$u['id']]);
|
||||||
|
|
||||||
return $u;
|
return $u;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -838,6 +849,16 @@ function dbSaveUser(array $user): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Piilotetut postilaatikot
|
||||||
|
if (array_key_exists('hidden_mailboxes', $user)) {
|
||||||
|
_dbExecute("DELETE FROM user_hidden_mailboxes WHERE user_id = ?", [$user['id']]);
|
||||||
|
if (!empty($user['hidden_mailboxes'])) {
|
||||||
|
foreach ($user['hidden_mailboxes'] as $mbId) {
|
||||||
|
_dbExecute("INSERT IGNORE INTO user_hidden_mailboxes (user_id, mailbox_id) VALUES (?, ?)", [$user['id'], $mbId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
|
|||||||
31
index.html
31
index.html
@@ -1136,6 +1136,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<button class="btn-secondary" id="btn-ticket-templates" style="padding:7px 14px;font-size:0.82rem;">📝 Vastauspohjat</button>
|
<button class="btn-secondary" id="btn-ticket-templates" style="padding:7px 14px;font-size:0.82rem;">📝 Vastauspohjat</button>
|
||||||
<button class="btn-secondary" id="btn-ticket-rules" style="padding:7px 14px;font-size:0.82rem;">⚙ Säännöt</button>
|
<button class="btn-secondary" id="btn-ticket-rules" style="padding:7px 14px;font-size:0.82rem;">⚙ Säännöt</button>
|
||||||
|
<button class="btn-secondary" id="btn-ticket-settings" style="padding:7px 14px;font-size:0.82rem;">⚙ Omat asetukset</button>
|
||||||
<label style="display:flex;align-items:center;gap:0.4rem;font-size:0.82rem;color:#777;cursor:pointer;white-space:nowrap;margin-left:auto;">
|
<label style="display:flex;align-items:center;gap:0.4rem;font-size:0.82rem;color:#777;cursor:pointer;white-space:nowrap;margin-left:auto;">
|
||||||
<input type="checkbox" id="ticket-auto-refresh" checked> Autopäivitys
|
<input type="checkbox" id="ticket-auto-refresh" checked> Autopäivitys
|
||||||
<select id="ticket-refresh-interval" style="padding:3px 6px;border:1px solid #ddd;border-radius:5px;font-size:0.8rem;">
|
<select id="ticket-refresh-interval" style="padding:3px 6px;border:1px solid #ddd;border-radius:5px;font-size:0.8rem;">
|
||||||
@@ -1327,6 +1328,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Omat asetukset -näkymä -->
|
||||||
|
<div id="ticket-settings-view" style="display:none;">
|
||||||
|
<div style="display:flex;align-items:center;gap:1rem;margin-bottom:1.5rem;">
|
||||||
|
<button class="btn-secondary" onclick="closeTicketSettings()">← Takaisin</button>
|
||||||
|
<h2 style="color:#0f3460;font-size:1.15rem;margin:0;">Omat asetukset</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-card" style="padding:1.5rem;margin-bottom:1.5rem;">
|
||||||
|
<h3 style="color:#0f3460;font-size:1rem;margin-bottom:0.75rem;">Sähköpostiallekirjoitukset</h3>
|
||||||
|
<p style="color:#888;font-size:0.82rem;margin-bottom:1rem;">Allekirjoitus liitetään automaattisesti sähköpostivastausten loppuun.</p>
|
||||||
|
<div id="ticket-settings-signatures"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-card" style="padding:1.5rem;margin-bottom:1.5rem;">
|
||||||
|
<h3 style="color:#0f3460;font-size:1rem;margin-bottom:0.75rem;">Postilaatikoiden näkyvyys</h3>
|
||||||
|
<p style="color:#888;font-size:0.82rem;margin-bottom:1rem;">Poista rasti postilaatikoista joiden tikettejä et halua nähdä.</p>
|
||||||
|
<div id="ticket-settings-mailbox-visibility"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex;gap:0.75rem;">
|
||||||
|
<button class="btn-primary" id="btn-save-ticket-settings">Tallenna asetukset</button>
|
||||||
|
<button class="btn-secondary" onclick="closeTicketSettings()">Peruuta</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1994,11 +2020,6 @@
|
|||||||
<input type="password" id="profile-password">
|
<input type="password" id="profile-password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="profile-signatures-section" style="display:none;margin-top:1rem;border-top:1px solid #e5e7eb;padding-top:1rem;">
|
|
||||||
<h3 style="color:#0f3460;font-size:1rem;margin-bottom:0.75rem;">Sähköpostiallekirjoitukset</h3>
|
|
||||||
<p style="color:#888;font-size:0.82rem;margin-bottom:0.75rem;">Allekirjoitus liitetään automaattisesti sähköpostivastausten loppuun.</p>
|
|
||||||
<div id="profile-signatures-list"></div>
|
|
||||||
</div>
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn-primary">Tallenna</button>
|
<button type="submit" class="btn-primary">Tallenna</button>
|
||||||
<button type="button" class="btn-secondary" id="profile-form-cancel">Peruuta</button>
|
<button type="button" class="btn-secondary" id="profile-form-cancel">Peruuta</button>
|
||||||
|
|||||||
133
script.js
133
script.js
@@ -8,6 +8,7 @@ let currentCompany = null; // {id, nimi}
|
|||||||
let availableCompanies = []; // [{id, nimi}, ...]
|
let availableCompanies = []; // [{id, nimi}, ...]
|
||||||
let currentTicketCompanyId = ''; // Avatun tiketin yritys (cross-company tuki)
|
let currentTicketCompanyId = ''; // Avatun tiketin yritys (cross-company tuki)
|
||||||
let currentUserSignatures = {}; // {mailbox_id: "allekirjoitus teksti"}
|
let currentUserSignatures = {}; // {mailbox_id: "allekirjoitus teksti"}
|
||||||
|
let currentHiddenMailboxes = []; // ['mailbox_id1', ...] — piilotetut postilaatikot
|
||||||
|
|
||||||
// Elements
|
// Elements
|
||||||
const loginScreen = document.getElementById('login-screen');
|
const loginScreen = document.getElementById('login-screen');
|
||||||
@@ -142,6 +143,7 @@ async function checkAuth() {
|
|||||||
availableCompanies = data.companies || [];
|
availableCompanies = data.companies || [];
|
||||||
currentCompany = availableCompanies.find(c => c.id === data.company_id) || availableCompanies[0] || null;
|
currentCompany = availableCompanies.find(c => c.id === data.company_id) || availableCompanies[0] || null;
|
||||||
currentUserSignatures = data.signatures || {};
|
currentUserSignatures = data.signatures || {};
|
||||||
|
currentHiddenMailboxes = data.hidden_mailboxes || [];
|
||||||
if (data.branding) applyBranding(data.branding);
|
if (data.branding) applyBranding(data.branding);
|
||||||
applyModules(data.enabled_modules || []);
|
applyModules(data.enabled_modules || []);
|
||||||
showDashboard();
|
showDashboard();
|
||||||
@@ -164,6 +166,7 @@ loginForm.addEventListener('submit', async (e) => {
|
|||||||
availableCompanies = data.companies || [];
|
availableCompanies = data.companies || [];
|
||||||
currentCompany = availableCompanies.find(c => c.id === data.company_id) || availableCompanies[0] || null;
|
currentCompany = availableCompanies.find(c => c.id === data.company_id) || availableCompanies[0] || null;
|
||||||
currentUserSignatures = data.signatures || {};
|
currentUserSignatures = data.signatures || {};
|
||||||
|
currentHiddenMailboxes = data.hidden_mailboxes || [];
|
||||||
showDashboard();
|
showDashboard();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
loginError.textContent = err.message;
|
loginError.textContent = err.message;
|
||||||
@@ -240,6 +243,8 @@ async function switchCompany(companyId) {
|
|||||||
if (auth.branding) applyBranding(auth.branding);
|
if (auth.branding) applyBranding(auth.branding);
|
||||||
applyModules(auth.enabled_modules || []);
|
applyModules(auth.enabled_modules || []);
|
||||||
currentUser.company_role = auth.company_role || '';
|
currentUser.company_role = auth.company_role || '';
|
||||||
|
currentUserSignatures = auth.signatures || {};
|
||||||
|
currentHiddenMailboxes = auth.hidden_mailboxes || [];
|
||||||
} catch (e2) {}
|
} catch (e2) {}
|
||||||
// Päivitä admin-näkyvyys yritysroolin mukaan
|
// Päivitä admin-näkyvyys yritysroolin mukaan
|
||||||
updateAdminVisibility();
|
updateAdminVisibility();
|
||||||
@@ -1214,6 +1219,7 @@ document.getElementById('user-form').addEventListener('submit', async (e) => {
|
|||||||
if (auth.authenticated) {
|
if (auth.authenticated) {
|
||||||
currentUser = { username: auth.username, nimi: auth.nimi, role: auth.role, company_role: auth.company_role || '', id: auth.user_id };
|
currentUser = { username: auth.username, nimi: auth.nimi, role: auth.role, company_role: auth.company_role || '', id: auth.user_id };
|
||||||
currentUserSignatures = auth.signatures || {};
|
currentUserSignatures = auth.signatures || {};
|
||||||
|
currentHiddenMailboxes = auth.hidden_mailboxes || [];
|
||||||
}
|
}
|
||||||
} catch (e) { alert(e.message); }
|
} catch (e) { alert(e.message); }
|
||||||
});
|
});
|
||||||
@@ -1234,43 +1240,14 @@ async function openProfileModal() {
|
|||||||
document.getElementById('profile-nimi').value = auth.nimi || '';
|
document.getElementById('profile-nimi').value = auth.nimi || '';
|
||||||
document.getElementById('profile-email').value = auth.email || '';
|
document.getElementById('profile-email').value = auth.email || '';
|
||||||
document.getElementById('profile-password').value = '';
|
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';
|
profileModal.style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('profile-form').addEventListener('submit', async (e) => {
|
document.getElementById('profile-form').addEventListener('submit', async (e) => {
|
||||||
e.preventDefault();
|
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 = {
|
const data = {
|
||||||
nimi: document.getElementById('profile-nimi').value,
|
nimi: document.getElementById('profile-nimi').value,
|
||||||
email: document.getElementById('profile-email').value,
|
email: document.getElementById('profile-email').value,
|
||||||
signatures,
|
|
||||||
};
|
};
|
||||||
const pw = document.getElementById('profile-password').value;
|
const pw = document.getElementById('profile-password').value;
|
||||||
if (pw) data.password = pw;
|
if (pw) data.password = pw;
|
||||||
@@ -1281,6 +1258,7 @@ document.getElementById('profile-form').addEventListener('submit', async (e) =>
|
|||||||
if (auth.authenticated) {
|
if (auth.authenticated) {
|
||||||
currentUser = { username: auth.username, nimi: auth.nimi, role: auth.role, company_role: auth.company_role || '', id: auth.user_id };
|
currentUser = { username: auth.username, nimi: auth.nimi, role: auth.role, company_role: auth.company_role || '', id: auth.user_id };
|
||||||
currentUserSignatures = auth.signatures || {};
|
currentUserSignatures = auth.signatures || {};
|
||||||
|
currentHiddenMailboxes = auth.hidden_mailboxes || [];
|
||||||
document.getElementById('user-info').textContent = auth.nimi || auth.username;
|
document.getElementById('user-info').textContent = auth.nimi || auth.username;
|
||||||
}
|
}
|
||||||
profileModal.style.display = 'none';
|
profileModal.style.display = 'none';
|
||||||
@@ -1325,6 +1303,11 @@ function renderTickets() {
|
|||||||
const showClosed = document.getElementById('ticket-show-closed').checked;
|
const showClosed = document.getElementById('ticket-show-closed').checked;
|
||||||
let filtered = tickets;
|
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ä
|
// Suljetut näkyvät vain kun täppä on päällä
|
||||||
if (showClosed) {
|
if (showClosed) {
|
||||||
filtered = filtered.filter(t => t.status === 'suljettu');
|
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-list-view').style.display = 'none';
|
||||||
document.getElementById('ticket-rules-view').style.display = 'none';
|
document.getElementById('ticket-rules-view').style.display = 'none';
|
||||||
document.getElementById('ticket-templates-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';
|
document.getElementById('ticket-detail-view').style.display = 'block';
|
||||||
|
|
||||||
// Reset reply form
|
// Reset reply form
|
||||||
@@ -1702,7 +1686,12 @@ async function showTicketDetail(id, companyId = '') {
|
|||||||
if (mbSelect) {
|
if (mbSelect) {
|
||||||
try {
|
try {
|
||||||
const mailboxes = await apiCall('all_mailboxes');
|
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>`
|
`<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('');
|
).join('');
|
||||||
// Vaihda allekirjoitusta kun mailbox vaihtuu
|
// Vaihda allekirjoitusta kun mailbox vaihtuu
|
||||||
@@ -1772,6 +1761,7 @@ function showTicketListView() {
|
|||||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||||
document.getElementById('ticket-rules-view').style.display = 'none';
|
document.getElementById('ticket-rules-view').style.display = 'none';
|
||||||
document.getElementById('ticket-templates-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';
|
document.getElementById('ticket-list-view').style.display = 'block';
|
||||||
currentTicketId = null;
|
currentTicketId = null;
|
||||||
// Reset bulk selection
|
// Reset bulk selection
|
||||||
@@ -1968,6 +1958,7 @@ function showRulesView() {
|
|||||||
document.getElementById('ticket-list-view').style.display = 'none';
|
document.getElementById('ticket-list-view').style.display = 'none';
|
||||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||||
document.getElementById('ticket-templates-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';
|
document.getElementById('ticket-rules-view').style.display = 'block';
|
||||||
loadRules();
|
loadRules();
|
||||||
}
|
}
|
||||||
@@ -2051,6 +2042,7 @@ function showTemplatesView() {
|
|||||||
document.getElementById('ticket-list-view').style.display = 'none';
|
document.getElementById('ticket-list-view').style.display = 'none';
|
||||||
document.getElementById('ticket-detail-view').style.display = 'none';
|
document.getElementById('ticket-detail-view').style.display = 'none';
|
||||||
document.getElementById('ticket-rules-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';
|
document.getElementById('ticket-templates-view').style.display = 'block';
|
||||||
hideTplForm();
|
hideTplForm();
|
||||||
renderTplList();
|
renderTplList();
|
||||||
@@ -2129,6 +2121,87 @@ window.deleteTpl = async function(id) {
|
|||||||
} catch (e) { alert(e.message); }
|
} 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 ====================
|
// ==================== BULK ACTIONS ====================
|
||||||
|
|
||||||
let bulkSelectedIds = new Set();
|
let bulkSelectedIds = new Set();
|
||||||
|
|||||||
Reference in New Issue
Block a user