瀏覽代碼

fix allegati

FabioFratini 10 月之前
父節點
當前提交
5fd35cfa57

+ 12 - 0
app/Http/Livewire/Traits/HasAllegato.php

@@ -140,4 +140,16 @@ trait HasAllegato
         $this->emit('attachments', implode("|", $this->allegatiFiles));
         $this->allegati = [];
     }
+
+    public function removeFile($filename)
+    {
+        $index = array_search($filename, $this->allegatiFiles);
+        if ($index !== false) {
+            unset($this->allegatiFiles[$index]);
+            $this->allegatiFiles = array_values($this->allegatiFiles);
+            $this->emit('attachments', implode("|", $this->allegatiFiles));
+        }
+    }
+
 }
+

+ 0 - 23
resources/views/components/report/allegati/allegati-modal.blade.php

@@ -118,29 +118,6 @@
                 window.livewire.emit('refresh');
             }, 200);
         });
-
-        document.getElementById('allegati').addEventListener('change', function(e) {
-            const maxFileSize = 2 * 1024 * 1024; // 2MB in bytes
-            const errorElement = document.getElementById('file-size-error');
-            errorElement.style.display = 'none';
-            errorElement.textContent = '';
-
-            if (this.files.length > 0) {
-                for (let i = 0; i < this.files.length; i++) {
-                    const file = this.files[i];
-                    console.log('File ' + (i+1) + ' size: ' + file.size + ' bytes');
-
-                    if (file.size > maxFileSize) {
-                        errorElement.style.display = 'block';
-                        errorElement.textContent = 'Errore: Il file "' + file.name + '" è troppo grande (' +
-                            Math.round(file.size / 1024 / 1024 * 10) / 10 + 'MB). La dimensione massima è 2MB.';
-                        // Clear the file input
-                        this.value = '';
-                        return;
-                    }
-                }
-            }
-        });
     });
 </script>
 @endpush