Forráskód Böngészése

Merge remote-tracking branch 'origin/iao_team' into iao_team_ferrari

ferrari 1 hónapja
szülő
commit
4d5b83266b

+ 12 - 1
app/Http/Livewire/CalendarRemove.php

@@ -7,11 +7,13 @@ use Livewire\Component;
 class CalendarRemove extends Component
 {
     public $records;
+    public $groups = [];
 
     public function render()
     {
         
         $this->records = [];
+        $this->groups = [];
 
         $calendars = \App\Models\Calendar::orderBy('from')->get();
         foreach($calendars as $calendar)
@@ -37,7 +39,15 @@ class CalendarRemove extends Component
             
             if ($members_count == 0)
             {
-                $this->records[] = array('id' => $calendar->id, 'date' => date("d/m/Y", strtotime($calendar->from)), "name" => $calendar->name, "hour" => date("H:i", strtotime($calendar->from)));
+
+                $hour = date("H:i", strtotime($calendar->from));
+
+                $x = ($calendar->course ? ($calendar->course->name . " ") : "") . $d . " " . $hour;
+                
+                if (!in_array($x, $this->groups))
+                    $this->groups[] = $x;
+
+                $this->records[] = array('id' => $calendar->id, 'date' => date("d/m/Y", strtotime($calendar->from)), "name" => $calendar->name, "hour" => $hour, "day" => $d);
             }
 
         }
@@ -52,6 +62,7 @@ class CalendarRemove extends Component
         {
             \App\Models\Calendar::findOrFail($id)->delete();
         }
+        return redirect()->to('/calendar_remove');        
 
     }
 

+ 59 - 5
resources/views/livewire/calendar_remove.blade.php

@@ -15,6 +15,11 @@
         <div class="col-12 mb-3">
             <h3 class="primary">Lezioni inserite senza nessun iscritto</h3>
         </div>
+        <div class="col-12">
+            @foreach($groups as $idx => $grp)
+                <a onclick="checkAll('{{$grp}}', {{$idx}})" class="btn btn-light bt{{$idx}}">{{$grp}}</a>
+            @endforeach
+        </div>
         <div class="col-12">
             <table class="report-table">
                 <thead>
@@ -29,7 +34,7 @@
                 <tbody>
                     @foreach($records as $record)
                     <tr>
-                        <td><input type="checkbox" value="{{$record["id"]}}" class="chk"></td>
+                        <td><input type="checkbox" value="{{$record["id"]}}" class="chk when_{{$record["name"]}}_{{$record["day"]}}_{{str_replace(":", "", $record["hour"])}}"></td>
                         <td>{{$record["date"]}}</td>
                         <td>{{$record["hour"]}}</td>
                         <td>{{$record["name"]}}</td>
@@ -38,7 +43,7 @@
                     @endforeach
                 </tbody>
                 <span id="deleting" style="display:none">Eliminazione in corso...</span>
-                <input type="button" class="btDelete btn--ui" value="Elimina">
+                <input type="button" class="btDelete btn--ui" value="Elimina selezionati">
             </table>
         </div>
     </div>
@@ -55,12 +60,13 @@
 
 @push('scripts')
 <script>
-    $(document).ready(function() {
 
-        var ids = [];
+    var ids = [];
+    var xxx = [];
+
+    $(document).ready(function() {
 
         $('.chk').change(function() {
-            console.log($(this).val());
             if(this.checked) 
             {
                 ids.push($(this).val());
@@ -75,11 +81,59 @@
             }
         }); 
 
+        
+
         $(".btDelete").click(function(){
             $("#deleting").show();
+            //$(this).hide();            
             @this.removeSelected(ids);      
         });
 
     });
+
+    function checkAll(x, idx)
+    {
+
+        var checked = true;
+
+        if ($(".bt" + idx).hasClass("btn-primary"))
+        {
+            $(".bt" + idx).removeClass("btn-primary");     
+            $(".bt" + idx).addClass("btn-light");       
+            checked = false;
+        }
+        else
+        {
+            $(".bt" + idx).removeClass("btn-light"); 
+            $(".bt" + idx).addClass("btn-primary");
+        }
+
+        /*var index = xxx.indexOf(x);
+        if (index > -1) 
+        {
+            xxx.splice(index, 1);
+            checked = false;
+        }*/
+
+        x = x.replaceAll(" ", "_");
+        x = x.replaceAll(":", "");
+        console.log(x);
+        var xxx = $(".when_" + x).map(function() {
+            console.log("CIAO");
+            var val = $(this).val();
+            $(this).prop('checked', checked);
+            if (checked)
+                ids.push(val);
+            else
+            {
+                var index = ids.indexOf(val);
+                if (index > -1) 
+                {
+                    ids.splice(index, 1);
+                }
+            }
+            //return this.innerHTML;
+        }).get();
+    }
 </script>
 @endpush