feat(124): sms templates CRUD + order picker
- Nowa tabela sms_templates (name + body + is_active) + minimalny CRUD.
- /settings/sms-templates: lista + formularz z paleta zmiennych (pill chips).
- Wydzielono Sms\SmsVariableResolver ze wspolna logika placeholderow;
Email\VariableResolver staje sie cienka fasada — EmailSendingService bez zmian.
- Dropdown "Wybierz szablon" w zakladce SMS na /orders/{id} z fetch
GET /orders/{id}/sms/template + OrderProAlerts.confirm przy nadpisaniu.
- Stopka SMSPLANET dalej doklejana wylacznie przez SmsConversationService
(Phase 122 contract preserved).
- Sidebar Ustawien: nowy link "Szablony SMS".
Migration: 20260512_000112_create_sms_templates.sql (CREATE TABLE).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -176,6 +176,8 @@ return [
|
||||
'message' => 'Tresc SMS',
|
||||
'footer_note' => 'Skonfigurowana stopka SMSPLANET zostanie dodana automatycznie.',
|
||||
'send' => 'Wyslij SMS',
|
||||
'template_picker' => 'Wybierz szablon',
|
||||
'template_picker_placeholder' => '— Wybierz szablon —',
|
||||
],
|
||||
'items_title' => 'Pozycje',
|
||||
'item_name' => 'Nazwa',
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
@use "modules/order-preview-modal";
|
||||
@use "modules/project-mappings";
|
||||
@use "modules/customer-risk-alert";
|
||||
@use "modules/sms-templates";
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
|
||||
137
resources/scss/modules/_sms-templates.scss
Normal file
137
resources/scss/modules/_sms-templates.scss
Normal file
@@ -0,0 +1,137 @@
|
||||
.sms-template-active-field {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.sms-template-active-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.sms-template-active-text {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.sms-template-counter {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.sms-template-counter-warning {
|
||||
color: #b45309;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.sms-template-actions {
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sms-template-actions > form {
|
||||
display: inline-flex;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.sms-var-panel {
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 8px;
|
||||
background: #f9fafb;
|
||||
padding: 12px 14px;
|
||||
}
|
||||
|
||||
.sms-var-panel__head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.sms-var-panel__title {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
color: #374151;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.sms-var-panel__hint {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.sms-var-group {
|
||||
padding: 8px 0;
|
||||
border-top: 1px dashed #e5e7eb;
|
||||
}
|
||||
|
||||
.sms-var-group:first-of-type {
|
||||
border-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.sms-var-group__label {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
color: #6b7280;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.sms-var-group__items {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.sms-var-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
background: #fff;
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 999px;
|
||||
padding: 4px 10px;
|
||||
cursor: pointer;
|
||||
color: #1f2937;
|
||||
line-height: 1.4;
|
||||
transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
|
||||
}
|
||||
|
||||
.sms-var-item code {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 11px;
|
||||
color: #4338ca;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.sms-var-item__desc {
|
||||
color: #6b7280;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.sms-var-item:hover {
|
||||
background: #eef2ff;
|
||||
border-color: #6366f1;
|
||||
color: #1e1b4b;
|
||||
}
|
||||
|
||||
.sms-var-item:hover code {
|
||||
color: #1e1b4b;
|
||||
}
|
||||
|
||||
.sms-var-item:hover .sms-var-item__desc {
|
||||
color: #312e81;
|
||||
}
|
||||
|
||||
.order-sms-template-picker {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
@@ -121,6 +121,9 @@
|
||||
<a class="sidebar__sublink<?= $currentMenu === 'settings' && $currentSettings === 'email-templates' ? ' is-active' : '' ?>" href="/settings/email-templates">
|
||||
Szablony e-mail
|
||||
</a>
|
||||
<a class="sidebar__sublink<?= $currentMenu === 'settings' && $currentSettings === 'sms-templates' ? ' is-active' : '' ?>" href="/settings/sms-templates">
|
||||
Szablony SMS
|
||||
</a>
|
||||
<a class="sidebar__sublink<?= $currentMenu === 'settings' && $currentSettings === 'automation' ? ' is-active' : '' ?>" href="/settings/automation">
|
||||
Zadania automatyczne
|
||||
</a>
|
||||
@@ -214,6 +217,7 @@
|
||||
<script src="/assets/js/modules/confirm-delete.js?ver=<?= filemtime(dirname(__DIR__, 3) . '/public/assets/js/modules/confirm-delete.js') ?: 0 ?>"></script>
|
||||
<script src="/assets/js/modules/alert-dismiss.js?ver=<?= filemtime(dirname(__DIR__, 3) . '/public/assets/js/modules/alert-dismiss.js') ?: 0 ?>"></script>
|
||||
<script src="/assets/js/modules/notifications.js?ver=<?= filemtime(dirname(__DIR__, 3) . '/public/assets/js/modules/notifications.js') ?: 0 ?>"></script>
|
||||
<script src="/assets/js/modules/sms-template-picker.js?ver=<?= filemtime(dirname(__DIR__, 3) . '/public/assets/js/modules/sms-template-picker.js') ?: 0 ?>"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.8/dist/chart.umd.min.js"></script>
|
||||
<script src="/assets/js/modules/statistics-summary-charts.js?ver=<?= filemtime(dirname(__DIR__, 3) . '/public/assets/js/modules/statistics-summary-charts.js') ?: 0 ?>"></script>
|
||||
<script>
|
||||
|
||||
@@ -17,6 +17,7 @@ $emailMailboxesList = is_array($emailMailboxes ?? null) ? $emailMailboxes : [];
|
||||
$smsMessagesList = is_array($smsMessages ?? null) ? $smsMessages : [];
|
||||
$smsPhoneValue = trim((string) ($smsPhone ?? ''));
|
||||
$smsDefaultFooterConfigured = (bool) ($smsDefaultFooterConfigured ?? false);
|
||||
$smsTemplatesList = is_array($smsTemplates ?? null) ? $smsTemplates : [];
|
||||
$historyList = is_array($history ?? null) ? $history : [];
|
||||
$activityLogList = is_array($activityLog ?? null) ? $activityLog : [];
|
||||
$statusPanelList = is_array($statusPanel ?? null) ? $statusPanel : [];
|
||||
@@ -1020,9 +1021,20 @@ foreach ($addressesList as $address) {
|
||||
<span class="field-label"><?= $e($t('orders.details.sms.phone')) ?></span>
|
||||
<input class="form-control" type="tel" name="phone" inputmode="tel" value="<?= $e($smsPhoneValue) ?>" required>
|
||||
</label>
|
||||
<?php if ($smsTemplatesList !== []): ?>
|
||||
<label class="form-field order-sms-template-picker">
|
||||
<span class="field-label"><?= $e($t('orders.details.sms.template_picker')) ?></span>
|
||||
<select class="form-control" data-sms-template-picker data-order-id="<?= (int) ($orderId ?? 0) ?>" data-message-target="js-sms-message">
|
||||
<option value=""><?= $e($t('orders.details.sms.template_picker_placeholder')) ?></option>
|
||||
<?php foreach ($smsTemplatesList as $smsTpl): ?>
|
||||
<option value="<?= (int) ($smsTpl['id'] ?? 0) ?>"><?= $e((string) ($smsTpl['name'] ?? '')) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<label class="form-field">
|
||||
<span class="field-label"><?= $e($t('orders.details.sms.message')) ?></span>
|
||||
<textarea class="form-control" name="message" rows="3" maxlength="918" required></textarea>
|
||||
<textarea class="form-control" id="js-sms-message" name="message" rows="3" maxlength="918" required></textarea>
|
||||
<?php if ($smsDefaultFooterConfigured): ?>
|
||||
<span class="order-sms-footer-note"><?= $e($t('orders.details.sms.footer_note')) ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
109
resources/views/settings/sms-templates-form.php
Normal file
109
resources/views/settings/sms-templates-form.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
$template = is_array($template ?? null) ? $template : null;
|
||||
$isEdit = $template !== null;
|
||||
$variableGroups = is_array($variableGroups ?? null) ? $variableGroups : [];
|
||||
?>
|
||||
|
||||
<section class="card">
|
||||
<h2 class="section-title"><?= $isEdit ? 'Edytuj szablon SMS' : 'Dodaj szablon SMS' ?></h2>
|
||||
<p class="muted mt-12">Wpisz tresc wiadomosci ze zmiennymi typu <code>{{zamowienie.numer}}</code>. Stopka SMSPLANET jest doklejana automatycznie przy wysylce, nie dopisuj jej w szablonie.</p>
|
||||
|
||||
<?php if (!empty($errorMessage)): ?>
|
||||
<div class="mt-12"><?php $type='danger'; $message=(string) $errorMessage; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($successMessage)): ?>
|
||||
<div class="mt-12"><?php $type='success'; $message=(string) $successMessage; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<section class="card mt-16">
|
||||
<form action="/settings/sms-templates/save" method="post" novalidate class="mt-12" id="js-sms-template-form">
|
||||
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
||||
<?php if ($isEdit): ?>
|
||||
<input type="hidden" name="id" value="<?= (int) ($template['id'] ?? 0) ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-grid-2">
|
||||
<label class="form-field">
|
||||
<span class="field-label">Nazwa szablonu *</span>
|
||||
<input class="form-control" type="text" name="name" maxlength="200" required value="<?= $e((string) ($template['name'] ?? '')) ?>" placeholder="np. Numer sledzenia">
|
||||
</label>
|
||||
<div class="form-field sms-template-active-field">
|
||||
<label class="sms-template-active-label">
|
||||
<input type="checkbox" name="is_active" value="1"<?= $isEdit ? (((int) ($template['is_active'] ?? 0)) === 1 ? ' checked' : '') : ' checked' ?>>
|
||||
<span class="field-label sms-template-active-text">Aktywny</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-12">
|
||||
<label class="form-field">
|
||||
<span class="field-label">Tresc wiadomosci *</span>
|
||||
<textarea class="form-control" name="body" id="js-sms-body" rows="6" maxlength="918" required placeholder="np. Czesc {{kupujacy.imie_nazwisko}}, Twoja przesylka {{przesylka.numer}} jest w drodze."><?= $e((string) ($template['body'] ?? '')) ?></textarea>
|
||||
<div class="sms-template-counter muted mt-4">
|
||||
<span id="js-sms-body-count">0</span> / 918 znakow
|
||||
<span class="sms-template-counter-warning" id="js-sms-body-warn" hidden>(pamietaj o stopce dodawanej przez SMSPLANET)</span>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="sms-var-panel mt-12">
|
||||
<div class="sms-var-panel__head">
|
||||
<span class="field-label sms-var-panel__title">Dostepne zmienne</span>
|
||||
<span class="muted sms-var-panel__hint">Kliknij chip, aby wstawic w pozycji kursora.</span>
|
||||
</div>
|
||||
<?php foreach ($variableGroups as $groupKey => $group): ?>
|
||||
<div class="sms-var-group" data-group="<?= $e($groupKey) ?>">
|
||||
<div class="sms-var-group__label"><?= $e((string) ($group['label'] ?? '')) ?></div>
|
||||
<div class="sms-var-group__items">
|
||||
<?php foreach (($group['vars'] ?? []) as $varKey => $varDesc): ?>
|
||||
<button type="button" class="sms-var-item js-sms-var-insert" data-var="{{<?= $e($groupKey . '.' . $varKey) ?>}}" title="<?= $e((string) $varDesc) ?>">
|
||||
<code>{{<?= $e($groupKey . '.' . $varKey) ?>}}</code>
|
||||
<span class="sms-var-item__desc"><?= $e((string) $varDesc) ?></span>
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div class="form-actions mt-16">
|
||||
<button type="submit" class="btn btn--primary"><?= $isEdit ? 'Zapisz zmiany' : 'Dodaj szablon' ?></button>
|
||||
<a href="/settings/sms-templates" class="btn btn--secondary">Powrot do listy</a>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var textarea = document.getElementById('js-sms-body');
|
||||
var counter = document.getElementById('js-sms-body-count');
|
||||
var warn = document.getElementById('js-sms-body-warn');
|
||||
if (!textarea || !counter) return;
|
||||
|
||||
function updateCount() {
|
||||
var len = textarea.value.length;
|
||||
counter.textContent = String(len);
|
||||
if (warn) {
|
||||
warn.hidden = len < 700;
|
||||
}
|
||||
}
|
||||
updateCount();
|
||||
textarea.addEventListener('input', updateCount);
|
||||
|
||||
document.querySelectorAll('.js-sms-var-insert').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var snippet = btn.getAttribute('data-var') || '';
|
||||
var start = textarea.selectionStart || 0;
|
||||
var end = textarea.selectionEnd || 0;
|
||||
var before = textarea.value.substring(0, start);
|
||||
var after = textarea.value.substring(end);
|
||||
textarea.value = before + snippet + after;
|
||||
var pos = start + snippet.length;
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(pos, pos);
|
||||
updateCount();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
110
resources/views/settings/sms-templates.php
Normal file
110
resources/views/settings/sms-templates.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
$templates = is_array($templates ?? null) ? $templates : [];
|
||||
?>
|
||||
|
||||
<section class="card">
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">Szablony SMS</h2>
|
||||
<a href="/settings/sms-templates/create" class="btn btn--primary btn--sm">Dodaj szablon</a>
|
||||
</div>
|
||||
<p class="muted mt-12">Szybkie szablony wiadomosci SMS do wstawiania z zakladki SMS w szczegolach zamowienia. Stopka SMSPLANET jest doklejana automatycznie.</p>
|
||||
|
||||
<?php if (!empty($errorMessage)): ?>
|
||||
<div class="mt-12"><?php $type='danger'; $message=(string) $errorMessage; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($successMessage)): ?>
|
||||
<div class="mt-12"><?php $type='success'; $message=(string) $successMessage; $dismissible=true; include dirname(__DIR__) . '/components/alert.php'; ?></div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<section class="card mt-16">
|
||||
<h3 class="section-title">Lista szablonow</h3>
|
||||
|
||||
<?php if (count($templates) === 0): ?>
|
||||
<p class="muted mt-12">Brak szablonow. Kliknij "Dodaj szablon", aby utworzyc pierwszy.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-wrap mt-12">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nazwa</th>
|
||||
<th>Tresc</th>
|
||||
<th>Status</th>
|
||||
<th>Akcje</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($templates as $tpl): ?>
|
||||
<?php
|
||||
$templateId = (int) ($tpl['id'] ?? 0);
|
||||
$bodyPreview = trim((string) ($tpl['body'] ?? ''));
|
||||
if (function_exists('mb_strlen') ? mb_strlen($bodyPreview) > 80 : strlen($bodyPreview) > 80) {
|
||||
$bodyPreview = (function_exists('mb_substr') ? mb_substr($bodyPreview, 0, 80) : substr($bodyPreview, 0, 80)) . '...';
|
||||
}
|
||||
?>
|
||||
<tr data-id="<?= $templateId ?>">
|
||||
<td><?= $e((string) ($tpl['name'] ?? '')) ?></td>
|
||||
<td><?= $e($bodyPreview) ?></td>
|
||||
<td>
|
||||
<?php if (((int) ($tpl['is_active'] ?? 0)) === 1): ?>
|
||||
<span class="badge badge--success js-status-badge">Aktywny</span>
|
||||
<?php else: ?>
|
||||
<span class="badge badge--muted js-status-badge">Nieaktywny</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="sms-template-actions">
|
||||
<a href="/settings/sms-templates/edit?id=<?= $templateId ?>" class="btn btn--sm btn--secondary">Edytuj</a>
|
||||
<button type="button" class="btn btn--sm btn--secondary js-toggle-btn"
|
||||
data-id="<?= $templateId ?>"
|
||||
data-active="<?= (int) ($tpl['is_active'] ?? 0) ?>">
|
||||
<?= ((int) ($tpl['is_active'] ?? 0)) === 1 ? 'Dezaktywuj' : 'Aktywuj' ?>
|
||||
</button>
|
||||
<form action="/settings/sms-templates/delete" method="post" class="inline-form js-confirm-delete" data-confirm-title="Usuwanie szablonu" data-confirm-message="Czy na pewno chcesz usunac ten szablon SMS?">
|
||||
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
||||
<input type="hidden" name="id" value="<?= $templateId ?>">
|
||||
<button type="button" class="btn btn--sm btn--danger js-delete-btn">Usun</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var csrfToken = <?= json_encode($csrfToken ?? '', JSON_HEX_TAG) ?>;
|
||||
|
||||
document.querySelectorAll('.js-toggle-btn').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var id = this.getAttribute('data-id');
|
||||
var isActive = this.getAttribute('data-active') === '1';
|
||||
var toggleBtn = this;
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('_token', csrfToken);
|
||||
fd.append('id', id);
|
||||
|
||||
toggleBtn.disabled = true;
|
||||
fetch('/settings/sms-templates/toggle', { method: 'POST', body: fd })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
if (data.success) {
|
||||
var newActive = !isActive;
|
||||
toggleBtn.setAttribute('data-active', newActive ? '1' : '0');
|
||||
toggleBtn.textContent = newActive ? 'Dezaktywuj' : 'Aktywuj';
|
||||
var badge = toggleBtn.closest('tr').querySelector('.js-status-badge');
|
||||
if (badge) {
|
||||
badge.textContent = newActive ? 'Aktywny' : 'Nieaktywny';
|
||||
badge.className = 'badge js-status-badge ' + (newActive ? 'badge--success' : 'badge--muted');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(function () {})
|
||||
.finally(function () { toggleBtn.disabled = false; });
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user