app.blade.php 11 KB

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