From ba4cf2eb10714d775bf8989054588a62915b4c3b Mon Sep 17 00:00:00 2001
From: Thibault Dockx <thibault.dockx@fusiondirectory.org>
Date: Tue, 28 May 2024 11:19:06 +0100
Subject: [PATCH] :sparkles: (templateDialog)

Adds auto saving in case no errors occurs and open the tab where errors is otherwise.
---
 include/management/class_templateDialog.inc | 22 ++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/include/management/class_templateDialog.inc b/include/management/class_templateDialog.inc
index 1ac237364..f0c8fecbe 100644
--- a/include/management/class_templateDialog.inc
+++ b/include/management/class_templateDialog.inc
@@ -122,11 +122,23 @@ class templateDialog implements FusionDirectoryDialog
     return $display;
   }
 
-  protected function handleFinish ()
-  {
-    $this->management->closeDialogs();
-    $this->management->openTabObject($this->template->apply());
-  }
+    /**
+     * @return void
+     * Note : The idea is to handle the save directly at the end of the validation of the template data.
+     * Allowing direct saving in case of no error and opening the UI at the exact tab in case of error.
+     */
+    protected function handleFinish ()
+    {
+        $this->management->closeDialogs();
+        $tab = $this->template->apply();
+        $errors = $tab->save();
+
+        if (!empty($errors)) {
+            $this->management->openTabObject($tab);
+            msg_dialog::displayChecks($errors);
+        }
+    }
+
 
   protected function handleCancel ()
   {
-- 
GitLab