ferrari 1 месяц назад
Родитель
Сommit
25104a05ce

+ 21 - 1
app/Http/Livewire/EmailComunications.php

@@ -90,7 +90,10 @@ class EmailComunications extends Component
 
     protected function validateDraft(): void
     {
-        $this->validate($this->baseRules());
+        $rules = [];
+        // $rules = $this->baseRules();
+        $rules['subject'] = 'required|string|max:255';
+        $this->validate($rules);
     }
 
     protected function validateSend(): void
@@ -137,6 +140,13 @@ class EmailComunications extends Component
                 'first_name'    => optional($r->member)->first_name,
                 'last_name'     => optional($r->member)->last_name,
             ])->toArray();
+            usort($this->recipients, function($a, $b) {
+                $last_name = strcmp($a['last_name'], $b['last_name']);
+                $first_name = strcmp($a['first_name'], $b['first_name']);
+
+                return $last_name == 0 ? $first_name : $last_name;
+            });
+
             $this->mode = $msg->status === 'scheduled' ? 'schedule' : 'now';
             $this->schedule_at = optional($msg->schedule_at)?->setTimezone($this->timezone)?->format('Y-m-d\TH:i');
             $this->existingAttachments = $msg->attachments->map(fn($a) => [
@@ -190,6 +200,7 @@ class EmailComunications extends Component
 
         $this->success = 'Bozza salvata';
 
+        $this->dispatchBrowserEvent('scroll-top');
         $this->dispatchBrowserEvent('load-editor', [
             'html'   => $this->content_html ?? '',
             'locked' => $this->locked,
@@ -221,6 +232,7 @@ class EmailComunications extends Component
         dispatch(new \App\Jobs\SendEmailMessage($this->messageId));
         $this->success = 'Invio avviato';
 
+        $this->dispatchBrowserEvent('scroll-top');
         $this->dispatchBrowserEvent('load-editor', [
             'html'   => $this->content_html ?? '',
             'locked' => $this->locked,
@@ -253,6 +265,7 @@ class EmailComunications extends Component
 
         $this->success = 'Email programmata';
 
+        $this->dispatchBrowserEvent('scroll-top');
         $this->dispatchBrowserEvent('load-editor', [
             'html'   => $this->content_html ?? '',
             'locked' => $this->locked,
@@ -357,6 +370,13 @@ class EmailComunications extends Component
             'first_name' => $m->first_name,
             'last_name' => $m->last_name,
         ];
+
+        usort($this->recipients, function($a, $b) {
+            $last_name = strcmp($a['last_name'], $b['last_name']);
+            $first_name = strcmp($a['first_name'], $b['first_name']);
+
+            return $last_name == 0 ? $first_name : $last_name;
+        });
     }
 
     public function removeNewAttachment(int $index): void

+ 10 - 1
app/Http/Livewire/SmsComunications.php

@@ -81,7 +81,10 @@ class SmsComunications extends Component
 
     protected function validateDraft(): void
     {
-        $this->validate($this->baseRules());
+        $rules = [];
+        // $rules = $this->baseRules();
+        $rules['subject'] = 'required|string|max:255';
+        $this->validate($rules);
     }
 
     protected function validateSend(): void
@@ -161,6 +164,8 @@ class SmsComunications extends Component
         });
 
         $this->success = 'Bozza salvata';
+
+        $this->dispatchBrowserEvent('scroll-top');
     }
 
     public function sendNow()
@@ -184,6 +189,8 @@ class SmsComunications extends Component
 
         dispatch(new \App\Jobs\SendSmsMessage($this->messageId));
         $this->success = 'Invio avviato';
+
+        $this->dispatchBrowserEvent('scroll-top');
     }
 
     public function scheduleMessage()
@@ -208,6 +215,8 @@ class SmsComunications extends Component
         });
 
         $this->success = 'Sms programmato';
+
+        $this->dispatchBrowserEvent('scroll-top');
     }
 
     protected function upsertMessage(string $status, $scheduleAt): SmsMessage

+ 4 - 4
resources/views/layouts/app.blade.php

@@ -224,14 +224,14 @@
                 print "Profilo Utente";
             if (Request::is('reports'))
                 print "Reports";
-            if (Request::is('sms_comunications'))
-                print "Comunicazioni SMS";
-            if (Request::is('email_comunications'))
-                print "Comunicazioni Email";
             if (Request::is('subscriptions'))
                 print "Abbonamenti";
             if (Request::is('subscription_member', 'subscription_member/*'))
                 print "Abbonamenti";
+            if (Request::is('mail_comunications'))
+                print "Email";
+            if (Request::is('sms_comunications'))
+                print "Sms";
             @endphp
             </h3>
 

+ 43 - 36
resources/views/livewire/email_comunications.blade.php

@@ -697,7 +697,7 @@
                 { data: "categories" },
             ],
             order: [
-                [1, 'desc']
+                [1, 'asc']
             ],
             fixedHeader: false,
             thead: {
@@ -745,45 +745,52 @@
 import { ClassicEditor } from "ckeditor5";
 import { editorConfig } from "/assets/libraries/ckeditor5/config.js";
 
-window.addEventListener("load-editor", (e) => {
-    let detail = e.detail || {};
-    let latestLocked = !!detail.locked;
-    let html = detail.html ?? '';
+    window.addEventListener("load-editor", (e) => {
+        let detail = e.detail || {};
+        let latestLocked = !!detail.locked;
+        let html = detail.html ?? '';
 
-    let el = document.querySelector('#message');
-    if (el.ckeditorInstance) el.ckeditorInstance.destroy();
-    
-    editorConfig.simpleUpload = {
-        uploadUrl: "{{ route('ckeditor.upload', ['_token' => csrf_token()]) }}"
-    };
+        let el = document.querySelector('#message');
+        if (el.ckeditorInstance) el.ckeditorInstance.destroy();
+        
+        editorConfig.simpleUpload = {
+            uploadUrl: "{{ route('ckeditor.upload', ['_token' => csrf_token()]) }}"
+        };
+
+        ClassicEditor
+            .create(el, editorConfig)
+            .then(editor => {
+                el.ckeditorInstance = editor;
+
+                editor.setData(html);
+
+                if (latestLocked) {
+                    editor.enableReadOnlyMode('locked');
+                    return;
+                }
+            })
+            .catch(console.error)
+    });
 
-    ClassicEditor
-        .create(el, editorConfig)
-        .then(editor => {
-            el.ckeditorInstance = editor;
+    window.submitEmail = function(action){
+        const ed = document.querySelector('#message')?.ckeditorInstance;
+        const html = ed ? ed.getData() : '';
 
-            editor.setData(html);
+        if (action === 'draft') {
+            @this.call('saveDraft', html);
+        } else if (action === 'send') {
+            @this.call('sendNow', html);
+        } else {
+            @this.call('scheduleMessage', html);
+        }
+    };
 
-            if (latestLocked) {
-                editor.enableReadOnlyMode('locked');
-                return;
-            }
-        })
-        .catch(console.error)
-});
-
-window.submitEmail = function(action){
-    const ed = document.querySelector('#message')?.ckeditorInstance;
-    const html = ed ? ed.getData() : '';
-
-    if (action === 'draft') {
-        @this.call('saveDraft', html);
-    } else if (action === 'send') {
-        @this.call('sendNow', html);
-    } else {
-        @this.call('scheduleMessage', html);
-    }
-};
+    window.addEventListener("scroll-top", (e) => {
+        let wrapper = document.querySelector('#card--dashboard');
+        if (wrapper) {
+            wrapper.scrollTo({top: 0, behavior: 'smooth'});
+        }
+    });
 </script>
 
 {{-- END CKEditor --}}

+ 8 - 1
resources/views/livewire/sms_comunications.blade.php

@@ -623,7 +623,7 @@
                 { data: "categories" },
             ],
             order: [
-                [1, 'desc']
+                [1, 'asc']
             ],
             fixedHeader: false,
             thead: {
@@ -666,6 +666,13 @@
             @this.call('scheduleMessage');
         }
     };
+
+    window.addEventListener("scroll-top", (e) => {
+        let wrapper = document.querySelector('#card--dashboard');
+        if (wrapper) {
+            wrapper.scrollTo({top: 0, behavior: 'smooth'});
+        }
+    });
 </script>
 
 {{-- END CKEditor --}}

+ 7 - 13
routes/web.php

@@ -762,41 +762,35 @@ Route::group(['middleware' => 'tenant'], function () {
 
         if (isset($_GET["order"])) {
             $column = '';
-            if ($_GET["order"][0]["column"] == 0)
-                $column = 'last_name';
             if ($_GET["order"][0]["column"] == 1)
-                $column = 'first_name';
+                $column = 'last_name';
             if ($_GET["order"][0]["column"] == 2)
-                $column = 'email';
+                $column = 'first_name';
             if ($_GET["order"][0]["column"] == 3)
-                $column = 'phone';
+                $column = 'email';
             if ($_GET["order"][0]["column"] == 4)
-                $column = 'birth_date';
+                $column = 'phone';
             if ($_GET["order"][0]["column"] == 5)
                 $column = 'birth_date';
             if ($_GET["order"][0]["column"] == 6)
-                $column = 'current_status';
+                $column = 'birth_date';
             if ($_GET["order"][0]["column"] == 7)
+                $column = 'current_status';
+            if ($_GET["order"][0]["column"] == 8)
                 $column = 'certificate';
 
             if ($column != '') {
-                if ($column == 'last_name') {
-                    $x = $x->orderBy('to_complete', 'DESC');
-                }
                 if ($column == 'certificate')
                     $x = $x->orderBy('certificate_date', $_GET["order"][0]["dir"]);
                 elseif ($column == 'current_status') {
-                    $x = $x->orderBy('to_complete', 'DESC');
                     $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
                 } else {
                     $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
                 }
             } else {
-                $x = $x->orderBy('to_complete', 'DESC');
                 $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
             }
         } else {
-            $x = $x->orderBy('to_complete', 'DESC');
             $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
         }