table.blade.php 41 KB

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