[icinga-checkins] icinga.org: icingaweb2-module-director/feature/better-job-form-12971: DirectorJobForm: better change detection, kind of

git at icinga.org git at icinga.org
Tue Oct 25 00:00:42 CEST 2016


Module: icingaweb2-module-director
Branch: feature/better-job-form-12971
Commit: bf5d04a71a152fd06aae5537ff74d46c342a7e8b
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=bf5d04a71a152fd06aae5537ff74d46c342a7e8b

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Oct 24 21:23:50 2016 +0000

DirectorJobForm: better change detection, kind of

---

 application/forms/DirectorJobForm.php |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/application/forms/DirectorJobForm.php b/application/forms/DirectorJobForm.php
index 84604ac..f5cb3a9 100644
--- a/application/forms/DirectorJobForm.php
+++ b/application/forms/DirectorJobForm.php
@@ -25,6 +25,17 @@ class DirectorJobForm extends DirectorObjectForm
             return;
         }
 
+        $oldJobClass = $this->getSentValue('former_job_class');
+        $this->addHidden('former_job_class', $jobClass);
+        $this->setSentValue('former_job_class', $jobClass);
+
+        if ($oldJobClass !== $jobClass) {
+            //var_dump('CHANGED');
+            $jobClassChanged = true;
+        } else {
+            $jobClassChanged = false;
+        }
+
         if ($desc = $jobClass::getDescription($this)) {
             $this->addHtmlHint($desc);
         }
@@ -75,6 +86,16 @@ class DirectorJobForm extends DirectorObjectForm
             'required'    => true,
         ));
 
+        $jobName = $this->getSentValue('job_name');
+        $hasNoJobName = ! strlen($jobName) || in_array($jobName, $jobTypes);
+
+        if ($jobClassChanged && $hasNoJobName) {
+            $this->setSentValue(
+                'job_name',
+                $jobTypes[$jobClass]
+            );
+        }
+
         $this->addSettings();
         $this->setButtons();
     }



More information about the icinga-checkins mailing list