Feat: CRUD групп с типами (организация/общие)

 create.blade.php — форма создания с выбором типа группы
 store метод — сохранение группы
 index.blade.php — кнопка создать, фильтр по пользователю
 edit метод — фильтр пользователей по организации
 Ссылка Группы в сайдбаре для Admin/Manager
 Полные маршруты для groups

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad
2026-03-30 10:21:17 +08:00
co-authored by Qwen-Coder
parent d27b631c8f
commit 6599b8d5b6
5 changed files with 142 additions and 69 deletions
+64 -63
View File
@@ -1,91 +1,92 @@
@extends('layouts.app')
@section('title', 'Добавить группу')
@section('title', 'Создать группу')
@section('content')
<div class="container-fluid">
<div class="row">
<nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
<div class="position-sticky pt-3">
@include('partials._sidebar')
</div>
</nav>
<nav class="col-md-3 col-lg-2 d-md-block sidebar"><div class="position-sticky pt-3">@include('partials._sidebar')</div></nav>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Добавить группу</h1>
<a href="{{ route('admin.organizations.show', $organization) }}" class="btn btn-secondary btn-sm">
<i class="bi bi-arrow-left"></i> Назад
</a>
<div class="d-flex justify-content-between align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Создать группу</h1>
<a href="{{ route('admin.groups.index') }}" class="btn btn-secondary btn-sm">Назад</a>
</div>
@if ($errors->any())
<div class="alert alert-danger">
<ul class="mb-0">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('admin.organizations.groups.store', $organization) }}" method="POST">
<form action="{{ route('admin.groups.store') }}" method="POST">
@csrf
<div class="row">
<div class="col-md-8">
<div class="card shadow-sm mb-4">
<div class="col-md-8 mb-4">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white"><h5 class="mb-0">Основная информация</h5></div>
<div class="card-body">
<h5 class="card-title mb-3">Основная информация</h5>
<div class="mb-3">
<label class="form-label">Тип группы *</label>
<select name="group_type" id="groupType" class="form-select @error('group_type') is-invalid @enderror" required onchange="toggleOrganizationField()">
<option value="">Выберите тип</option>
<option value="organization" {{ old('group_type') == 'organization' ? 'selected' : '' }}>Группа организации</option>
<option value="general" {{ old('group_type') == 'general' ? 'selected' : '' }}>Общая группа</option>
</select>
<small class="text-muted">Группа организации только пользователи этой организации. Общая любые пользователи.</small>
@error('group_type')<div class="invalid-feedback">{{ $message }}</div>@enderror
</div>
<div class="mb-3" id="organizationField" style="display:none;">
<label class="form-label">Организация *</label>
<select name="organization_id" class="form-select @error('organization_id') is-invalid @enderror">
<option value="">Выберите организацию</option>
@foreach($organizations as $id => $name)
<option value="{{ $id }}" {{ old('organization_id') == $id ? 'selected' : '' }}>{{ $name }}</option>
@endforeach
</select>
@error('organization_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
</div>
<div class="mb-3">
<label for="name" class="form-label">Название группы <span class="text-danger">*</span></label>
<input type="text" class="form-control @error('name') is-invalid @enderror"
id="name" name="name" value="{{ old('name') }}" required autofocus>
@error('name')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
<label class="form-label">Название группы *</label>
<input type="text" name="name" class="form-control @error('name') is-invalid @enderror" value="{{ old('name') }}" required>
@error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
</div>
<div class="mb-3">
<label for="description" class="form-label">Описание</label>
<textarea class="form-control @error('description') is-invalid @enderror"
id="description" name="description" rows="3">{{ old('description') }}</textarea>
@error('description')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
<label class="form-label">Описание</label>
<textarea name="description" class="form-control" rows="3">{{ old('description') }}</textarea>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="is_active" name="is_active" value="1" {{ old('is_active', true) ? 'checked' : '' }}>
<label class="form-check-label" for="is_active">Активна</label>
<div class="form-check mb-3">
<input type="checkbox" name="is_active" value="1" class="form-check-input" {{ old('is_active', true) ? 'checked' : '' }}>
<label class="form-check-label">Активна</label>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm mb-4">
<div class="col-md-4 mb-4">
<div class="card shadow-sm">
<div class="card-header bg-info text-white"><h5 class="mb-0">Подсказка</h5></div>
<div class="card-body">
<h5 class="card-title mb-3">Организация</h5>
<p class="text-muted mb-0">{{ $organization->name }}</p>
@if($organization->inn)
<p class="text-muted small">ИНН: {{ $organization->inn }}</p>
@endif
<h6>Группа организации</h6>
<p class="small text-muted">Привязана к конкретной организации. Можно добавлять только пользователей этой организации.</p>
<hr>
<h6>Общая группа</h6>
<p class="small text-muted">Не привязана к организации. Можно добавлять любых пользователей системы.</p>
</div>
</div>
</div>
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary">
<i class="bi bi-check-lg"></i> Создать группу
</button>
<a href="{{ route('admin.organizations.show', $organization) }}" class="btn btn-secondary">
<i class="bi bi-x-lg"></i> Отмена
</a>
</div>
<button type="submit" class="btn btn-primary">Создать группу</button>
<a href="{{ route('admin.groups.index') }}" class="btn btn-secondary">Отмена</a>
</form>
</main>
</div>
</div>
<script>
function toggleOrganizationField() {
const type = document.getElementById('groupType').value;
document.getElementById('organizationField').style.display = (type === 'organization') ? 'block' : 'none';
}
document.addEventListener('DOMContentLoaded', function() {
toggleOrganizationField();
});
</script>
@endsection