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

fix popup uscita sezione fornitori

ferrari 4 месяцев назад
Родитель
Сommit
14898e6ef8
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

@@ -107,6 +107,7 @@ class Supplier extends Component
         $this->emit('load-select');
         $this->add = true;
         $this->update = false;
+        $this->emit('setEdit', true);
     }
 
     public function store()
@@ -169,6 +170,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() . ')');
         }
@@ -205,6 +207,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() . ')');
@@ -238,6 +242,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() . ')');
         }
@@ -248,6 +254,7 @@ class Supplier extends Component
         $this->add = false;
         $this->update = false;
         $this->resetFields();
+        $this->emit('setEdit', false);
     }
 
     public function delete($id)

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

@@ -284,6 +284,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) {
@@ -301,7 +308,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', () => {