103 lines
4.2 KiB
PHP
103 lines
4.2 KiB
PHP
<?php
|
|
$rules = is_array($rules ?? null) ? $rules : [];
|
|
|
|
$eventLabels = [
|
|
'receipt.created' => 'Utworzono paragon',
|
|
'shipment.status_changed' => 'Zmiana statusu przesylki',
|
|
];
|
|
?>
|
|
|
|
<section class="card">
|
|
<div class="section-header">
|
|
<h2 class="section-title">Zadania automatyczne</h2>
|
|
<a href="/settings/automation/create" class="btn btn--primary btn--sm">Dodaj zadanie</a>
|
|
</div>
|
|
<p class="muted mt-12">Reguły automatyzacji wykonywane po wystąpieniu zdarzenia.</p>
|
|
|
|
<?php if (!empty($errorMessage)): ?>
|
|
<div class="alert alert--danger mt-12" role="alert"><?= $e((string) $errorMessage) ?></div>
|
|
<?php endif; ?>
|
|
<?php if (!empty($successMessage)): ?>
|
|
<div class="alert alert--success mt-12" role="status"><?= $e((string) $successMessage) ?></div>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<section class="card mt-16">
|
|
<?php if (count($rules) === 0): ?>
|
|
<p class="muted mt-12">Brak zadan automatycznych. Kliknij “Dodaj zadanie” aby utworzyc pierwsza regule.</p>
|
|
<?php else: ?>
|
|
<div class="table-wrap mt-12">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Nazwa</th>
|
|
<th>Zdarzenie</th>
|
|
<th>Warunkow</th>
|
|
<th>Akcji</th>
|
|
<th>Status</th>
|
|
<th>Akcje</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($rules as $rule): ?>
|
|
<tr>
|
|
<td><?= $e((string) ($rule['name'] ?? '')) ?></td>
|
|
<td><?= $e($eventLabels[(string) ($rule['event_type'] ?? '')] ?? (string) ($rule['event_type'] ?? '')) ?></td>
|
|
<td><?= (int) ($rule['conditions_count'] ?? 0) ?></td>
|
|
<td><?= (int) ($rule['actions_count'] ?? 0) ?></td>
|
|
<td>
|
|
<?php if (((int) ($rule['is_active'] ?? 0)) === 1): ?>
|
|
<span class="badge badge--success">Aktywne</span>
|
|
<?php else: ?>
|
|
<span class="badge badge--muted">Nieaktywne</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td style="white-space:nowrap">
|
|
<a href="/settings/automation/edit?id=<?= (int) ($rule['id'] ?? 0) ?>" class="btn btn--sm btn--secondary">Edytuj</a>
|
|
<form action="/settings/automation/duplicate" method="post" style="display:inline">
|
|
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
|
<input type="hidden" name="id" value="<?= (int) ($rule['id'] ?? 0) ?>">
|
|
<button type="submit" class="btn btn--sm btn--secondary">Duplikuj</button>
|
|
</form>
|
|
<form action="/settings/automation/toggle" method="post" style="display:inline">
|
|
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
|
<input type="hidden" name="id" value="<?= (int) ($rule['id'] ?? 0) ?>">
|
|
<button type="submit" class="btn btn--sm btn--secondary">
|
|
<?= ((int) ($rule['is_active'] ?? 0)) === 1 ? 'Dezaktywuj' : 'Aktywuj' ?>
|
|
</button>
|
|
</form>
|
|
<form action="/settings/automation/delete" method="post" style="display:inline" class="js-confirm-delete">
|
|
<input type="hidden" name="_token" value="<?= $e($csrfToken ?? '') ?>">
|
|
<input type="hidden" name="id" value="<?= (int) ($rule['id'] ?? 0) ?>">
|
|
<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() {
|
|
document.querySelectorAll('.js-delete-btn').forEach(function(btn) {
|
|
btn.addEventListener('click', function() {
|
|
var form = this.closest('form');
|
|
if (window.OrderProAlerts && window.OrderProAlerts.confirm) {
|
|
window.OrderProAlerts.confirm(
|
|
'Usuwanie zadania',
|
|
'Czy na pewno chcesz usunac to zadanie automatyczne?',
|
|
function() { form.submit(); }
|
|
);
|
|
} else {
|
|
if (confirm('Czy na pewno chcesz usunac to zadanie automatyczne?')) {
|
|
form.submit();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|