app.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <!doctype html>
  2. <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <!-- CSRF Token -->
  7. <meta name="csrf-token" content="{{ csrf_token() }}">
  8. <title>{{ config('app.name', 'Laravel') }}</title>
  9. <!-- favicon -->
  10. <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
  11. <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
  12. <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
  13. <link rel="manifest" href="/site.webmanifest">
  14. <!-- Scripts -->
  15. @vite(['resources/sass/app.scss', 'resources/js/app.js'])
  16. </head>
  17. <body>
  18. @php
  19. $unreadNotificationsCount = auth()->check() ? auth()->user()->unreadUserNotifications()->count() : 0;
  20. @endphp
  21. <div class="alerts">
  22. @if($message = session('success'))
  23. @php
  24. if(!is_array($message)) $message = [$message];
  25. @endphp
  26. @foreach($message as $m)
  27. <div class="main-alert alert alert-success" role="alert">
  28. {{ $m }}
  29. </div>
  30. @endforeach
  31. @endif
  32. @if($message = session('danger'))
  33. @php
  34. if(!is_array($message)) $message = [$message];
  35. @endphp
  36. @foreach($message as $m)
  37. <div class="main-alert alert alert-danger" role="alert">
  38. {{ $m }}
  39. </div>
  40. @endforeach
  41. @endif
  42. @if($message = session('error'))
  43. @php
  44. if(!is_array($message)) $message = [$message];
  45. @endphp
  46. @foreach($message as $m)
  47. <div class="main-alert alert alert-danger" role="alert">
  48. {{ $m }}
  49. </div>
  50. @endforeach
  51. @endif
  52. @if($message = session('warning'))
  53. @php
  54. if(!is_array($message)) $message = [$message];
  55. @endphp
  56. @foreach($message as $m)
  57. <div class="main-alert alert alert-warning" role="alert">
  58. {{ $m }}
  59. </div>
  60. @endforeach
  61. @endif
  62. @if($errors->any())
  63. @foreach($errors->all() as $m)
  64. <div class="main-alert alert alert-danger" role="alert">
  65. {{ $m }}
  66. </div>
  67. @endforeach
  68. @endif
  69. </div>
  70. <div id="app">
  71. <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
  72. <div class="container-fluid">
  73. <a class="navbar-brand" href="{{ url('/') }}">
  74. {{ config('app.name', 'Laravel') }}
  75. </a>
  76. @auth
  77. <a href="{{ route('notifications.index') }}" class="nav-link notification-bell-link d-flex align-items-center ms-auto me-2">
  78. <span class="position-relative d-inline-block">
  79. <i class="bi bi-bell fs-5"></i>
  80. <span id="notification-badge"
  81. data-count="{{ $unreadNotificationsCount }}"
  82. class="notification-badge-dot @if($unreadNotificationsCount < 1) d-none @endif"></span>
  83. </span>
  84. </a>
  85. @endauth
  86. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Открыть меню">
  87. <span class="navbar-toggler-icon"></span>
  88. </button>
  89. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  90. <!-- Left Side Of Navbar -->
  91. <ul class="navbar-nav me-auto">
  92. @include('layouts.menu')
  93. </ul>
  94. <!-- Right Side Of Navbar -->
  95. <ul class="navbar-nav ms-auto">
  96. <!-- Authentication Links -->
  97. @guest
  98. @if (Route::has('login'))
  99. <li class="nav-item">
  100. <a class="nav-link" href="{{ route('login') }}">Вход</a>
  101. </li>
  102. @endif
  103. @if (Route::has('register'))
  104. <li class="nav-item">
  105. <a class="nav-link" href="{{ route('register') }}">Регистрация</a>
  106. </li>
  107. @endif
  108. @else
  109. <li class="nav-item dropdown">
  110. <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  111. {{ year() }}
  112. </a>
  113. <div class="dropdown-menu">
  114. @for($year = (int)date('Y') + 1; $year >= 2020; $year--)
  115. <a class="dropdown-item" href="{{ route('set-year', ['year' => $year]) }}">{{ $year }}</a>
  116. @endfor
  117. </div>
  118. </li>
  119. <li class="nav-item dropdown">
  120. <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  121. {{ Auth::user()->name }}
  122. </a>
  123. <div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
  124. <a class="dropdown-item" href="{{ route('user.profile') }}">Профиль</a>
  125. @if(session()->has('impersonator_id'))
  126. <a class="dropdown-item" href="{{ route('user.impersonate.leave') }}"
  127. onclick="event.preventDefault();
  128. document.getElementById('leave-impersonation-form').submit();">
  129. Выйти из impersonate
  130. </a>
  131. @endif
  132. <a class="dropdown-item" href="{{ route('logout') }}"
  133. onclick="event.preventDefault();
  134. document.getElementById('logout-form').submit();">
  135. Выход
  136. </a>
  137. <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
  138. @csrf
  139. </form>
  140. <form id="leave-impersonation-form" action="{{ route('user.impersonate.leave') }}" method="POST" class="d-none">
  141. @csrf
  142. </form>
  143. </div>
  144. </li>
  145. @endguest
  146. </ul>
  147. </div>
  148. </div>
  149. </nav>
  150. <main class="pt-2 pb-0">
  151. <div class="container-fluid">
  152. @yield('content')
  153. </div>
  154. </main>
  155. </div>
  156. <div id="ws-notification-container" class="ws-notification-container"></div>
  157. @include('partials.customAlert')
  158. <script>
  159. // Глобальные настройки (без jQuery)
  160. var user = {{ auth()->user()?->id ?? 0}};
  161. var socketAddress = '{{ config('app.ws_addr') }}';
  162. var notificationsReadUrlTemplate = '{{ url('notifications/__id__/read') }}';
  163. var customConfirmCallback = null;
  164. localStorage.setItem('user', user);
  165. localStorage.setItem('socketAddress', socketAddress);
  166. // Функция для замены стандартного alert
  167. function customAlert(message) {
  168. document.getElementById('customAlertModalBody').textContent = message;
  169. var myModal = new bootstrap.Modal(document.getElementById('customAlertModal'), {});
  170. myModal.show();
  171. }
  172. function customConfirm(message, onConfirm, title = 'Подтверждение') {
  173. document.getElementById('customConfirmModalLabel').textContent = title;
  174. document.getElementById('customConfirmModalBody').textContent = message;
  175. customConfirmCallback = typeof onConfirm === 'function' ? onConfirm : null;
  176. var confirmModal = bootstrap.Modal.getOrCreateInstance(document.getElementById('customConfirmModal'));
  177. confirmModal.show();
  178. }
  179. document.getElementById('customConfirmModalOk').addEventListener('click', function () {
  180. var modalElement = document.getElementById('customConfirmModal');
  181. var confirmModal = bootstrap.Modal.getInstance(modalElement);
  182. if (confirmModal) {
  183. confirmModal.hide();
  184. }
  185. if (typeof customConfirmCallback === 'function') {
  186. var callback = customConfirmCallback;
  187. customConfirmCallback = null;
  188. callback();
  189. }
  190. });
  191. document.getElementById('customConfirmModal').addEventListener('hidden.bs.modal', function () {
  192. customConfirmCallback = null;
  193. });
  194. // Ждём загрузки jQuery через Vite
  195. function waitForJQuery(callback) {
  196. if (typeof $ !== 'undefined') {
  197. callback();
  198. } else {
  199. setTimeout(function() { waitForJQuery(callback); }, 50);
  200. }
  201. }
  202. waitForJQuery(function() {
  203. $(document).ready(function () {
  204. // Поиск МАФ
  205. var selectMaf = $('#select_maf');
  206. $('#search_maf').on('keyup', function () {
  207. $.get('{{ route('product.search') }}?s=' + $(this).val(),
  208. function (data) {
  209. selectMaf.children().remove()
  210. $.each(data, function (id, name) {
  211. selectMaf.append('<option value=\'' + id + '\'>' + name + '</option>');
  212. });
  213. }
  214. );
  215. });
  216. // Keep token alive
  217. setInterval(keepTokenAlive, 1000 * 60 * 15); // every 15 mins
  218. function keepTokenAlive() {
  219. $.ajax({
  220. url: '/keep-token-alive',
  221. method: 'post',
  222. headers: {
  223. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  224. }
  225. }).then(function () {
  226. console.log('Updated csrf token');
  227. });
  228. }
  229. });
  230. });
  231. </script>
  232. @stack('scripts')
  233. </body>
  234. </html>