瀏覽代碼

membri - aggiunto checkbox multipla per archiviazione/ripristino

ferrari 1 月之前
父節點
當前提交
a7f3da34b8

+ 24 - 5
app/Http/Livewire/Member.php

@@ -2633,7 +2633,20 @@ class Member extends Component
         }
         return $ret;
     }
-    public function archive($id)
+
+    public function archiveMultiple($ids) {
+        $success = true;
+        foreach ($ids as $id) {
+            $success = $this->archive($id, true);
+            if (!$success) break;
+        }
+        if ($success) {
+            session()->flash('success', 'Membri archiviati con successo');
+            $this->emit('reload');
+        }
+    }
+
+    public function archive($id, $bulk = false)
     {
         try {
             $member = \App\Models\Member::findOrFail($id);
@@ -2648,10 +2661,10 @@ class Member extends Component
 
             updateMemberData($id);
 
-            session()->flash('success', 'Membro archiviato con successo');
-
-            $this->emit('reload');
-
+            if (!$bulk) {
+                session()->flash('success', 'Membro archiviato con successo');
+                $this->emit('reload');
+            }
         } catch (\Exception $e) {
             session()->flash('error', 'Errore durante l\'archiviazione: ' . $e->getMessage());
             Log::error('Archive member error', [
@@ -2659,7 +2672,13 @@ class Member extends Component
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
+
+            if ($bulk) {
+                return false;
+            }
         }
+
+        return true;
     }
 }
 

+ 48 - 9
app/Http/Livewire/MemberArchive.php

@@ -30,7 +30,20 @@ class MemberArchive extends Component
                 $this->getCategories($record->childs, $indentation + 1);
         }
     }
-    public function restore($id)
+    
+    public function restoreMultiple($ids) {
+        $success = true;
+        foreach ($ids as $id) {
+            $success = $this->restore($id, true);
+            if (!$success) break;
+        }
+        if ($success) {
+            session()->flash('success', 'Membri ripristinati con successo');
+            $this->emit('reload');
+        }
+    }
+
+    public function restore($id, $bulk = false)
     {
         try {
             $member = \App\Models\Member::findOrFail($id);
@@ -44,20 +57,39 @@ class MemberArchive extends Component
 
             updateMemberData($id);
 
-            session()->flash('success', 'Membro riattivato con successo');
-
-            $this->emit('reload');
+            if (!$bulk) {
+                session()->flash('success', 'Membro ripristinato con successo');
+                $this->emit('reload');
+            }
         } catch (\Exception $e) {
-            session()->flash('error', 'Errore durante la riattivazione: ' . $e->getMessage());
+            session()->flash('error', 'Errore durante il ripristino: ' . $e->getMessage());
             Log::error('Restore member error', [
                 'member_id' => $id,
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
+
+            if ($bulk) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+    
+    public function archiveMultiple($ids) {
+        $success = true;
+        foreach ($ids as $id) {
+            $success = $this->archive($id, true);
+            if (!$success) break;
+        }
+        if ($success) {
+            session()->flash('success', 'Membri archiviati con successo');
+            $this->emit('reload');
         }
     }
 
-    public function archive($id)
+    public function archive($id, $bulk = false)
     {
         try {
             $member = \App\Models\Member::findOrFail($id);
@@ -119,9 +151,10 @@ class MemberArchive extends Component
 
             updateMemberData($id);
 
-            session()->flash('success', 'Membro archiviato con successo');
-
-            $this->emit('reload');
+            if (!$bulk) {
+                session()->flash('success', 'Membro archiviato con successo');
+                $this->emit('reload');
+            }
         } catch (\Exception $e) {
             session()->flash('error', 'Errore durante l\'archiviazione: ' . $e->getMessage());
             Log::error('Archive member error', [
@@ -129,6 +162,12 @@ class MemberArchive extends Component
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
+
+            if ($bulk) {
+                return false;
+            }
         }
+
+        return true;
     }
 }

+ 20 - 0
public/css/style.css

@@ -16831,4 +16831,24 @@ button.download-png {
     position: absolute;
     top: 0;
     right: 0;
+}
+
+.btn-group:has(.archive-multiple-btn) > .btn-group > .btn {
+    border-radius: var(--bs-btn-border-radius);
+}
+
+#btnArchive,
+#btnRestore {
+    border-radius: var(--bs-btn-border-radius);
+    background-color: #0c6197 !important;
+    color: #ffffff;
+    padding-inline: 18px;
+    font-size: 17px;
+    line-height: 1;
+    margin-left: 5px;
+}
+
+#btnArchive:hover,
+#btnRestore:hover {
+    background-color: #0e70af !important;
 }

+ 65 - 4
resources/views/livewire/member.blade.php

@@ -392,8 +392,7 @@
                     <table class="table tablesaw tableHead tablesaw-stack table--lista_utenti tableHead" width="100%" id="tablesaw-350" width="100%">
                         <thead>
                             <tr>
-                                <!--<th scope="col">#</th>-->
-
+                                <th scope="col"><input type="checkbox" name="chkAll" class="chkAll"></th>
                                 <th scope="col" style="text-align: center">Cognome</th>
                                 <th scope="col">Nome</th>
                                 <th scope="col">Telefono</th>
@@ -408,7 +407,7 @@
                             @if(false)
                             @foreach($records as $idx => $record)
                                 <tr>
-                                    <td> <label><input class="table-check" type="checkbox" wire:model="multipleIds" value="{{$record->id}}"><span class="sr-only d-inline-block d-lg-none ms-2 mobile-row-selector"> Seleziona riga</span></label></td>
+                                    <td><label><input class="table-check" type="checkbox" wire:model="multipleIds" value="{{$record->id}}"><span class="sr-only d-inline-block d-lg-none ms-2 mobile-row-selector"> Seleziona riga</span></label></td>
                                     <td>{{ ($idx + 1) }}</td>
                                     <td>ID{{str_pad($record->id, 5, "0", STR_PAD_LEFT)}}</td>
                                     <td><a href="#" wire:click="showDetail({{$record->id}})">{{$record->last_name}}</a></td>
@@ -2291,6 +2290,19 @@
                 @this.delete(id);
         }
 
+        function archiveMultipleData()
+        {
+            var ids = [];
+            $(".chkIds").each(function () {
+                if (this.checked) ids.push($(this).val());
+            });
+
+            if (ids.length) {
+                if (confirm('Sei sicuro? Gli utenti non saranno più visibili ma potranno essere ripristinati dalla sezione Archivio.'))
+                    @this.archiveMultiple(ids);
+            }
+        }
+
         function archiveData(id)
         {
             if (confirm('Sei sicuro? L\'utente non sarà più visibile ma potrà essere ripristinato dalla sezione Archivio.'))
@@ -2478,6 +2490,14 @@
                 serverSide: true,
                 ajax: '/get_members?cards=' + filterCards + "&filterCategories=" + filterCategories + "&filterCertificateType=" + filterCertificateType + "&filterScadenza=" + filterScadenza + "&filterStatus=" + filterStatus + "&fromYear=" + fromYear + "&toYear=" + toYear + "&fromYearYear=" + fromYearYear + "&toYearYear=" + toYearYear,
                 columns: [
+                    {
+                        data: "member_id",
+                        orderable: false,
+                        render: function (data){
+                            var ret = '<input type="checkbox" name="chk'+data+'" value="'+data+'" class="chkIds" onchange="updateMultipleSelection()">';
+                            return ret;
+                        }
+                    },
                     {
                         data: "last_name",
                         render: function (data){
@@ -2586,7 +2606,20 @@
                                     }
                                 ],
                                 dropup: true
-                            }
+                            },
+                            {
+                                text: '<i class="fa-regular fa-folder-closed"></i>',
+                                attr: {
+                                    id: 'btnArchive',
+                                    style: 'display: none',
+                                    onclick: 'archiveMultipleData()',
+                                    class: 'btn archive-multiple-btn',
+                                    "data-bs-toggle":"popover",
+                                    "data-bs-trigger":"hover focus",
+                                    "data-bs-placement":"bottom",
+                                    "data-bs-content":"Archivia",
+                                }
+                            },
                         ]
                     },
                     top1B : {
@@ -2612,6 +2645,34 @@
             $('#tablesaw-350').on('draw.dt', function() {
                 $('[data-bs-toggle="popover"]').popover()
             });
+
+            $(".chkAll").change(function () {
+                var check = this.checked;
+                var ok = false;
+                $(".chkIds").each(function () {
+                    $(this).prop("checked", check);
+                    ok = true;
+                });
+                if (check && ok) {
+                    $("#btnArchive").show();
+                } else {
+                    $("#btnArchive").hide();
+                }
+            });
+        }
+
+        function updateMultipleSelection() {
+            let checked = false;
+            $(".chkIds").each(function () {
+                if (this.checked) checked = true;
+            });                
+
+            if (checked) {
+                $("#btnArchive").show();
+            } else {
+                $("#btnArchive").hide();
+                $(".chkAll").prop("checked", false);
+            }
         }
 
         $(document).ready(function() {

+ 103 - 10
resources/views/livewire/member_archive.blade.php

@@ -153,6 +153,7 @@
             <table class="table tablesaw tableHead tablesaw-stack table--lista_utenti tableHead" width="100%" id="tablesaw-350" width="100%">
                 <thead>
                     <tr>
+                        <th scope="col"><input type="checkbox" name="chkAll" class="chkAll"></th>
                         <th scope="col" style="text-align: center">Cognome</th>
                         <th scope="col">Nome</th>
                         <th scope="col">Telefono</th>
@@ -290,12 +291,38 @@
 
 @push('scripts')
     <script>
+        function restoreMultipleData()
+        {
+            var ids = [];
+            $(".chkIds").each(function () {
+                if (this.checked) ids.push($(this).val());
+            });
+
+            if (ids.length) {
+                if (confirm('Sei sicuro? Gli utenti verranno ripristinati.'))
+                    @this.restoreMultiple(ids);
+            }
+        }
+
         function restoreData(id)
         {
             if (confirm('Sei sicuro? L\'utente verrà ripristinato.'))
                 @this.restore(id);
         }
 
+        function archiveMultipleData()
+        {
+            var ids = [];
+            $(".chkIds").each(function () {
+                if (this.checked) ids.push($(this).val());
+            });
+
+            if (ids.length) {
+                if (confirm('Sei sicuro? Tutti i dati relativi a questi utenti verranno archiviati e non saranno più visibili.'))
+                    @this.archiveMultiple(ids);
+            }
+        }
+
         function archiveData(id)
         {
             if (confirm('Sei sicuro? Tutti i dati relativi a questo utente verranno archiviati e non saranno più visibili.'))
@@ -462,6 +489,14 @@
                 processing: true,
                 ajax: url,
                 columns: [
+                    {
+                        data: "member_id",
+                        orderable: false,
+                        render: function (data){
+                            var ret = '<input type="checkbox" name="chk'+data+'" value="'+data+'" class="chkIds" onchange="updateMultipleSelection()">';
+                            return ret;
+                        }
+                    },
                     {
                         data: "last_name",
                         render: function (data){
@@ -537,16 +572,16 @@
                     topStart : null,
                     topEnd : null,
                     top1A: {
-                        // buttons: [
-                        //     {
-                        //         extend: 'collection',
-                        //         text: 'ESPORTA',
+                        buttons: [
+                            {
+                                extend: 'collection',
+                                text: 'ESPORTA',
                                 buttons: [
                                     {
                                         extend: 'excelHtml5',
                                         text: '<i class="fa-solid fa-file-excel"></i>',
                                         action: newexportaction,
-                                        title: date_export + 'Utenti archiviati',
+                                        title: 'Utenti archiviati',
                                         exportOptions: {
                                             columns: ":not(':last')",
                                             page: 'all'
@@ -556,7 +591,7 @@
                                         extend: 'pdfHtml5',
                                         text: '<i class="fa-solid fa-file-pdf"></i>',
                                         action: newexportaction,
-                                        title: date_export + 'Utenti archiviati',
+                                        title: 'Utenti archiviati',
                                         exportOptions: {
                                             columns: ":not(':last')"
                                         },
@@ -568,15 +603,41 @@
                                         extend: 'print',
                                         action: newexportaction,
                                         text: '<i class="fa-solid fa-print"></i>',
-                                        title: date_export + 'Utenti archiviati',
+                                        title: 'Utenti archiviati',
                                         exportOptions: {
                                             columns: ":not(':last')"
                                         }
                                     }
                                 ],
-                        //         dropup: true
-                        //     }
-                        // ]
+                                dropup: true
+                            },
+                            {
+                                text: '<i class="fa-solid fa-rotate-left"></i>',
+                                attr: {
+                                    id: 'btnRestore',
+                                    style: 'display: none',
+                                    onclick: 'restoreMultipleData()',
+                                    class: 'btn archive-multiple-btn',
+                                    "data-bs-toggle":"popover",
+                                    "data-bs-trigger":"hover focus",
+                                    "data-bs-placement":"bottom",
+                                    "data-bs-content":"Ripristina",
+                                }
+                            },
+                            {
+                                text: '<i class="fa-regular fa-trash-can"></i>',
+                                attr: {
+                                    id: 'btnArchive',
+                                    style: 'display: none',
+                                    onclick: 'archiveMultipleData()',
+                                    class: 'btn archive-multiple-btn',
+                                    "data-bs-toggle":"popover",
+                                    "data-bs-trigger":"hover focus",
+                                    "data-bs-placement":"bottom",
+                                    "data-bs-content":"Archivia",
+                                }
+                            },
+                        ]
                     },
                     top1B : {
                         pageLength: {
@@ -603,6 +664,38 @@
             $('#tablesaw-350').on('draw.dt', function() {
                 $('[data-bs-toggle="popover"]').popover()
             });
+
+            $(".chkAll").change(function () {
+                var check = this.checked;
+                var ok = false;
+                $(".chkIds").each(function () {
+                    $(this).prop("checked", check);
+                    ok = true;
+                });
+                if (check && ok) {
+                    $("#btnRestore").show();
+                    $("#btnArchive").show();
+                } else {
+                    $("#btnRestore").hide();
+                    $("#btnArchive").hide();
+                }
+            });
+        }
+
+        function updateMultipleSelection() {
+            let checked = false;
+            $(".chkIds").each(function () {
+                if (this.checked) checked = true;
+            });                
+
+            if (checked) {
+                $("#btnRestore").show();
+                $("#btnArchive").show();
+            } else {
+                $("#btnRestore").hide();
+                $("#btnArchive").hide();
+                $(".chkAll").prop("checked", false);
+            }
         }
 
         Livewire.on('reload', (x) =>

+ 2 - 1
routes/web.php

@@ -488,7 +488,8 @@ Route::get('/get_members', function () {
 
         $datas[] = array(
             //'c' => $idx + 1,
-            //'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
+            // 'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
+            'member_id' => $r->id,
             'last_name' => $r->last_name . "|" . $r->id,
             'first_name' => $r->first_name . "|" . $r->id,
             'phone' => $r->phone,