table.blade.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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}} align-middle"
  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($id === 'users' && $headerName === 'role')
  226. {{ \App\Models\Role::NAMES[$string->role] ?? $string->role }}
  227. @elseif($headerName === 'actions' && isset($routeName) && isset($string->id))
  228. <a href="{{ route($routeName, $string->id) }}" class="btn btn-sm btn-outline-primary">
  229. Редактировать
  230. </a>
  231. @else
  232. <p title="{!! $string->$headerName !!}">
  233. {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
  234. </p>
  235. @endif
  236. </td>
  237. @endforeach
  238. </tr>
  239. @endforeach
  240. </tbody>
  241. </table>
  242. </div>
  243. <!-- Модальное окно настроек таблицы -->
  244. <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="table_{{ $id }}_modal_settings_label"
  245. aria-hidden="true">
  246. <div class="modal-dialog modal-fullscreen-sm-down">
  247. <div class="modal-content">
  248. <div class="modal-header">
  249. <h1 class="modal-title fs-5" id="table_{{ $id }}_modal_settings_label">Выбор отображаемых колонок</h1>
  250. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  251. </div>
  252. <div class="modal-body">
  253. @foreach($header as $headerName => $headerTitle)
  254. <div>
  255. <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
  256. class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
  257. </label>
  258. </div>
  259. @endforeach
  260. </div>
  261. <div class="modal-footer">
  262. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. <!-- Модальное окно фильтров -->
  268. <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="table_{{ $id }}_modal_filters_label"
  269. aria-hidden="true">
  270. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  271. <div class="modal-content">
  272. <div class="modal-header">
  273. <h1 class="modal-title fs-5" id="table_{{ $id }}_modal_filters_label">Фильтры по колонкам таблицы</h1>
  274. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  275. </div>
  276. <div class="modal-body">
  277. <form class="filters">
  278. @if(isset($filters) && is_array($filters))
  279. @foreach($filters as $filterName => $filter)
  280. @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
  281. @include('partials.select', [
  282. 'name' => 'filters[' . $filterName . ']',
  283. 'title' => $filter['title'],
  284. 'options' => $filter['values'],
  285. 'value' => request()->filters[$filterName] ?? '',
  286. ])
  287. @endforeach
  288. @endif
  289. @if(isset($ranges) && is_array($ranges))
  290. @foreach($ranges as $rangeName => $range)
  291. @include('partials.input', [
  292. 'name' => 'filters[' . $rangeName . '_from]',
  293. 'type' => 'number',
  294. 'title' => $range['title'] . ' с:',
  295. 'min' => $range['min'],
  296. 'max' => $range['max'],
  297. 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
  298. ])
  299. @include('partials.input', [
  300. 'name' => 'filters[' . $rangeName . '_to]',
  301. 'type' => 'number',
  302. 'title' => ' по:',
  303. 'min' => $range['min'],
  304. 'max' => $range['max'],
  305. 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
  306. ])
  307. @endforeach
  308. @endif
  309. @if(isset($dates) && is_array($dates))
  310. @foreach($dates as $rangeName => $range)
  311. @include('partials.input', [
  312. 'name' => 'filters[' . $rangeName . '_from]',
  313. 'type' => 'date',
  314. 'title' => $range['title'] . ' с:',
  315. 'min' => $range['min'],
  316. 'max' => $range['max'],
  317. 'value' => request()->filters[$rangeName . '_from'] ?? '',
  318. ])
  319. @include('partials.input', [
  320. 'name' => 'filters[' . $rangeName . '_to]',
  321. 'type' => 'date',
  322. 'title' => $range['title'] . ' по:',
  323. 'min' => $range['min'],
  324. 'max' => $range['max'],
  325. 'value' => request()->filters[$rangeName . '_to'] ?? '',
  326. ])
  327. @endforeach
  328. @endif
  329. </form>
  330. </div>
  331. <div class="modal-footer">
  332. <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
  333. <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
  334. </button>
  335. </div>
  336. </div>
  337. </div>
  338. </div>
  339. <!-- Модальное окно поиска -->
  340. <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="table_{{ $id }}_modal_search_label"
  341. aria-hidden="true">
  342. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  343. <div class="modal-content">
  344. <div class="modal-header">
  345. <h1 class="modal-title fs-5" id="table_{{ $id }}_modal_search_label">Поиск</h1>
  346. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  347. </div>
  348. <div class="modal-body">
  349. <div>
  350. Поиск ведётся по следующим колонкам:
  351. <span class="fst-italic">
  352. @foreach($searchFields as $searchField)
  353. {{ $header[$searchField] ?? $searchField }}
  354. @if(!$loop->last)
  355. ,
  356. @endif
  357. @endforeach
  358. </span>
  359. </div>
  360. <form class="search-form">
  361. @include('partials.input', [
  362. 'name' => 's',
  363. 'title' => 'Поиск',
  364. 'placeholder' => 'что ищем?',
  365. 'value' => request()->s ?? '',
  366. ])
  367. </form>
  368. </div>
  369. <div class="modal-footer">
  370. <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
  371. <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
  372. </button>
  373. </div>
  374. </div>
  375. </div>
  376. </div>
  377. @push('scripts')
  378. <script type="module">
  379. // Ждём загрузки jQuery через Vite
  380. function waitForJQuery(callback) {
  381. if (typeof window.$ !== 'undefined') {
  382. callback();
  383. } else {
  384. setTimeout(() => waitForJQuery(callback), 50);
  385. }
  386. }
  387. waitForJQuery(function () {
  388. // on page load set column visible
  389. let tbl = $('#tbl');
  390. let tableName = tbl.attr('data-table-name');
  391. let tables = JSON.parse(localStorage.getItem('table_' + tableName));
  392. // on first load create tables object
  393. if (!tables) {
  394. tables = {};
  395. }
  396. // hide disabled columns
  397. $.each(tables, function (colName, colStatus) {
  398. if (!colStatus) {
  399. $('.checkbox-' + colName).attr('checked', false);
  400. $('.column_' + colName).hide();
  401. }
  402. });
  403. // highlight search text
  404. let searchText = $('.search-form input').val();
  405. if (searchText !== '') {
  406. let innerHTML = tbl.html();
  407. let index = innerHTML.indexOf(searchText);
  408. if (index >= 0) {
  409. innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
  410. tbl.html(innerHTML);
  411. }
  412. }
  413. $('.table').fadeIn();
  414. function isRowActionTarget(target) {
  415. return $(target).closest('a, button, input, select, textarea, label, .dropdown, [data-bs-toggle], [data-no-row-select]').length > 0;
  416. }
  417. function openRow($row, newTab = false) {
  418. const href = $row.data('row-href');
  419. if (!href) {
  420. return;
  421. }
  422. selectRow($row, false);
  423. if (newTab) {
  424. window.open(href, '_blank');
  425. } else {
  426. window.location.href = href;
  427. }
  428. }
  429. function selectRow($row, updateHash = true) {
  430. if (!$row || !$row.length) {
  431. return;
  432. }
  433. $row.closest('tbody').find('tr.is-selected').removeClass('is-selected');
  434. $row.addClass('is-selected');
  435. if (updateHash) {
  436. const rowId = $row.data('row-id');
  437. if (rowId) {
  438. const hash = '#row-' + rowId;
  439. const newUrl = window.location.pathname + window.location.search + hash;
  440. history.replaceState(null, '', newUrl);
  441. if (tableName) {
  442. localStorage.setItem('table_last_row_' + tableName, String(rowId));
  443. }
  444. }
  445. }
  446. }
  447. $(document).on('click', '.table-interactive tbody tr', function (e) {
  448. if (isRowActionTarget(e.target)) {
  449. return;
  450. }
  451. const $row = $(this);
  452. // На десктопах с Ctrl открываем в новой вкладке сразу по одиночному клику
  453. const isTouchDevice = window.matchMedia('(pointer: coarse)').matches || ('ontouchstart' in window);
  454. if (!isTouchDevice && (e.ctrlKey || e.metaKey)) {
  455. openRow($row, true);
  456. return;
  457. }
  458. selectRow($row);
  459. // На мобильных dblclick часто не срабатывает, поэтому поддерживаем двойной тап.
  460. if (!isTouchDevice) {
  461. return;
  462. }
  463. const now = Date.now();
  464. const rowKey = String($row.data('row-id') ?? $row.data('row-href') ?? '');
  465. const lastTapAt = Number($row.data('last-tap-at') ?? 0);
  466. const lastTapKey = String($row.data('last-tap-key') ?? '');
  467. if (lastTapAt && (now - lastTapAt) < 450 && rowKey && lastTapKey === rowKey) {
  468. openRow($row);
  469. $row.removeData('last-tap-at').removeData('last-tap-key');
  470. return;
  471. }
  472. $row.data('last-tap-at', now);
  473. $row.data('last-tap-key', rowKey);
  474. });
  475. $(document).on('dblclick', '.table-interactive tbody tr', function (e) {
  476. if (isRowActionTarget(e.target)) {
  477. return;
  478. }
  479. openRow($(this), e.ctrlKey || e.metaKey);
  480. });
  481. $('.toggle-column').on('change', function () {
  482. let columnName = $(this).attr('data-name');
  483. let columnStatus = $(this).is(':checked');
  484. // save column status
  485. tables[columnName] = columnStatus;
  486. localStorage.setItem('table_' + tableName, JSON.stringify(tables));
  487. // show or hide column
  488. if (columnStatus) {
  489. $('.column_' + columnName).show('fast');
  490. } else {
  491. $('.column_' + columnName).hide('fast');
  492. }
  493. });
  494. $('.sort-by-column').on('click', function () {
  495. let columnName = $(this).attr('data-name');
  496. let currentUrl = new URL(document.location.href);
  497. let currentColumnName = currentUrl.searchParams.get('sortBy');
  498. currentUrl.searchParams.set('sortBy', columnName);
  499. if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
  500. currentUrl.searchParams.delete('order');
  501. } else {
  502. currentUrl.searchParams.set('order', 'desc');
  503. }
  504. document.location.href = currentUrl.href;
  505. });
  506. $('.accept-filters').on('click', function () {
  507. let filters = $('.filters').serializeArray();
  508. let currentUrl = new URL(document.location.href);
  509. $.each(filters, function (id, filter) {
  510. if (filter.value !== '') {
  511. currentUrl.searchParams.set(filter.name, filter.value);
  512. } else {
  513. currentUrl.searchParams.delete(filter.name);
  514. }
  515. });
  516. currentUrl.searchParams.delete('page');
  517. document.location.href = currentUrl.href;
  518. });
  519. $('.reset-filters').on('click', function () {
  520. let filters = $('.filters').serializeArray();
  521. let currentUrl = new URL(document.location.href);
  522. $.each(filters, function (id, filter) {
  523. currentUrl.searchParams.delete(filter.name);
  524. });
  525. currentUrl.searchParams.delete('page');
  526. document.location.href = currentUrl.href;
  527. });
  528. $('.accept-search').on('click', function () {
  529. let s = $('.search-form input').val();
  530. let currentUrl = new URL(document.location.href);
  531. if (s !== '') {
  532. currentUrl.searchParams.set('s', s);
  533. } else {
  534. currentUrl.searchParams.delete('s');
  535. }
  536. currentUrl.searchParams.delete('page');
  537. document.location.href = currentUrl.href;
  538. });
  539. $('.reset-search').on('click', function () {
  540. let currentUrl = new URL(document.location.href);
  541. currentUrl.searchParams.delete('s');
  542. currentUrl.searchParams.delete('page');
  543. document.location.href = currentUrl.href;
  544. });
  545. $('.change-order-status').on('focus', function () {
  546. $(this).data('previous-value', $(this).val());
  547. });
  548. $('.change-order-status').on('change', function () {
  549. let $select = $(this);
  550. let orderStatusId = $select.val();
  551. let orderId = $select.attr('data-order-id');
  552. let previousValue = $select.data('previous-value');
  553. $.post(
  554. '{{ route('order.update') }}',
  555. {
  556. '_token' : '{{ csrf_token() }}',
  557. id: orderId,
  558. order_status_id: orderStatusId
  559. },
  560. function () {
  561. $select.data('previous-value', orderStatusId);
  562. $('.alerts').append(
  563. '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
  564. );
  565. setTimeout(function () {
  566. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  567. $(".main-alert").slideUp(500);
  568. })
  569. }, 3000);
  570. }
  571. ).fail(function (xhr) {
  572. if (previousValue !== undefined) {
  573. $select.val(previousValue);
  574. }
  575. let errorText = xhr.responseJSON?.message || 'Не удалось обновить статус площадки!';
  576. $('.alerts').append(
  577. '<div class="main-alert alert alert-danger" role="alert">' + errorText + '</div>'
  578. );
  579. setTimeout(function () {
  580. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  581. $(".main-alert").slideUp(500);
  582. })
  583. }, 3000);
  584. });
  585. });
  586. $('.change-reclamation-status').on('change', function () {
  587. let statusId = $(this).val();
  588. let url = $(this).attr('data-url');
  589. $.post(
  590. url,
  591. {
  592. '_token' : '{{ csrf_token() }}',
  593. status_id: statusId
  594. },
  595. function () {
  596. $('.alerts').append(
  597. '<div class="main-alert alert alert-success" role="alert">Обновлён статус рекламации!</div>'
  598. );
  599. setTimeout(function () {
  600. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  601. $(".main-alert").slideUp(500);
  602. })
  603. }, 3000);
  604. }
  605. );
  606. });
  607. function updateMainTableScrollHeight() {
  608. const tableScrollElement = document.querySelector('.js-main-table-scroll');
  609. if (!tableScrollElement) {
  610. return;
  611. }
  612. const tableTop = tableScrollElement.getBoundingClientRect().top;
  613. const bottomGap = 16;
  614. let paginationHeight = 0;
  615. const paginationRow = document.querySelector('.pagination')?.closest('.row');
  616. if (paginationRow) {
  617. paginationHeight = paginationRow.getBoundingClientRect().height + 8;
  618. }
  619. const maxHeight = Math.max(180, window.innerHeight - tableTop - paginationHeight - bottomGap);
  620. tableScrollElement.style.maxHeight = maxHeight + 'px';
  621. }
  622. $(document).ready(function () {
  623. updateMainTableScrollHeight();
  624. window.addEventListener('resize', updateMainTableScrollHeight);
  625. // Инициализация tooltips для полей tsn_number и pricing_code
  626. const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  627. const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  628. const hash = window.location.hash;
  629. if (hash && hash.startsWith('#row-')) {
  630. const $row = $(hash);
  631. if ($row.length) {
  632. selectRow($row, false);
  633. $row[0].scrollIntoView({block: 'center'});
  634. const rowId = $row.data('row-id');
  635. if (rowId && tableName) {
  636. localStorage.setItem('table_last_row_' + tableName, String(rowId));
  637. }
  638. return;
  639. }
  640. }
  641. if (tableName) {
  642. const storedRowId = localStorage.getItem('table_last_row_' + tableName);
  643. if (storedRowId) {
  644. const $storedRow = $('#row-' + storedRowId);
  645. if ($storedRow.length) {
  646. selectRow($storedRow, false);
  647. $storedRow[0].scrollIntoView({block: 'center'});
  648. }
  649. }
  650. }
  651. });
  652. }); // end waitForJQuery
  653. </script>
  654. @endpush