Commit 90302d36633b80a73985b19c1a677ce5552f2795

Authored by Андрей Ларионов
1 parent dd87a3ce43

Блоки меню для футера и шапки

Showing 9 changed files with 188 additions and 18 deletions Side-by-side Diff

app/Http/Controllers/Admin/CompanyController.php
... ... @@ -43,19 +43,62 @@ class CompanyController extends Controller
43 43 }
44 44 }
45 45  
  46 + ////////////////////////////////////////////////////////////////////////////////
46 47 // кабинет - редактор шапки-футера сайта
47 48 public function editblocks(Request $request) {
48 49 if ($request->ajax()) {
49 50 $header_footer = header_footer::where('header', $request->header)->OrderBy('sort')->OrderBy('name')->paginate(15);
50 51 $list_menu = header_footer::where('header', $request->header)->OrderBy('name')->get();
51   - return view('admin.editbloks.index_ajax', compact('header_footer'));
  52 + return view('admin.editbloks.index_ajax', compact('header_footer', 'list_menu'));
52 53 } else {
53 54 $header_footer = header_footer::where('header', '1')->OrderBy('sort')->OrderBy('name')->paginate(15);
54 55 $list_menu = header_footer::where('header', '1')->OrderBy('name')->get();
55   - return view('admin.editbloks.index', compact('header_footer'));
  56 + return view('admin.editbloks.index', compact('header_footer', 'list_menu'));
56 57 }
57 58 }
58 59  
  60 + public function editblock_add() {
  61 + $items = header_footer::query()->OrderBy('name')->get();
  62 + return view('admin.editbloks.add', compact('items'));
  63 + }
  64 +
  65 + public function editblock_store(Request $request) {
  66 + header_footer::create($request->all());
  67 + return redirect()->route('admin.edit-blocks');
  68 + }
  69 +
  70 + public function editblock_ajax(Request $request) {
  71 + if ($request->ajax()) {
  72 + $hf = header_footer::find($request->id);
  73 + $filter = $request->header;
  74 + unset($request->id);
  75 + unset($request->header);
  76 + $hf->update($request->all());
  77 +
  78 + $header_footer = header_footer::where('header', $filter)->OrderBy('sort')->OrderBy('name')->paginate(15);
  79 + $list_menu = header_footer::where('header', $filter)->OrderBy('name')->get();
  80 + return view('admin.editbloks.index_ajax', compact('header_footer', 'list_menu'));
  81 + } else {
  82 + return "Ошибка!";
  83 + }
  84 + }
  85 +
  86 + public function editblock_edit(header_footer $block) {
  87 + $items = header_footer::query()->OrderBy('name')->get();
  88 + return view('admin.editbloks.edit', compact('block', 'items'));
  89 + }
  90 +
  91 + public function editblock_update(Request $request, header_footer $block) {
  92 + $block->update($request->all());
  93 + return redirect()->route('admin.edit-blocks');
  94 + }
  95 +
  96 + public function editblock_destroy(header_footer $block) {
  97 + $block->delete();
  98 + return redirect()->route('admin.edit-blocks');
  99 + }
  100 + /////////////////////////////////////////////////////////
  101 +
59 102 // кабинет - редактор работодатели на главной
60 103 public function employers_main(Request $request) {
61 104 if ($request->ajax()) {
app/Models/header_footer.php
... ... @@ -8,4 +8,13 @@ use Illuminate\Database\Eloquent\Model;
8 8 class header_footer extends Model
9 9 {
10 10 use HasFactory;
  11 +
  12 + protected $fillable = [
  13 + 'name',
  14 + 'link',
  15 + 'code_id',
  16 + 'category',
  17 + 'header',
  18 + 'sort'
  19 + ];
11 20 }
resources/views/admin/editbloks/add.blade.php
... ... @@ -0,0 +1,7 @@
  1 +@extends('layout.admin', ['title' => 'Админка - Добавление элемента шапки-футера'])
  2 +
  3 +@section('content')
  4 + <form method="POST" action="{{ route('admin.add-block-store') }}">
  5 + @include('admin.editbloks.form')
  6 + </form>
  7 +@endsection
resources/views/admin/editbloks/edit.blade.php
... ... @@ -0,0 +1,7 @@
  1 +@extends('layout.admin', ['title' => 'Админка - Редактирование элемента шапки-футера'])
  2 +
  3 +@section('content')
  4 + <form method="POST" action="{{ route('admin.update-block', ['block' => $block->id]) }}">
  5 + @include('admin.editbloks.form')
  6 + </form>
  7 +@endsection
resources/views/admin/editbloks/form.blade.php
... ... @@ -0,0 +1,61 @@
  1 +@csrf
  2 +@isset($block)
  3 + @method('PUT')
  4 +@endisset
  5 +
  6 +<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
  7 + <label class="block text-sm">
  8 + <span class="text-gray-700 dark:text-gray-400">Имя</span>
  9 + <input name="name" id="name"
  10 + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
  11 + placeholder="Название пункта" value="{{ old('name') ?? $block->name ?? '' }}"
  12 + />
  13 + @error('name')
  14 + <span class="text-xs text-red-600 dark:text-red-400">
  15 + {{ $message }}
  16 + </span>
  17 + @enderror
  18 + </label><br>
  19 +
  20 + <label class="block text-sm">
  21 + <span class="text-gray-700 dark:text-gray-400">Родитель</span>
  22 + @php
  23 + $parent_id = old('code_id') ?? $block->code_id ?? 0;
  24 + @endphp
  25 + <select name="code_id" class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray"
  26 + title="Родитель">
  27 + <option value="0">Без родителя</option>
  28 + @include('admin.editbloks.parent_id', ['level' => -1, 'parent' => 0])
  29 + </select>
  30 + </label><br>
  31 +
  32 + <label class="block text-sm">
  33 + <span class="text-gray-700 dark:text-gray-400">Расположение</span>
  34 + <select name="header" class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray"
  35 + title="Расположение">
  36 + <option value="1" @isset($block) @if($block->header == 1) selected @endif @endisset>Шапка</option>
  37 + <option value="0" @isset($block) @if($block->header == 0) selected @endif @endisset>Футер</option>
  38 + </select>
  39 + </label><br>
  40 +
  41 + <label class="block text-sm">
  42 + <span class="text-gray-700 dark:text-gray-400">Ссылка</span>
  43 + <input name="link" id="link"
  44 + class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
  45 + placeholder="Ссылка" value="{{ old('link') ?? $block->link ?? '' }}"
  46 + />
  47 + @error('link')
  48 + <span class="text-xs text-red-600 dark:text-red-400">
  49 + {{ $message }}
  50 + </span>
  51 + @enderror
  52 + </label><br>
  53 +
  54 + <div class="flex flex-col flex-wrap mb-4 space-y-4 md:flex-row md:items-end md:space-x-4">
  55 + <div>
  56 + <button type="submit" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
  57 + Сохранить
  58 + </button>
  59 + </div>
  60 + </div>
  61 +</div>
resources/views/admin/editbloks/index.blade.php
... ... @@ -3,16 +3,45 @@
3 3 @section('script')
4 4 <script>
5 5 $(document).ready(function() {
6   - $(document).on('chance', '#header', function () {
  6 + $(document).on('change', '#header', function () {
7 7 var this_ = $(this);
8 8 var value = this_.val();
9 9 var ajax_block = $('#ajax_block');
  10 + console.log('Смена фильтра таблицы меню ');
10 11  
11 12 $.ajax({
12 13 type: "GET",
13 14 url: "{{ url()->full()}}",
14 15 data: "header=" + value,
15 16 success: function (data) {
  17 + console.log('Успешно!');
  18 + ajax_block.html(data);
  19 + },
  20 + headers: {
  21 + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  22 + },
  23 + error: function (data) {
  24 + console.log('Error: ' + data);
  25 + }
  26 + });
  27 + });
  28 +
  29 + $(document).on('change', '.check_js', function () {
  30 + var this_ = $(this);
  31 + var value = this_.val();
  32 + var id_rec = this_.attr('data-fid');
  33 + var field = this_.attr('data-field');
  34 + var ajax_block = $('#ajax_block');
  35 + var filter = $('#header');
  36 + var filter_val = filter.val();
  37 +
  38 + console.log("id=" + id_rec + "&" + field + "=" + value + "&header=" + filter_val);
  39 +
  40 + $.ajax({
  41 + type: "GET",
  42 + url: "{{ route('admin.ajax.block')}}",
  43 + data: "id=" + id_rec + "&" + field + "=" + value + "&header=" + filter_val,
  44 + success: function (data) {
16 45 console.log('Обновление таблицы меню ');
17 46 ajax_block.html(data);
18 47 },
... ... @@ -60,10 +89,10 @@
60 89  
61 90 @section('content')
62 91  
63   - <a href="{{ route('admin.add-seo') }}" style="width: 145px" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
  92 + <a href="{{ route('admin.add-block') }}" style="width: 145px" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
64 93 Добавить опцию
65 94 </a>
66   - <select name="header" id="header" class="form-control">
  95 + <select name="header" id="header" class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray">
67 96 <option value="1">Шапка</option>
68 97 <option value="0">Футер</option>
69 98 </select>
... ... @@ -99,7 +128,7 @@
99 128 {{$page->link}}
100 129 </td>
101 130 <td class="px-4 py-3">
102   - <select name="code_id{{$page->code_id}}" id="{{$page->id}}" data-field="code_id" class="form-control check_js">
  131 + <select name="code_id{{$page->code_id}}" id="code_id{{$page->id}}" data-fid="{{$page->id}}" data-field="code_id" class="form-control check_js">
103 132 <option value="0"
104 133 @if($page->code_id == 0)
105 134 selected
... ... @@ -108,7 +137,7 @@
108 137 @isset($list_menu)
109 138 @foreach($list_menu as $menu)
110 139 <option value="{{ $menu->id }}"
111   - @if($menu->id == $page->code_id)
  140 + @if($menu->id == $page->code_id)
112 141 selected
113 142 @endif
114 143 >{{ $menu->name }} ({{ $menu->id }})</option>
... ... @@ -117,7 +146,7 @@
117 146 </select>
118 147 </td>
119 148 <td class="px-4 py-3 text-sm">
120   - <select name="sort{{$page->id}}" id="{{$page->id}}" data-field="sort" class="form-control check_js">
  149 + <select name="sort{{$page->id}}" id="sort{{$page->id}}" data-fid="{{$page->id}}" data-field="sort" class="form-control check_js">
121 150 <option value="100" @if($page->sort == '100') selected @endif>100</option>
122 151 <option value="110" @if($page->sort == '110') selected @endif>110</option>
123 152 <option value="120" @if($page->sort == '120') selected @endif>120</option>
... ... @@ -136,14 +165,12 @@
136 165 {{$page->created_at}}
137 166 </td>
138 167 <td class="px-4 py-3 text-sm_">
139   - <? /*?>
140   - <form action="{{ route('admin.delete-seo', ['page' => $page->id]) }}" method="POST">
141   - <a href="{{ route('admin.edit-seo', ['page' => $page->id]) }}">Изменить</a> |
  168 + <form action="{{ route('admin.delete-block', ['block' => $page->id]) }}" method="POST">
  169 + <a href="{{ route('admin.edit-block', ['block' => $page->id]) }}">Изменить</a> |
142 170 @csrf
143 171 @method('DELETE')
144 172 <input class="btn btn-danger" type="submit" value="Удалить"/>
145 173 </form>
146   - <? */ ?>
147 174 </td>
148 175 </tr>
149 176 @endforeach
resources/views/admin/editbloks/index_ajax.blade.php
... ... @@ -26,7 +26,7 @@
26 26 {{$page->link}}
27 27 </td>
28 28 <td class="px-4 py-3">
29   - <select name="code_id{{$page->code_id}}" id="{{$page->id}}" data-field="code_id" class="form-control check_js">
  29 + <select name="code_id{{$page->code_id}}" id="code_id{{$page->id}}" data-fid="{{$page->id}}" data-field="code_id" class="form-control check_js">
30 30 <option value="0"
31 31 @if($page->code_id == 0)
32 32 selected
... ... @@ -44,7 +44,7 @@
44 44 </select>
45 45 </td>
46 46 <td class="px-4 py-3 text-sm">
47   - <select name="sort{{$page->id}}" id="{{$page->id}}" data-field="sort" class="form-control check_js">
  47 + <select name="sort{{$page->id}}" id="sort{{$page->id}}" data-fid="{{$page->id}}" data-field="sort" class="form-control check_js">
48 48 <option value="100" @if($page->sort == '100') selected @endif>100</option>
49 49 <option value="110" @if($page->sort == '110') selected @endif>110</option>
50 50 <option value="120" @if($page->sort == '120') selected @endif>120</option>
... ... @@ -63,14 +63,12 @@
63 63 {{$page->created_at}}
64 64 </td>
65 65 <td class="px-4 py-3 text-sm_">
66   - <? /*?>
67   - <form action="{{ route('admin.delete-seo', ['page' => $page->id]) }}" method="POST">
68   - <a href="{{ route('admin.edit-seo', ['page' => $page->id]) }}">Изменить</a> |
  66 + <form action="{{ route('admin.delete-block', ['block' => $page->id]) }}" method="POST">
  67 + <a href="{{ route('admin.edit-block', ['block' => $page->id]) }}">Изменить</a> |
69 68 @csrf
70 69 @method('DELETE')
71 70 <input class="btn btn-danger" type="submit" value="Удалить"/>
72 71 </form>
73   - <? */ ?>
74 72 </td>
75 73 </tr>
76 74 @endforeach
resources/views/admin/editbloks/parent_id.blade.php
... ... @@ -0,0 +1,10 @@
  1 +@if ($items->where('code_id', $parent)->count())
  2 + @php $level++ @endphp
  3 + @foreach ($items->where('code_id', $parent) as $item)
  4 + <option value="{{ $item->id }}" @if ($item->id == $parent_id) selected @endif>
  5 + @if ($level) {!! str_repeat('&nbsp;&nbsp;&nbsp;', $level) !!} @endif
  6 + {{ $item->name }} ({{ $item->id }})
  7 + </option>
  8 + @include('admin.editbloks.parent_id', ['level' => $level, 'parent' => $item->id])
  9 + @endforeach
  10 +@endif
... ... @@ -171,8 +171,16 @@ Route::group([
171 171 return view('admin.editor.index');
172 172 })->name('editor-site');
173 173  
  174 +
174 175 // кабинет - редактор шапки-футера сайта
175 176 Route::get('edit-blocks', [CompanyController::class, 'editblocks'])->name('edit-blocks');
  177 + Route::get('edit-bloks/add', [CompanyController::class, 'editblock_add'])->name('add-block');
  178 + Route::post('edit-bloks/add', [CompanyController::class, 'editblock_store'])->name('add-block-store');
  179 + Route::get('edit-bloks/ajax', [CompanyController::class, 'editblock_ajax'])->name('ajax.block');
  180 + Route::get('edit-bloks/edit/{block}', [CompanyController::class, 'editblock_edit'])->name('edit-block');
  181 + Route::put('edit-bloks/edit/{block}', [CompanyController::class, 'editblock_update'])->name('update-block');
  182 + Route::delete('edit-bloks/delete/{block}', [CompanyController::class, 'editblock_destroy'])->name('delete-block');
  183 +
176 184  
177 185 // кабинет - редактор должности на главной
178 186 Route::get('job-titles-main', [CompanyController::class, 'job_titles_main'])->name('job-titles-main');