table.blade.php 34 KB

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