table.blade.php 37 KB

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