Files
CRM-IKZ/app/Views/admin/boards/fields/create.php
T
2026-07-14 08:19:56 +04:00

134 lines
5.8 KiB
PHP

<h1 class="h3 mb-3">Создание поля</h1>
<?php if (!empty($_SESSION['error'])): ?>
<div class="alert alert-danger">
<?= htmlspecialchars((string)$_SESSION['error']) ?>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
<?php if (!empty($_SESSION['success'])): ?>
<div class="alert alert-success">
<?= htmlspecialchars((string)$_SESSION['success']) ?>
</div>
<?php unset($_SESSION['success']); ?>
<?php endif; ?>
<div class="card shadow-sm">
<div class="card-body">
<form method="post" action="/admin/boards/fields/store">
<input type="hidden" name="board_id" value="<?= (int)$board['id'] ?>">
<div class="mb-3">
<label class="form-label">Доска</label>
<input type="text" class="form-control" value="<?= htmlspecialchars((string)$board['name']) ?>" disabled>
</div>
<div class="mb-3">
<label class="form-label">Код</label>
<input type="text" name="code" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Название</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label">Тип поля</label>
<select name="field_type" class="form-select" id="field_type">
<option value="text">text</option>
<option value="textarea">textarea</option>
<option value="number">number</option>
<option value="date">date</option>
<option value="select">select</option>
<option value="checkbox">checkbox</option>
</select>
</div>
<div class="mb-3" id="select_options_wrap" style="display:none;">
<label class="form-label">Варианты select</label>
<textarea name="select_options" class="form-control" rows="5" placeholder="Каждый вариант с новой строки"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Порядок</label>
<input type="number" name="sort_order" class="form-control" value="100">
</div>
<div class="form-check mb-2">
<input class="form-check-input" type="checkbox" name="is_required" id="is_required">
<label class="form-check-label" for="is_required">Обязательное</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="is_active" id="is_active" checked>
<label class="form-check-label" for="is_active">Активное</label>
</div>
<button type="submit" class="btn btn-success">Создать</button>
<a href="/admin/boards/fields?id=<?= (int)$board['id'] ?>" class="btn btn-secondary">Назад</a>
</form>
</div>
</div>
<?php if (!empty($fields)): ?>
<div class="card shadow-sm mt-4">
<div class="card-body">
<h5 class="mb-3">Уже созданные поля</h5>
<div class="table-responsive">
<table class="table table-sm align-middle mb-0">
<thead>
<tr>
<th>ID</th>
<th>Код</th>
<th>Название</th>
<th>Тип</th>
<th>Порядок</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($fields as $field): ?>
<tr>
<td><?= (int)$field['id'] ?></td>
<td><?= htmlspecialchars((string)$field['code']) ?></td>
<td><?= htmlspecialchars((string)$field['name']) ?></td>
<td><?= htmlspecialchars((string)$field['field_type']) ?></td>
<td><?= (int)$field['sort_order'] ?></td>
<td>
<div class="d-flex gap-2">
<a href="/admin/boards/fields/edit?id=<?= (int)$field['id'] ?>" class="btn btn-sm btn-outline-primary">
Изменить
</a>
<form method="post" action="/admin/boards/fields/delete" onsubmit="return confirm('Удалить поле и все его значения у задач?');" class="d-inline">
<input type="hidden" name="id" value="<?= (int)$field['id'] ?>">
<button type="submit" class="btn btn-sm btn-outline-danger">
Удалить
</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
<script>
document.addEventListener('DOMContentLoaded', function () {
const fieldType = document.getElementById('field_type');
const wrap = document.getElementById('select_options_wrap');
if (fieldType && wrap) {
fieldType.addEventListener('change', function () {
wrap.style.display = this.value === 'select' ? 'block' : 'none';
});
}
});
</script>