table.blade.php 36 KB

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