table.blade.php 42 KB

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