records.blade.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <div class="col card--ui" id="card--dashboard">
  2. <header id="title--section" style="display:none !important" class="d-flex align-items-center justify-content-between">
  3. <div class="title--section_name d-flex align-items-center justify-content-between">
  4. <i class="ico--ui title_section utenti me-2"></i>
  5. <h2 class="primary">Prima nota</h2>
  6. </div>
  7. </header>
  8. <section id="subheader" class="">
  9. <div class="row g-3">
  10. <div class="col-md-2">
  11. Utente
  12. <select name="search_member_id" class="form-select filterMember" wire:model="filterMember">
  13. <option value="">--Seleziona--
  14. @foreach($members as $member)
  15. <option value="{{$member->id}}">{{$member->last_name}} {{$member->first_name}}
  16. @endforeach
  17. </select>
  18. </div>
  19. <div class="col-md-4">
  20. Causale
  21. <select name="search_causal_id[]" class="form-select filterCausals me-2" multiple="multiple" wire:model="filterCausals">
  22. @foreach($causals as $causal)
  23. <option value="{{$causal["id"]}}">{!!$causal["name"]!!}
  24. @endforeach
  25. </select>
  26. </div>
  27. <div class="col-md-2">
  28. <span class="date_span">Dal</span>
  29. <input type="date" wire:model.defer="fromDate" class="form-control" @if($isFiltering) disabled @endif>
  30. </div>
  31. <div class="col-md-2">
  32. <span class="date_span ms-2">al</span>
  33. <input type="date" wire:model.defer="toDate" class="form-control" @if($isFiltering) disabled @endif>
  34. </div>
  35. <div class="col-md-2">
  36. <div class="prima--nota_buttons ms-auto" style="float:right; margin-top:25px;">
  37. <button class="btn--ui primary" wire:click="applyFilters" style="margin-right:5px;" @if($isFiltering) disabled @endif>
  38. @if($isFiltering)
  39. <i class="fas fa-spinner fa-spin"></i> CARICAMENTO...
  40. @else
  41. FILTRA
  42. @endif
  43. </button>
  44. <button class="btn--ui lightGrey reset reset" style="margin-left:5px;color:#10172A;" onclick="reset()" @if($isFiltering) disabled @endif>RESET</button>
  45. </div>
  46. </div>
  47. </div>
  48. <div style="float:left; margin-top:10px; margin-bottom:10px;">
  49. <div class="dropdown">
  50. <button class="btn--ui_outline light dropdown-toggle" type="button" id="exportDropdown" data-bs-toggle="dropdown" aria-expanded="false"
  51. style="color:#10172A;" @if($isFiltering) disabled @endif>
  52. ESPORTA
  53. </button>
  54. <ul class="dropdown-menu" aria-labelledby="exportDropdown">
  55. <li><a class="dropdown-item" href="#" wire:click="export()">Excel</a></li>
  56. <li><a class="dropdown-item" href="#" id="print">Stampa</a></li>
  57. </ul>
  58. </div>
  59. </div>
  60. </section>
  61. <section id="resume-table" class="scrollTable records-table" style="position: relative;">
  62. @if($isFiltering)
  63. <div class="loading-overlay">
  64. <div class="loading-content">
  65. <i class="fas fa-spinner fa-spin fa-3x"></i>
  66. <p>Caricamento dati in corso...</p>
  67. </div>
  68. </div>
  69. @endif
  70. <!-- Your existing table -->
  71. <table class="table tablesaw tableHead tablesaw-stack" id="tablesaw-350" width="100%">
  72. <thead>
  73. <tr>
  74. <th scope="col">Data</th>
  75. <th scope="col" style="border-left:3px solid white;">Causale</th>
  76. <th scope="col" style="border-left:3px solid white;">Dettaglio Causale</th>
  77. <th scope="col" style="border-left:3px solid white;">Stato</th>
  78. <th scope="col" style="border-left:3px solid white;">Nominativo</th>
  79. @foreach($payments as $p)
  80. <th colspan="2" scope="col" style="text-align:center; border-left:3px solid white;">{{$p->name}}</th>
  81. @endforeach
  82. </tr>
  83. <tr>
  84. <th scope="col"></th>
  85. <th scope="col" style="border-left:3px solid white;"></th>
  86. <th scope="col" style="border-left:3px solid white;"></th>
  87. <th scope="col" style="border-left:3px solid white;"></th>
  88. <th scope="col" style="border-left:3px solid white;"></th>
  89. @foreach($payments as $p)
  90. @if($p->type == 'ALL')
  91. <th scope="col" style="text-align:center; border-left:3px solid white;">Entrate</th>
  92. <th scope="col" style="text-align:center">Uscite</th>
  93. @elseif($p->type == 'IN')
  94. <th scope="col" style="text-align:center; border-left:3px solid white;">Entrate</th>
  95. <th scope="col" style="text-align:center;"></th>
  96. @elseif($p->type == 'OUT')
  97. <th style="border-left:3px solid white;"></th>
  98. <th scope="col" style="text-align:center;">Uscite</th>
  99. @endif
  100. @endforeach
  101. </tr>
  102. </thead>
  103. <tbody id="checkall-target">
  104. @php $count = 0; @endphp
  105. @foreach($records as $causal => $record)
  106. <tr>
  107. @php
  108. $parts = explode("§", $causal);
  109. $d = $parts[0] ?? '';
  110. $c = $parts[1] ?? '';
  111. $n = $parts[2] ?? ''; // Nominativo
  112. $det = $parts[3] ?? '';
  113. $del = $parts[4] ?? '';
  114. // Check if detail contains multiple causals (separated by |)
  115. $detailParts = explode('|', $det);
  116. $isMultiple = count($detailParts) > 1;
  117. $displayDetail = $isMultiple ? 'Varie' : $det;
  118. @endphp
  119. <td style="background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{date("d/m/Y", strtotime($d))}}</td>
  120. <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{$c}}</td>
  121. <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">
  122. @if($isMultiple)
  123. <span class="varie-link" data-causals="{{implode('|', array_slice($detailParts, 1))}}" style="color: #0C6197; cursor: pointer; text-decoration: underline;">
  124. {{$displayDetail}}
  125. </span>
  126. @else
  127. {{$displayDetail}}
  128. @endif
  129. </td>
  130. <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">
  131. @if($del == 'DELETED')
  132. <span style='color:red'>Annullata</span>
  133. @endif
  134. </td>
  135. <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">{{$n}}</td>
  136. @foreach($payments as $p)
  137. @if(isset($record[$p->name]))
  138. <td style="text-align:right; border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">
  139. @if(isset($record[$p->name]["IN"]))
  140. <span class="tablesaw-cell-content " style="color:green">{{formatPrice($record[$p->name]["IN"])}}</span>
  141. @endif
  142. </td>
  143. <td style="text-align:right;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}">
  144. @if(isset($record[$p->name]["OUT"]))
  145. <span class="tablesaw-cell-content " style="color:red">{{formatPrice($record[$p->name]["OUT"])}}</span>
  146. @endif
  147. </td>
  148. @else
  149. <td style="border-left:3px solid white !important;background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}"></td>
  150. <td style="background-color:{{$count % 2 == 0 ? 'white' : '#f2f4f7'}}"></td>
  151. @endif
  152. @endforeach
  153. </tr>
  154. @php $count++; @endphp
  155. @endforeach
  156. </tbody>
  157. <tfoot>
  158. <tr>
  159. <td></td>
  160. <td></td>
  161. <td></td>
  162. <td></td>
  163. <td><b>Totale</b></td>
  164. @foreach($payments as $p)
  165. @if(isset($totals[$p->name]))
  166. @if($p->type == 'ALL')
  167. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:green; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["IN"] : 0)}}</b></span></td>
  168. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:red; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["OUT"] : 0)}}</b></span></td>
  169. @elseif($p->type == 'IN')
  170. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:green; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["IN"] : 0)}}</b></span></td>
  171. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:red; font-size:18px;"><b>&nbsp;</b></span></td>
  172. @elseif($p->type == 'OUT')
  173. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:green; font-size:18px;"><b>&nbsp;</b></span></td>
  174. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:red; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["OUT"] : 0)}}</b></span></td>
  175. @endif
  176. @else
  177. @if($p->type == 'ALL')
  178. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:green; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["IN"] : 0)}}</b></span></td>
  179. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:red; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["OUT"] : 0)}}</b></span></td>
  180. @elseif($p->type == 'IN')
  181. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:green; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["IN"] : 0)}}</b></span></td>
  182. <td style="text-align:center"><span class="tablesaw-cell-content primary" style="color:red; font-size:18px;"><b>&nbsp;</b></span></td>
  183. @elseif($p->type == 'OUT')
  184. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:green; font-size:18px;"><b>&nbsp;</b></span></td>
  185. <td style="text-align:center"><span class="tablesaw-cell-content primary" style="color:red; font-size:18px;"><b>{{formatPrice(isset($totals[$p->name]) ? $totals[$p->name]["OUT"] : 0)}}</b></span></td>
  186. @endif
  187. @endif
  188. @endforeach
  189. </tr>
  190. <tr style="display:none">
  191. <td></td>
  192. <td><b>Differenza</b></td>
  193. @foreach($payments as $p)
  194. @if(isset($totals[$p->name]))
  195. @php
  196. $diff = $totals[$p->name]["IN"] - $totals[$p->name]["OUT"];
  197. @endphp
  198. @if($diff < 0)
  199. <td></td>
  200. @endif
  201. <td style="text-align:right"><span class="tablesaw-cell-content primary" style="color:{{$diff > 0 ? 'green' : 'red'}}; font-size:18px;"><b>{{formatPrice($diff)}}</b></span></td>
  202. @if($diff > 0)
  203. <td></td>
  204. @endif
  205. @else
  206. <td colspan="2" style="text-align:right"><b>{{formatPrice(0)}}</b></td>
  207. @endif
  208. @endforeach
  209. </tr>
  210. </tfoot>
  211. </table>
  212. <button type="button" class="btn btn-floating btn-lg" id="btn-back-to-bottom"><i class="fas fa-arrow-down"></i></button>
  213. <button type="button" class="btn btn-floating btn-lg" id="btn-back-to-top"><i class="fas fa-arrow-up"></i></button>
  214. </section>
  215. <div class="modal fade" id="causalsModal" tabindex="-1" aria-labelledby="causalsModalLabel" aria-hidden="true">
  216. <div class="modal-dialog modal-lg">
  217. <div class="modal-content">
  218. <div class="modal-header" style="background-color: #0C6197!important;">
  219. <h5 class="modal-title" id="causalsModalLabel" >Dettaglio Causali</h5>
  220. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="CHIUDI"></button>
  221. </div>
  222. <div class="modal-body">
  223. <div class="row">
  224. <div class="col-12">
  225. <h6>Causali incluse:</h6>
  226. <ul id="causalsList" class="list-group list-group-flush">
  227. <!-- Causals will be populated here by JavaScript -->
  228. </ul>
  229. </div>
  230. </div>
  231. </div>
  232. <div class="modal-footer" style="background-color: #FFF!important;">
  233. <button type="button" class="btn--ui lightGrey me-2" data-bs-dismiss="modal">CHIUDI</button>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. @push('scripts')
  240. <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  241. @endpush
  242. @push('scripts')
  243. <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  244. <style>
  245. #btn-back-to-top {
  246. background-color: #0C6197;
  247. color: white;
  248. position: fixed;
  249. /* bottom: 20px; */
  250. /* right: 20px; */
  251. display: none;
  252. }
  253. #btn-back-to-bottom {
  254. background-color: #0C6197;
  255. color: white;
  256. position: fixed;
  257. /* top: 120px; */
  258. /* right: 20px; */
  259. z-index: 9999;
  260. display: none;
  261. }
  262. .scrollTable {
  263. margin-left: 0px ;
  264. margin-right: 0px ;
  265. padding: 15px;
  266. /*max-width: 800px !important;*/
  267. overflow-x: auto;
  268. overflow-y: auto;
  269. white-space: nowrap;
  270. border: 1px solid #ddd;
  271. }
  272. ::-webkit-scrollbar-thumb {
  273. background: #e4e4e4;
  274. border-radius: 10px;
  275. }
  276. table thead {
  277. /* Important */
  278. position: sticky;
  279. z-index: 100;
  280. top: 0;
  281. }
  282. .select2-container--default .select2-selection--single{
  283. background-color: #E9F0F5;
  284. border: 0.0625rem solid #DFE5EB;
  285. font-size: 0.75rem;
  286. }
  287. .select2-selection
  288. {
  289. height: 38px !important;
  290. }
  291. .select2-selection__rendered
  292. {
  293. padding-top:3px;
  294. }
  295. .select2 {
  296. width:100% !important;
  297. }
  298. .i{
  299. font-size:16px;
  300. font-weight:bold;
  301. }
  302. .cellBorder
  303. {
  304. border-left: 1px solid grey;
  305. }
  306. .select2-selection--multiple{
  307. overflow: hidden !important;
  308. height: auto !important;
  309. }
  310. .select2-container {
  311. box-sizing: border-box;
  312. display: inline-block;
  313. margin: 0;
  314. position: relative;
  315. vertical-align: middle;
  316. }
  317. .select2-container .select2-selection--single {
  318. box-sizing: border-box;
  319. cursor: pointer;
  320. display: block;
  321. height: 38px;
  322. user-select: none;
  323. -webkit-user-select: none;
  324. }
  325. .select2-container .select2-selection--single .select2-selection__rendered {
  326. display: block;
  327. padding-left: 8px;
  328. padding-right: 20px;
  329. overflow: hidden;
  330. text-overflow: ellipsis;
  331. white-space: nowrap;
  332. }
  333. button#exportDropdown.btn--ui_outline.light {
  334. font-weight: normal !important;
  335. }
  336. .btn--ui_outline.light.dropdown-toggle:active,
  337. .btn--ui_outline.light.dropdown-toggle:focus,
  338. .btn--ui_outline.light.dropdown-toggle.show {
  339. background-color: transparent !important;
  340. color: #10172A !important;
  341. box-shadow: none !important;
  342. }
  343. .btn--ui_outline.light.dropdown-toggle:hover {
  344. background-color: transparent !important;
  345. color: #10172A !important;
  346. }
  347. </style>
  348. <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  349. <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
  350. <script src="/assets/js/aCollapTable.js"></script>
  351. @endpush
  352. @push('scripts')
  353. <script>
  354. Livewire.on('load-table', () => {
  355. load();
  356. });
  357. function load()
  358. {
  359. $(document).ready(function(){
  360. $(document).on("keypress", $('.filterCausals'), function (e) {
  361. setTimeout(() => {
  362. $(".select2-results__option").each(function(){
  363. var txt = $(this).html();
  364. var count = (txt.match(/-/g) || []).length;
  365. $(this).addClass('paddingLeftSelect' + count);
  366. });
  367. }, 100);
  368. });
  369. $('.filterCausals').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  370. $('.filterCausals').on('change', function (e) {
  371. var data = $('.filterCausals').select2("val");
  372. @this.set('filterCausals', data);
  373. });
  374. $('.filterCausals').on('select2:open', function (e) {
  375. setTimeout(() => {
  376. $(".select2-results__option").each(function(){
  377. var txt = $(this).html();
  378. var count = (txt.match(/-/g) || []).length;
  379. $(this).addClass('paddingLeftSelect' + count);
  380. });
  381. }, 100);
  382. });
  383. $('.filterMember').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  384. $('.filterMember').on('change', function (e) {
  385. var data = $('.filterMember').select2("val");
  386. @this.set('filterMember', data);
  387. });
  388. });
  389. }
  390. Livewire.on('load-select', () => {
  391. $('.filterCausals').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  392. $('.filterCausals').on('change', function (e) {
  393. var data = $('.filterCausals').select2("val");
  394. @this.set('filterCausals', data);
  395. });
  396. $('.filterMember').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
  397. $('.filterMember').on('change', function (e) {
  398. var data = $('.filterMember').select2("val");
  399. @this.set('filterMember', data);
  400. });
  401. setMaxWidth();
  402. setMaxHeight();
  403. });
  404. load();
  405. </script>
  406. @endpush
  407. @push('scripts')
  408. <script>
  409. function printData()
  410. {
  411. var divToPrint=document.getElementById("tablesaw-350");
  412. newWin= window.open("");
  413. var htmlToPrint = '' +
  414. '<style type="text/css">' +
  415. 'table th, table td {' +
  416. 'border:1px solid #000;' +
  417. 'padding:0.5em;' +
  418. '}' +
  419. '</style>';
  420. htmlToPrint += divToPrint.outerHTML;
  421. newWin.document.write(htmlToPrint);
  422. newWin.document.close();
  423. newWin.print();
  424. newWin.close();
  425. }
  426. document.querySelector("#print").addEventListener("click", function(){
  427. printData();
  428. });
  429. $( document ).ready( function(){
  430. setMaxWidth();
  431. setMaxHeight();
  432. $( window ).bind( "resize", setMaxWidth );
  433. $( window ).bind( "resize", setMaxHeight );
  434. $(".open-filter").click(function(){
  435. setMaxWidth();
  436. setMaxHeight();
  437. });
  438. });
  439. function setMaxWidth() {
  440. }
  441. function setMaxHeight() {
  442. }
  443. let mybuttonBottom = document.getElementById("btn-back-to-bottom");
  444. let mybutton = document.getElementById("btn-back-to-top");
  445. window.onscroll = function () {
  446. scrollFunction();
  447. };
  448. const element = document.getElementById('resume-table');
  449. element.onscroll = (e)=>{
  450. scrollFunction();
  451. };
  452. function scrollFunction() {
  453. if (
  454. element.scrollTop > 20
  455. ) {
  456. mybutton.style.display = "block";
  457. mybuttonBottom.style.display = "block";
  458. } else {
  459. mybutton.style.display = "none";
  460. mybuttonBottom.style.display = "none";
  461. }
  462. }
  463. function scrollFunctionOld() {
  464. if (
  465. document.body.scrollTop > 20 ||
  466. document.documentElement.scrollTop > 20
  467. ) {
  468. mybutton.style.display = "block";
  469. mybuttonBottom.style.display = "block";
  470. } else {
  471. mybutton.style.display = "none";
  472. mybuttonBottom.style.display = "none";
  473. }
  474. }
  475. // When the user clicks on the button, scroll to the top of the document
  476. mybutton.addEventListener("click", backToTop);
  477. mybuttonBottom.addEventListener("click", backToBottom);
  478. function backToTop() {
  479. $('#resume-table').scrollTop(0);
  480. /*document.body.scrollTop = 0;
  481. document.documentElement.scrollTop = 0;*/
  482. }
  483. function backToBottom() {
  484. $('#resume-table').scrollTop($('#resume-table')[0].scrollHeight);
  485. //window.scrollTo(0, document.body.scrollHeight);
  486. }
  487. function reset()
  488. {
  489. $('.filterMember').val('');
  490. $('.filterMember').trigger('change');
  491. $('.filterCausals').val('');
  492. $('.filterCausals').trigger('change');
  493. var today = new Date().toISOString().split('T')[0];
  494. // Update the form inputs
  495. window.livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id')).set('fromDate', today);
  496. window.livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id')).set('toDate', today);
  497. // Reset the applied dates and trigger filter
  498. window.livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id')).set('appliedFromDate', today);
  499. window.livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id')).set('appliedToDate', today);
  500. // Trigger re-render
  501. window.livewire.find(document.querySelector('[wire\\:id]').getAttribute('wire:id')).call('$refresh');
  502. }
  503. $(document).ready(function() {
  504. // Safe function to close select2 dropdowns
  505. function closeSelect2Dropdowns() {
  506. // Only close select2 on elements that actually have select2 initialized
  507. $('.filterCausals').each(function() {
  508. if ($(this).hasClass('select2-hidden-accessible')) {
  509. $(this).select2('close');
  510. }
  511. });
  512. $('.filterMember').each(function() {
  513. if ($(this).hasClass('select2-hidden-accessible')) {
  514. $(this).select2('close');
  515. }
  516. });
  517. }
  518. // Handle click on "Varie" links
  519. $(document).on('click', '.varie-link', function(e) {
  520. e.preventDefault();
  521. e.stopPropagation();
  522. // Close any open select2 dropdowns safely
  523. closeSelect2Dropdowns();
  524. // Get the causals data from the data attribute
  525. const causalsData = $(this).data('causals');
  526. if (causalsData) {
  527. // Split the causals by | separator
  528. const causals = causalsData.split('|');
  529. // Clear the previous list
  530. $('#causalsList').empty();
  531. // Populate the modal with causals
  532. causals.forEach(function(causal) {
  533. if (causal.trim()) {
  534. $('#causalsList').append(
  535. '<li class="list-group-item">' +
  536. '<i class="fas fa-tags me-2" style="color: #0C6197;"></i>' +
  537. causal.trim() +
  538. '</li>'
  539. );
  540. }
  541. });
  542. // Show the modal with proper focus management
  543. $('#causalsModal').modal('show');
  544. // Ensure modal gets focus
  545. $('#causalsModal').on('shown.bs.modal', function () {
  546. $(this).find('.btn-close').focus();
  547. });
  548. }
  549. });
  550. // Close select2 dropdowns when modal is opening
  551. $('#causalsModal').on('show.bs.modal', function () {
  552. closeSelect2Dropdowns();
  553. $('body').addClass('modal-open');
  554. });
  555. // Clean up when modal is closed
  556. $('#causalsModal').on('hidden.bs.modal', function () {
  557. $('body').removeClass('modal-open');
  558. });
  559. });
  560. // Update the existing load function to include the new event handlers
  561. function load()
  562. {
  563. $(document).ready(function(){
  564. $(document).on("keypress", $('.filterCausals'), function (e) {
  565. setTimeout(() => {
  566. $(".select2-results__option").each(function(){
  567. var txt = $(this).html();
  568. var count = (txt.match(/-/g) || []).length;
  569. $(this).addClass('paddingLeftSelect' + count);
  570. });
  571. }, 100);
  572. });
  573. // Initialize select2 only if not already initialized
  574. if (!$('.filterCausals').hasClass('select2-hidden-accessible')) {
  575. $('.filterCausals').select2({
  576. "language": {"noResults": function(){return "Nessun risultato";}},
  577. "dropdownParent": $('body'),
  578. "width": "100%"
  579. });
  580. }
  581. $('.filterCausals').off('change.customHandler').on('change.customHandler', function (e) {
  582. var data = $('.filterCausals').select2("val");
  583. @this.set('filterCausals', data);
  584. });
  585. $('.filterCausals').off('select2:open.customHandler').on('select2:open.customHandler', function (e) {
  586. // Close modal if open when select2 opens
  587. if ($('#causalsModal').hasClass('show')) {
  588. $('#causalsModal').modal('hide');
  589. }
  590. setTimeout(() => {
  591. $(".select2-results__option").each(function(){
  592. var txt = $(this).html();
  593. var count = (txt.match(/-/g) || []).length;
  594. $(this).addClass('paddingLeftSelect' + count);
  595. });
  596. }, 100);
  597. });
  598. // Initialize select2 only if not already initialized
  599. if (!$('.filterMember').hasClass('select2-hidden-accessible')) {
  600. $('.filterMember').select2({
  601. "language": {"noResults": function(){return "Nessun risultato";}},
  602. "dropdownParent": $('body'),
  603. "width": "100%"
  604. });
  605. }
  606. $('.filterMember').off('change.customHandler').on('change.customHandler', function (e) {
  607. var data = $('.filterMember').select2("val");
  608. @this.set('filterMember', data);
  609. });
  610. $('.filterMember').off('select2:open.customHandler').on('select2:open.customHandler', function (e) {
  611. // Close modal if open when select2 opens
  612. if ($('#causalsModal').hasClass('show')) {
  613. $('#causalsModal').modal('hide');
  614. }
  615. });
  616. // Re-attach event handlers for "Varie" links after Livewire updates
  617. $(document).off('click', '.varie-link').on('click', '.varie-link', function(e) {
  618. e.preventDefault();
  619. e.stopPropagation();
  620. // Close any open select2 dropdowns safely
  621. $('.filterCausals').each(function() {
  622. if ($(this).hasClass('select2-hidden-accessible')) {
  623. $(this).select2('close');
  624. }
  625. });
  626. $('.filterMember').each(function() {
  627. if ($(this).hasClass('select2-hidden-accessible')) {
  628. $(this).select2('close');
  629. }
  630. });
  631. const causalsData = $(this).data('causals');
  632. if (causalsData) {
  633. const causals = causalsData.split('|');
  634. $('#causalsList').empty();
  635. causals.forEach(function(causal) {
  636. if (causal.trim()) {
  637. $('#causalsList').append(
  638. '<li class="list-group-item">' +
  639. '<i class="fas fa-tags me-2" style="color: #0C6197;"></i>' +
  640. causal.trim() +
  641. '</li>'
  642. );
  643. }
  644. });
  645. $('#causalsModal').modal('show');
  646. }
  647. });
  648. });
  649. }
  650. </script>
  651. @endpush