diff --git a/api.php b/api.php index 60aa2e2..505e160 100644 --- a/api.php +++ b/api.php @@ -2108,12 +2108,15 @@ switch ($action) { $replyMailbox = $companyConf['mailboxes'][0]; } - // Hae käyttäjän allekirjoitus tälle postilaatikolle + // Hae käyttäjän allekirjoitus tälle postilaatikolle (ellei estetty) + $noSignature = !empty($input['no_signature']); $mailboxId = $replyMailbox['id'] ?? ''; $signature = ''; - $sigUser = dbGetUser($_SESSION['user_id']); - if ($sigUser) { - $signature = trim($sigUser['signatures'][$mailboxId] ?? ''); + if (!$noSignature) { + $sigUser = dbGetUser($_SESSION['user_id']); + if ($sigUser) { + $signature = trim($sigUser['signatures'][$mailboxId] ?? ''); + } } $emailBody = $signature ? $body . "\n\n-- \n" . $signature : $body; diff --git a/index.html b/index.html index 54768c1..35ecef7 100644 --- a/index.html +++ b/index.html @@ -383,6 +383,7 @@ Suljetut + 📝 Vastauspohjat ⚙ Säännöt Autopäivitys @@ -458,7 +459,10 @@ - + + + Älä käytä allekirjoitusta + Lähetä vastaus @@ -534,6 +538,39 @@ + + + + ← Takaisin tiketteihin + + + Vastauspohjat + + Lisää pohja + + Yrityksen yhteiset vastauspohjat tiketteihin. Valittavissa vastauslomakkeen valikosta kaikille käyttäjille. + + + + + Uusi vastauspohja + + + + Nimi * + + + + Sisältö * + + + + + Tallenna + Peruuta + + + + diff --git a/script.js b/script.js index b2a0917..79906a1 100644 --- a/script.js +++ b/script.js @@ -1184,6 +1184,7 @@ document.getElementById('profile-form').addEventListener('submit', async (e) => } catch (e) { alert(e.message); } }); + // ==================== TICKETS (ASIAKASPALVELU) ==================== let tickets = []; @@ -1564,8 +1565,10 @@ async function showTicketDetail(id, companyId = '') { `; }).join(''); - // Show detail, hide list + // Show detail, hide list + other views 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-detail-view').style.display = 'block'; // Reset reply form @@ -1598,8 +1601,9 @@ async function showTicketDetail(id, companyId = '') { // Allekirjoituksen esikatselu function updateSignaturePreview(mbId) { const sigPreview = document.getElementById('signature-preview'); + const noSigCheck = document.getElementById('reply-no-signature'); const sig = currentUserSignatures[mbId] || ''; - if (sig) { + if (sig && !(noSigCheck && noSigCheck.checked)) { sigPreview.textContent = '-- \n' + sig; sigPreview.style.display = 'block'; } else { @@ -1608,6 +1612,15 @@ async function showTicketDetail(id, companyId = '') { } updateSignaturePreview(ticket.mailbox_id || ''); + // Allekirjoitus-checkbox: päivitä esikatselu vaihdettaessa + const noSigCheckbox = document.getElementById('reply-no-signature'); + if (noSigCheckbox) { + noSigCheckbox.addEventListener('change', () => { + const mbSelect = document.getElementById('reply-mailbox-select'); + updateSignaturePreview(mbSelect ? mbSelect.value : ''); + }); + } + // Vastauspohjat — lataa dropdown try { const templates = await apiCall('reply_templates'); @@ -1634,6 +1647,7 @@ async function showTicketDetail(id, companyId = '') { 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-list-view').style.display = 'block'; currentTicketId = null; // Reset bulk selection @@ -1659,19 +1673,23 @@ document.querySelectorAll('.btn-reply-tab').forEach(btn => { const sigPrev = document.getElementById('signature-preview'); const metaFields = document.getElementById('reply-meta-fields'); const tplWrap = document.getElementById('reply-template-select-wrap'); + const noSigLabel = document.getElementById('reply-no-signature') ? document.getElementById('reply-no-signature').closest('label') : null; if (ticketReplyType === 'note') { textarea.placeholder = 'Kirjoita sisäinen muistiinpano...'; sendBtn.textContent = 'Tallenna muistiinpano'; sigPrev.style.display = 'none'; if (metaFields) metaFields.style.display = 'none'; if (tplWrap) tplWrap.style.display = 'none'; + if (noSigLabel) noSigLabel.style.display = 'none'; } else { textarea.placeholder = 'Kirjoita vastaus...'; sendBtn.textContent = 'Lähetä vastaus'; if (metaFields) metaFields.style.display = ''; if (tplWrap) tplWrap.style.display = ''; - // Näytä allekirjoitus jos on asetettu - if (sigPrev.textContent.trim()) sigPrev.style.display = 'block'; + if (noSigLabel) noSigLabel.style.display = ''; + // Näytä allekirjoitus jos on asetettu ja checkbox sallii + const noSigCheck = document.getElementById('reply-no-signature'); + if (sigPrev.textContent.trim() && !(noSigCheck && noSigCheck.checked)) sigPrev.style.display = 'block'; } }); }); @@ -1692,8 +1710,10 @@ document.getElementById('btn-send-reply').addEventListener('click', async () => if (ticketReplyType !== 'note') { const mbSel = document.getElementById('reply-mailbox-select'); const ccFld = document.getElementById('reply-cc'); + const noSig = document.getElementById('reply-no-signature'); if (mbSel) payload.mailbox_id = mbSel.value; if (ccFld) payload.cc = ccFld.value.trim(); + if (noSig && noSig.checked) payload.no_signature = true; } await apiCall(action + ticketCompanyParam(), 'POST', payload); // Reload the detail view @@ -1821,6 +1841,7 @@ function renderRules() { 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-rules-view').style.display = 'block'; loadRules(); } @@ -1898,6 +1919,90 @@ async function toggleRule(id, enabled) { } catch (e) { alert(e.message); } } +// ==================== VASTAUSPOHJAT (TUKITABISSA) ==================== + +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-templates-view').style.display = 'block'; + hideTplForm(); + renderTplList(); +} + +function hideTemplatesView() { + document.getElementById('ticket-templates-view').style.display = 'none'; + document.getElementById('ticket-list-view').style.display = 'block'; +} + +function renderTplList() { + const list = document.getElementById('tpl-list'); + if (!list) return; + if (replyTemplates.length === 0) { + list.innerHTML = 'Ei vastauspohjia vielä. Lisää ensimmäinen klikkaamalla "+ Lisää pohja".'; + return; + } + list.innerHTML = replyTemplates.map(t => + ` + + ${esc(t.nimi)} + ${esc(t.body.substring(0, 100))} + + + Muokkaa + Poista + + ` + ).join(''); +} + +function showTplForm(tpl) { + document.getElementById('tpl-form-container').style.display = ''; + document.getElementById('tpl-form-title').textContent = tpl ? 'Muokkaa vastauspohjaa' : 'Uusi vastauspohja'; + document.getElementById('tpl-form-id').value = tpl ? tpl.id : ''; + document.getElementById('tpl-form-name').value = tpl ? tpl.nimi : ''; + document.getElementById('tpl-form-body').value = tpl ? tpl.body : ''; +} + +function hideTplForm() { + document.getElementById('tpl-form-container').style.display = 'none'; +} + +document.getElementById('btn-ticket-templates').addEventListener('click', async () => { + await loadTemplates(); + showTemplatesView(); +}); +document.getElementById('btn-templates-back').addEventListener('click', () => hideTemplatesView()); +document.getElementById('btn-add-tpl').addEventListener('click', () => showTplForm(null)); +document.getElementById('btn-cancel-tpl').addEventListener('click', () => hideTplForm()); + +document.getElementById('btn-save-tpl').addEventListener('click', async () => { + const nimi = document.getElementById('tpl-form-name').value.trim(); + const body = document.getElementById('tpl-form-body').value.trim(); + if (!nimi || !body) { alert('Täytä nimi ja sisältö'); return; } + const id = document.getElementById('tpl-form-id').value || undefined; + try { + await apiCall('reply_template_save', 'POST', { id, nimi, body }); + hideTplForm(); + await loadTemplates(); + renderTplList(); + } catch (e) { alert(e.message); } +}); + +window.editTpl = function(id) { + const t = replyTemplates.find(x => x.id === id); + if (t) showTplForm(t); +}; + +window.deleteTpl = async function(id) { + if (!confirm('Poistetaanko vastauspohja?')) return; + try { + await apiCall('reply_template_delete', 'POST', { id }); + await loadTemplates(); + renderTplList(); + } catch (e) { alert(e.message); } +}; + // ==================== BULK ACTIONS ==================== let bulkSelectedIds = new Set();
Yrityksen yhteiset vastauspohjat tiketteihin. Valittavissa vastauslomakkeen valikosta kaikille käyttäjille.
Ei vastauspohjia vielä. Lisää ensimmäinen klikkaamalla "+ Lisää pohja".