table.blade.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <div class="table-responsive js-main-table-scroll">
  2. <div class="table-buttons py-2 bg-primary rounded-start d-flex flex-column ">
  3. <button type="button" class="btn btn-sm text-white" data-bs-toggle="modal"
  4. data-bs-target="#table_{{ $id }}_modal_search">
  5. <i class="bi bi-search-heart @if(request()->has('s')) text-danger @endif"></i>
  6. </button>
  7. <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
  8. data-bs-target="#table_{{ $id }}_modal_filters">
  9. <i class="bi bi-funnel-fill @if(request()->has('filters')) text-danger @endif"></i>
  10. </button>
  11. <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
  12. data-bs-target="#table_{{ $id }}_modal_settings">
  13. <i class="bi bi-gear-fill"></i>
  14. </button>
  15. </div>
  16. <table class="table table-interactive table-initial-hidden" id="tbl" data-table-name="{{ $id }}">
  17. <thead class="table-head-shadow">
  18. <tr>
  19. @foreach($header as $headerName => $headerTitle)
  20. <th scope="col" class="bg-primary-subtle column_{{ $headerName }}">
  21. <div class="d-flex align-items-center justify-content-between">
  22. <div class="@if($headerName !== 'actions') cursor-pointer sort-by-column @endif" data-name="{{ $headerName }}">
  23. {{ $headerTitle }}
  24. </div>
  25. <div class="text-center mx-1 @if($headerName !== 'actions') cursor-pointer @endif" data-name="{{ $headerName }}">
  26. @if($headerName !== 'actions' && ($headerName== $sortBy))
  27. @if($orderBy === 'asc')
  28. <i class="bi bi-arrow-down-square-fill text-primary"></i>
  29. @else
  30. <i class="bi bi-arrow-up-square-fill text-primary"></i>
  31. @endif
  32. @endif
  33. </div>
  34. @if(($enableColumnFilters ?? true) && $headerName !== 'image' && $headerName !== 'actions')
  35. @php
  36. $type = null;
  37. $data = (array_merge($filters, $ranges, $dates))[$headerName] ?? null;
  38. if (isset($filters[$headerName])) {
  39. $type = 'filters';
  40. } elseif (isset($ranges[$headerName])) {
  41. // Для dropdown фильтров вместо диапазона используем список всех вариантов
  42. $type = 'filters';
  43. } elseif (isset($dates[$headerName])) {
  44. $type = 'dates';
  45. }
  46. @endphp
  47. <div class="text-end cursor-pointer dropdown" data-bs-auto-close="outside" aria-expanded="false">
  48. <i
  49. data-bs-auto-close="outside"
  50. aria-expanded="false"
  51. data-bs-toggle="dropdown"
  52. class="dropdown-toggle bi
  53. @if(isset(request()->filters[$headerName]) ||
  54. isset(request()->filters[str_replace('_txt', '', $headerName) . '_from']) ||
  55. isset(request()->filters[str_replace('_txt', '', $headerName) . '_to'])
  56. )
  57. bi-funnel-fill text-danger
  58. @else
  59. bi-funnel
  60. @endif
  61. " id="{{$headerName}}"></i>
  62. @include('partials.newFilterElement', ['id' => $headerName, 'data' => $data, 'type' => $type, 'table' => $id, 'isSort' => $headerName == $sortBy, '$orderBy' => $orderBy])
  63. </div>
  64. @endif
  65. </div>
  66. </th>
  67. @endforeach
  68. </tr>
  69. </thead>
  70. <tbody>
  71. @foreach($strings as $string)
  72. @php
  73. $rowId = $string->id ?? null;
  74. $rowAnchor = $rowId ? 'row-' . $rowId : null;
  75. $rowHref = null;
  76. if (isset($routeName) && $rowId) {
  77. $rowHref = route($routeName, [$string->id, 'previous_url' => request()->fullUrl() . '#' . $rowAnchor]);
  78. }
  79. @endphp
  80. <tr
  81. @if($rowAnchor) id="{{ $rowAnchor }}" data-row-id="{{ $rowId }}" @endif
  82. @if($rowHref) data-row-href="{{ $rowHref }}" @endif
  83. @if($id === 'reclamations') data-open-target="_blank" @endif
  84. >
  85. @foreach($header as $headerName => $headerTitle)
  86. <td class="column_{{$headerName}}"
  87. >
  88. @if(str_contains($headerName, '-'))
  89. @php
  90. list($rel, $field) = explode('-', $headerName);
  91. @endphp
  92. @if(isset($string->$rel->$field))
  93. @if(str_ends_with($field, '_id'))
  94. @php
  95. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $field));
  96. @endphp
  97. {!! $string->$rel->$relation?->name; !!}
  98. @else
  99. @if(str_contains($field, 'image') && $string->$rel->$field)
  100. <a href="{{ $string->$rel->$field }}" data-toggle="lightbox"
  101. data-gallery="photos" data-size="fullscreen">
  102. <img src="{{ $string->$rel->$field }}" alt="" class="img-thumbnail maf-img">
  103. </a>
  104. @else
  105. {!! $string->$rel->$field !!}
  106. @endif
  107. @endif
  108. @else
  109. <ul class="small mb-0 list-group list-group-flush bg-secondary">
  110. @foreach($string->$rel ?? [] as $item)
  111. <li class="list-group-item py-0 bg-body-secondary">
  112. {!! $item->$field !!}
  113. </li>
  114. @endforeach
  115. </ul>
  116. @endif
  117. @elseif(str_ends_with($headerName, '_id'))
  118. @php
  119. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $headerName));
  120. @endphp
  121. @if($headerName == 'order_status_id')
  122. <div class="badge fs-5 text-bg-{{ App\Models\Order::STATUS_COLOR[$string->order_status_id] }}">{{ $string->$relation?->name }}</div>
  123. @else
  124. {!! $string->$relation?->name; !!}
  125. @endif
  126. @elseif(str_ends_with($headerName, '_date') && ($string->$headerName))
  127. {{ \App\Helpers\DateHelper::getHumanDate($string->$headerName, true) }}
  128. @elseif(str_contains($headerName, 'image') && $string->$headerName)
  129. <a href="{{ $string->$headerName }}" data-toggle="lightbox" data-gallery="photos"
  130. data-size="fullscreen">
  131. <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail maf-img">
  132. </a>
  133. @elseif(str_contains($headerName, 'order_status_name'))
  134. <select name="order_status_name" data-order-id="{{ $string->id }}" @disabled(!hasRole('admin,manager')) class="change-order-status form-control form-control-sm" >
  135. @foreach($statuses as $statusId => $statusName)
  136. <option value="{{ $statusId }}" @selected($statusName == $string->$headerName)>{{ $statusName }}</option>
  137. @endforeach
  138. </select>
  139. @elseif($id === 'reclamations' && $headerName === 'status_name')
  140. <select name="status_id"
  141. data-reclamation-id="{{ $string->id }}"
  142. data-url="{{ route('reclamations.update-status', $string->id) }}"
  143. @disabled(!hasRole('admin,manager'))
  144. class="change-reclamation-status form-control form-control-sm">
  145. @foreach($statuses as $statusId => $statusName)
  146. <option value="{{ $statusId }}" @selected($statusId == $string->status_id)>{{ $statusName }}</option>
  147. @endforeach
  148. </select>
  149. @elseif($headerName === 'tsn_number' && $string->$headerName)
  150. <span data-bs-toggle="tooltip"
  151. data-bs-placement="top"
  152. title="{{ $string->tsn_number_description ?? 'Нет расшифровки' }}"
  153. class="tooltip-help">
  154. {{ $string->$headerName }}
  155. </span>
  156. @elseif($headerName === 'pricing_code' && $string->$headerName)
  157. <span data-bs-toggle="tooltip"
  158. data-bs-placement="top"
  159. title="{{ $string->pricing_code_description ?? 'Нет расшифровки' }}"
  160. class="tooltip-help">
  161. {{ $string->$headerName }}
  162. </span>
  163. @elseif($headerName === 'pricing_codes_list' && $string->pricingCodes->count() > 0)
  164. @foreach($string->pricingCodes as $pricingCode)
  165. <span data-bs-toggle="tooltip"
  166. data-bs-placement="top"
  167. title="{{ $pricingCode->description ?? 'Нет расшифровки' }}"
  168. class="tooltip-help">
  169. {{ $pricingCode->code }}
  170. </span>@if(!$loop->last)<br>@endif
  171. @endforeach
  172. @elseif($id === 'pricing_codes' && $headerName === 'type')
  173. @if($string->type === 'tsn_number')
  174. <span class="badge bg-info">№ по ТСН</span>
  175. @else
  176. <span class="badge bg-primary">Шифр расценки</span>
  177. @endif
  178. @elseif($id === 'pricing_codes' && $headerName === 'description')
  179. <div class="d-flex justify-content-between align-items-center">
  180. <span class="description-text-{{ $string->id }}">{{ $string->description }}</span>
  181. <button type="button" class="btn btn-sm btn-link edit-description"
  182. data-id="{{ $string->id }}"
  183. data-description="{{ $string->description }}">
  184. <i class="bi bi-pencil"></i>
  185. </button>
  186. </div>
  187. <form action="{{ route('pricing_codes.update', $string) }}" method="POST" class="edit-form-{{ $string->id }} is-hidden">
  188. @csrf
  189. @method('PUT')
  190. <div class="input-group input-group-sm">
  191. <input type="text" name="description" class="form-control" value="{{ $string->description }}">
  192. <button type="submit" class="btn btn-success">Сохранить</button>
  193. <button type="button" class="btn btn-secondary cancel-edit" data-id="{{ $string->id }}">Отмена</button>
  194. </div>
  195. </form>
  196. @elseif($id === 'pricing_codes' && $headerName === 'actions')
  197. <form action="{{ route('pricing_codes.destroy', $string) }}" method="POST" class="d-inline js-confirm-submit"
  198. data-confirm-message="Удалить код {{ $string->code }}?">
  199. @csrf
  200. @method('DELETE')
  201. <button type="submit" class="btn btn-sm btn-danger">Удалить</button>
  202. </form>
  203. @elseif($headerName === 'actions' && isset($routeName) && isset($string->id))
  204. <a href="{{ route($routeName, $string->id) }}" class="btn btn-sm btn-outline-primary">
  205. Редактировать
  206. </a>
  207. @else
  208. <p title="{!! $string->$headerName !!}">
  209. {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
  210. </p>
  211. @endif
  212. </td>
  213. @endforeach
  214. </tr>
  215. @endforeach
  216. </tbody>
  217. </table>
  218. </div>
  219. <!-- Модальное окно настроек таблицы -->
  220. <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
  221. aria-hidden="true">
  222. <div class="modal-dialog modal-fullscreen-sm-down">
  223. <div class="modal-content">
  224. <div class="modal-header">
  225. <h1 class="modal-title fs-5" id="exampleModalLabel">Выбор отображаемых колонок</h1>
  226. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  227. </div>
  228. <div class="modal-body">
  229. @foreach($header as $headerName => $headerTitle)
  230. <div>
  231. <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
  232. class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
  233. </label>
  234. </div>
  235. @endforeach
  236. </div>
  237. <div class="modal-footer">
  238. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. <!-- Модальное окно фильтров -->
  244. <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
  245. aria-hidden="true">
  246. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  247. <div class="modal-content">
  248. <div class="modal-header">
  249. <h1 class="modal-title fs-5" id="exampleModalLabel">Фильтры по колонкам таблицы</h1>
  250. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  251. </div>
  252. <div class="modal-body">
  253. <form class="filters">
  254. @if(isset($filters) && is_array($filters))
  255. @foreach($filters as $filterName => $filter)
  256. @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
  257. @include('partials.select', [
  258. 'name' => 'filters[' . $filterName . ']',
  259. 'title' => $filter['title'],
  260. 'options' => $filter['values'],
  261. 'value' => request()->filters[$filterName] ?? '',
  262. ])
  263. @endforeach
  264. @endif
  265. @if(isset($ranges) && is_array($ranges))
  266. @foreach($ranges as $rangeName => $range)
  267. @include('partials.input', [
  268. 'name' => 'filters[' . $rangeName . '_from]',
  269. 'type' => 'number',
  270. 'title' => $range['title'] . ' с:',
  271. 'min' => $range['min'],
  272. 'max' => $range['max'],
  273. 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
  274. ])
  275. @include('partials.input', [
  276. 'name' => 'filters[' . $rangeName . '_to]',
  277. 'type' => 'number',
  278. 'title' => ' по:',
  279. 'min' => $range['min'],
  280. 'max' => $range['max'],
  281. 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
  282. ])
  283. @endforeach
  284. @endif
  285. @if(isset($dates) && is_array($dates))
  286. @foreach($dates as $rangeName => $range)
  287. @include('partials.input', [
  288. 'name' => 'filters[' . $rangeName . '_from]',
  289. 'type' => 'date',
  290. 'title' => $range['title'] . ' с:',
  291. 'min' => $range['min'],
  292. 'max' => $range['max'],
  293. 'value' => request()->filters[$rangeName . '_from'] ?? '',
  294. ])
  295. @include('partials.input', [
  296. 'name' => 'filters[' . $rangeName . '_to]',
  297. 'type' => 'date',
  298. 'title' => $range['title'] . ' по:',
  299. 'min' => $range['min'],
  300. 'max' => $range['max'],
  301. 'value' => request()->filters[$rangeName . '_to'] ?? '',
  302. ])
  303. @endforeach
  304. @endif
  305. </form>
  306. </div>
  307. <div class="modal-footer">
  308. <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
  309. <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
  310. </button>
  311. </div>
  312. </div>
  313. </div>
  314. </div>
  315. <!-- Модальное окно поиска -->
  316. <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
  317. aria-hidden="true">
  318. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  319. <div class="modal-content">
  320. <div class="modal-header">
  321. <h1 class="modal-title fs-5" id="exampleModalLabel">Поиск</h1>
  322. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  323. </div>
  324. <div class="modal-body">
  325. <div>
  326. Поиск ведётся по следующим колонкам:
  327. <span class="fst-italic">
  328. @foreach($searchFields as $searchField)
  329. {{ $header[$searchField] }}
  330. @if(!$loop->last)
  331. ,
  332. @endif
  333. @endforeach
  334. </span>
  335. </div>
  336. <form class="search-form">
  337. @include('partials.input', [
  338. 'name' => 's',
  339. 'title' => 'Поиск',
  340. 'placeholder' => 'что ищем?',
  341. 'value' => request()->s ?? '',
  342. ])
  343. </form>
  344. </div>
  345. <div class="modal-footer">
  346. <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
  347. <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
  348. </button>
  349. </div>
  350. </div>
  351. </div>
  352. </div>
  353. @push('scripts')
  354. <script type="module">
  355. // Ждём загрузки jQuery через Vite
  356. function waitForJQuery(callback) {
  357. if (typeof window.$ !== 'undefined') {
  358. callback();
  359. } else {
  360. setTimeout(() => waitForJQuery(callback), 50);
  361. }
  362. }
  363. waitForJQuery(function () {
  364. // on page load set column visible
  365. let tbl = $('#tbl');
  366. let tableName = tbl.attr('data-table-name');
  367. let tables = JSON.parse(localStorage.getItem('table_' + tableName));
  368. // on first load create tables object
  369. if (!tables) {
  370. tables = {};
  371. }
  372. // hide disabled columns
  373. $.each(tables, function (colName, colStatus) {
  374. if (!colStatus) {
  375. $('.checkbox-' + colName).attr('checked', false);
  376. $('.column_' + colName).hide();
  377. }
  378. });
  379. // highlight search text
  380. let searchText = $('.search-form input').val();
  381. if (searchText !== '') {
  382. let innerHTML = tbl.html();
  383. let index = innerHTML.indexOf(searchText);
  384. if (index >= 0) {
  385. innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
  386. tbl.html(innerHTML);
  387. }
  388. }
  389. $('.table').fadeIn();
  390. function isRowActionTarget(target) {
  391. return $(target).closest('a, button, input, select, textarea, label, .dropdown, [data-bs-toggle], [data-no-row-select]').length > 0;
  392. }
  393. function selectRow($row, updateHash = true) {
  394. if (!$row || !$row.length) {
  395. return;
  396. }
  397. $row.closest('tbody').find('tr.is-selected').removeClass('is-selected');
  398. $row.addClass('is-selected');
  399. if (updateHash) {
  400. const rowId = $row.data('row-id');
  401. if (rowId) {
  402. const hash = '#row-' + rowId;
  403. const newUrl = window.location.pathname + window.location.search + hash;
  404. history.replaceState(null, '', newUrl);
  405. if (tableName) {
  406. localStorage.setItem('table_last_row_' + tableName, String(rowId));
  407. }
  408. }
  409. }
  410. }
  411. $(document).on('click', '.table-interactive tbody tr', function (e) {
  412. if (isRowActionTarget(e.target)) {
  413. return;
  414. }
  415. selectRow($(this));
  416. });
  417. $(document).on('dblclick', '.table-interactive tbody tr', function (e) {
  418. if (isRowActionTarget(e.target)) {
  419. return;
  420. }
  421. const $row = $(this);
  422. const href = $row.data('row-href');
  423. if (!href) {
  424. return;
  425. }
  426. selectRow($row, false);
  427. const target = $row.data('open-target');
  428. if (target === '_blank') {
  429. window.open(href, '_blank');
  430. } else {
  431. window.location.href = href;
  432. }
  433. });
  434. $('.toggle-column').on('change', function () {
  435. let columnName = $(this).attr('data-name');
  436. let columnStatus = $(this).is(':checked');
  437. // save column status
  438. tables[columnName] = columnStatus;
  439. localStorage.setItem('table_' + tableName, JSON.stringify(tables));
  440. // show or hide column
  441. if (columnStatus) {
  442. $('.column_' + columnName).show('fast');
  443. } else {
  444. $('.column_' + columnName).hide('fast');
  445. }
  446. });
  447. $('.sort-by-column').on('click', function () {
  448. let columnName = $(this).attr('data-name');
  449. let currentUrl = new URL(document.location.href);
  450. let currentColumnName = currentUrl.searchParams.get('sortBy');
  451. currentUrl.searchParams.set('sortBy', columnName);
  452. if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
  453. currentUrl.searchParams.delete('order');
  454. } else {
  455. currentUrl.searchParams.set('order', 'desc');
  456. }
  457. document.location.href = currentUrl.href;
  458. });
  459. $('.accept-filters').on('click', function () {
  460. let filters = $('.filters').serializeArray();
  461. let currentUrl = new URL(document.location.href);
  462. $.each(filters, function (id, filter) {
  463. if (filter.value !== '') {
  464. currentUrl.searchParams.set(filter.name, filter.value);
  465. } else {
  466. currentUrl.searchParams.delete(filter.name);
  467. }
  468. });
  469. currentUrl.searchParams.delete('page');
  470. document.location.href = currentUrl.href;
  471. });
  472. $('.reset-filters').on('click', function () {
  473. let filters = $('.filters').serializeArray();
  474. let currentUrl = new URL(document.location.href);
  475. $.each(filters, function (id, filter) {
  476. currentUrl.searchParams.delete(filter.name);
  477. });
  478. currentUrl.searchParams.delete('page');
  479. document.location.href = currentUrl.href;
  480. });
  481. $('.accept-search').on('click', function () {
  482. let s = $('.search-form input').val();
  483. let currentUrl = new URL(document.location.href);
  484. if (s !== '') {
  485. currentUrl.searchParams.set('s', s);
  486. } else {
  487. currentUrl.searchParams.delete('s');
  488. }
  489. currentUrl.searchParams.delete('page');
  490. document.location.href = currentUrl.href;
  491. });
  492. $('.reset-search').on('click', function () {
  493. let currentUrl = new URL(document.location.href);
  494. currentUrl.searchParams.delete('s');
  495. currentUrl.searchParams.delete('page');
  496. document.location.href = currentUrl.href;
  497. });
  498. $('.change-order-status').on('change', function () {
  499. let orderStatusId = $(this).val();
  500. let orderId = $(this).attr('data-order-id');
  501. $.post(
  502. '{{ route('order.update') }}',
  503. {
  504. '_token' : '{{ csrf_token() }}',
  505. id: orderId,
  506. order_status_id: orderStatusId
  507. },
  508. function () {
  509. $('.alerts').append(
  510. '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
  511. );
  512. setTimeout(function () {
  513. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  514. $(".main-alert").slideUp(500);
  515. })
  516. }, 3000);
  517. }
  518. );
  519. });
  520. $('.change-reclamation-status').on('change', function () {
  521. let statusId = $(this).val();
  522. let url = $(this).attr('data-url');
  523. $.post(
  524. url,
  525. {
  526. '_token' : '{{ csrf_token() }}',
  527. status_id: statusId
  528. },
  529. function () {
  530. $('.alerts').append(
  531. '<div class="main-alert alert alert-success" role="alert">Обновлён статус рекламации!</div>'
  532. );
  533. setTimeout(function () {
  534. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  535. $(".main-alert").slideUp(500);
  536. })
  537. }, 3000);
  538. }
  539. );
  540. });
  541. function updateMainTableScrollHeight() {
  542. const tableScrollElement = document.querySelector('.js-main-table-scroll');
  543. if (!tableScrollElement) {
  544. return;
  545. }
  546. const tableTop = tableScrollElement.getBoundingClientRect().top;
  547. const bottomGap = 16;
  548. let paginationHeight = 0;
  549. const paginationRow = document.querySelector('.pagination')?.closest('.row');
  550. if (paginationRow) {
  551. paginationHeight = paginationRow.getBoundingClientRect().height + 8;
  552. }
  553. const maxHeight = Math.max(180, window.innerHeight - tableTop - paginationHeight - bottomGap);
  554. tableScrollElement.style.maxHeight = maxHeight + 'px';
  555. }
  556. $(document).ready(function () {
  557. updateMainTableScrollHeight();
  558. window.addEventListener('resize', updateMainTableScrollHeight);
  559. // Инициализация tooltips для полей tsn_number и pricing_code
  560. const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  561. const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  562. const hash = window.location.hash;
  563. if (hash && hash.startsWith('#row-')) {
  564. const $row = $(hash);
  565. if ($row.length) {
  566. selectRow($row, false);
  567. $row[0].scrollIntoView({block: 'center'});
  568. const rowId = $row.data('row-id');
  569. if (rowId && tableName) {
  570. localStorage.setItem('table_last_row_' + tableName, String(rowId));
  571. }
  572. return;
  573. }
  574. }
  575. if (tableName) {
  576. const storedRowId = localStorage.getItem('table_last_row_' + tableName);
  577. if (storedRowId) {
  578. const $storedRow = $('#row-' + storedRowId);
  579. if ($storedRow.length) {
  580. selectRow($storedRow, false);
  581. $storedRow[0].scrollIntoView({block: 'center'});
  582. }
  583. }
  584. }
  585. });
  586. }); // end waitForJQuery
  587. </script>
  588. @endpush