table.blade.php 40 KB

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