Просмотр исходного кода

fix popup uscita sezione fornitori

ferrari 4 месяцев назад
Родитель
Сommit
272918d54d
2 измененных файлов с 17 добавлено и 1 удалено
  1. 7 0
      app/Http/Livewire/Supplier.php
  2. 10 1
      resources/views/livewire/supplier.blade.php

+ 7 - 0
app/Http/Livewire/Supplier.php

@@ -124,6 +124,7 @@ class Supplier extends Component
         $this->emit('load-select');
         $this->add = true;
         $this->update = false;
+        $this->emit('setEdit', true);
     }
 
     private function cleanEmptyFields()
@@ -192,6 +193,7 @@ class Supplier extends Component
             session()->flash('success', 'Fornitore creato');
             $this->resetFields();
             $this->add = false;
+            $this->emit('setEdit', false);
         } catch (\Exception $ex) {
             session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
         }
@@ -229,6 +231,8 @@ class Supplier extends Component
                 $this->checkIsItaly();
                 $this->emit('load-provinces', $this->nation_id, 'provinceClass');
                 $this->emit('load-cities', $this->province_id, 'cityClass');
+
+                $this->emit('setEdit', true);
             }
         } catch (\Exception $ex) {
             session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
@@ -240,6 +244,7 @@ class Supplier extends Component
         $this->add = false;
         $this->update = false;
         $this->resetFields();
+        $this->emit('setEdit', false);
     }
 
     // Replace delete method with anonymize method
@@ -345,6 +350,8 @@ class Supplier extends Component
             session()->flash('success', 'Fornitore aggiornato');
             $this->resetFields();
             $this->update = false;
+
+            $this->emit('setEdit', false);
         } catch (\Exception $ex) {
             session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
         }

+ 10 - 1
resources/views/livewire/supplier.blade.php

@@ -259,6 +259,13 @@
 
 @push('scripts')
     <script>
+        var isEdit = false;
+        Livewire.on('setEdit', (x) =>
+        {
+            isEdit = x;
+            console.log(isEdit);
+        });
+
         function matchStart(params, data) {
             params.term = params.term || '';
             if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
@@ -276,7 +283,9 @@
         }
 
         window.onbeforeunload = function(){
-            return 'Cambiando pagina le eventuali modifiche andranno perse';
+            if (isEdit) {
+                return 'Cambiando pagina le eventuali modifiche andranno perse';
+            }
         };
 
         Livewire.on('load-select', () => {