app.blade.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. <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('warning'))
  43. @php
  44. if(!is_array($message)) $message = [$message];
  45. @endphp
  46. @foreach($message as $m)
  47. <div class="main-alert alert alert-warning" role="alert">
  48. {{ $m }}
  49. </div>
  50. @endforeach
  51. @endif
  52. </div>
  53. <div id="app">
  54. <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
  55. <div class="container-fluid">
  56. <a class="navbar-brand" href="{{ url('/') }}">
  57. {{ config('app.name', 'Laravel') }}
  58. </a>
  59. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Открыть меню">
  60. <span class="navbar-toggler-icon"></span>
  61. </button>
  62. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  63. <!-- Left Side Of Navbar -->
  64. <ul class="navbar-nav me-auto">
  65. @include('layouts.menu')
  66. </ul>
  67. <!-- Right Side Of Navbar -->
  68. <ul class="navbar-nav ms-auto">
  69. <!-- Authentication Links -->
  70. @guest
  71. @if (Route::has('login'))
  72. <li class="nav-item">
  73. <a class="nav-link" href="{{ route('login') }}">Вход</a>
  74. </li>
  75. @endif
  76. @if (Route::has('register'))
  77. <li class="nav-item">
  78. <a class="nav-link" href="{{ route('register') }}">Регистрация</a>
  79. </li>
  80. @endif
  81. @else
  82. <li class="nav-item dropdown">
  83. <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  84. {{ year() }}
  85. </a>
  86. <div class="dropdown-menu">
  87. @for($year = (int)date('Y') + 1; $year >= 2020; $year--)
  88. <a class="dropdown-item" href="{{ route('set-year', ['year' => $year]) }}">{{ $year }}</a>
  89. @endfor
  90. </div>
  91. </li>
  92. <li class="nav-item dropdown">
  93. <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  94. {{ Auth::user()->name }}
  95. </a>
  96. <div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
  97. <a class="dropdown-item" href="{{ route('user.profile') }}">Профиль</a>
  98. @if(session()->has('impersonator_id'))
  99. <a class="dropdown-item" href="{{ route('user.impersonate.leave') }}"
  100. onclick="event.preventDefault();
  101. document.getElementById('leave-impersonation-form').submit();">
  102. Выйти из impersonate
  103. </a>
  104. @endif
  105. <a class="dropdown-item" href="{{ route('logout') }}"
  106. onclick="event.preventDefault();
  107. document.getElementById('logout-form').submit();">
  108. Выход
  109. </a>
  110. <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
  111. @csrf
  112. </form>
  113. <form id="leave-impersonation-form" action="{{ route('user.impersonate.leave') }}" method="POST" class="d-none">
  114. @csrf
  115. </form>
  116. </div>
  117. </li>
  118. @endguest
  119. </ul>
  120. </div>
  121. </div>
  122. </nav>
  123. <main class="py-4">
  124. <div class="container-fluid">
  125. @yield('content')
  126. </div>
  127. </main>
  128. </div>
  129. @include('partials.customAlert')
  130. <script>
  131. // Глобальные настройки (без jQuery)
  132. var user = {{ auth()->user()?->id ?? 0}};
  133. var socketAddress = '{{ config('app.ws_addr') }}';
  134. var customConfirmCallback = null;
  135. localStorage.setItem('user', user);
  136. localStorage.setItem('socketAddress', socketAddress);
  137. // Функция для замены стандартного alert
  138. function customAlert(message) {
  139. document.getElementById('customAlertModalBody').textContent = message;
  140. var myModal = new bootstrap.Modal(document.getElementById('customAlertModal'), {});
  141. myModal.show();
  142. }
  143. function customConfirm(message, onConfirm, title = 'Подтверждение') {
  144. document.getElementById('customConfirmModalLabel').textContent = title;
  145. document.getElementById('customConfirmModalBody').textContent = message;
  146. customConfirmCallback = typeof onConfirm === 'function' ? onConfirm : null;
  147. var confirmModal = bootstrap.Modal.getOrCreateInstance(document.getElementById('customConfirmModal'));
  148. confirmModal.show();
  149. }
  150. document.getElementById('customConfirmModalOk').addEventListener('click', function () {
  151. var modalElement = document.getElementById('customConfirmModal');
  152. var confirmModal = bootstrap.Modal.getInstance(modalElement);
  153. if (confirmModal) {
  154. confirmModal.hide();
  155. }
  156. if (typeof customConfirmCallback === 'function') {
  157. var callback = customConfirmCallback;
  158. customConfirmCallback = null;
  159. callback();
  160. }
  161. });
  162. document.getElementById('customConfirmModal').addEventListener('hidden.bs.modal', function () {
  163. customConfirmCallback = null;
  164. });
  165. // Ждём загрузки jQuery через Vite
  166. function waitForJQuery(callback) {
  167. if (typeof $ !== 'undefined') {
  168. callback();
  169. } else {
  170. setTimeout(function() { waitForJQuery(callback); }, 50);
  171. }
  172. }
  173. waitForJQuery(function() {
  174. $(document).ready(function () {
  175. // Поиск МАФ
  176. var selectMaf = $('#select_maf');
  177. $('#search_maf').on('keyup', function () {
  178. $.get('{{ route('product.search') }}?s=' + $(this).val(),
  179. function (data) {
  180. selectMaf.children().remove()
  181. $.each(data, function (id, name) {
  182. selectMaf.append('<option value=\'' + id + '\'>' + name + '</option>');
  183. });
  184. }
  185. );
  186. });
  187. // Keep token alive
  188. setInterval(keepTokenAlive, 1000 * 60 * 15); // every 15 mins
  189. function keepTokenAlive() {
  190. $.ajax({
  191. url: '/keep-token-alive',
  192. method: 'post',
  193. headers: {
  194. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  195. }
  196. }).then(function () {
  197. console.log('Updated csrf token');
  198. });
  199. }
  200. });
  201. });
  202. </script>
  203. @stack('scripts')
  204. </body>
  205. </html>