[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: IcingaServiceForm: improve apply handling

git at icinga.org git at icinga.org
Wed May 25 11:25:28 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: 2f603855558b0ebd30f05a920f34e37cf186eb28
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=2f603855558b0ebd30f05a920f34e37cf186eb28

Author: Thomas Gelf <thomas at gelf.net>
Date:   Wed May 25 08:14:00 2016 +0200

IcingaServiceForm: improve apply handling

---

 application/controllers/ServiceController.php |   16 +---------------
 application/forms/IcingaServiceForm.php       |   19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php
index 4aa1144..3b51fa6 100644
--- a/application/controllers/ServiceController.php
+++ b/application/controllers/ServiceController.php
@@ -67,15 +67,6 @@ class ServiceController extends ObjectController
                 $this->translate('Apply "%s"'),
                 $this->apply->object_name
             );
-
-            $form = $this->view->form;
-            if (!$form->hasBeenSent()) {
-                $form->populate(array(
-                    'imports'     => $this->apply->object_name,
-                    'object_name' => $this->apply->object_name,
-                    'object_type' => 'apply',
-                ));
-            }
         }
     }
 
@@ -83,12 +74,7 @@ class ServiceController extends ObjectController
     {
         if ($this->apply) {
             if (!$form->hasBeenSent()) {
-                $form->populate(array(
-                    'imports'     => $this->apply->object_name,
-                    'object_name' => $this->apply->object_name,
-                    'object_type' => 'apply',
-                ));
-                $form->getObject()->object_type = 'apply';
+                $form->createApplyRuleFor($this->apply);
             }
         }
     }
diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php
index 08a351e..b934ad5 100644
--- a/application/forms/IcingaServiceForm.php
+++ b/application/forms/IcingaServiceForm.php
@@ -4,11 +4,14 @@ namespace Icinga\Module\Director\Forms;
 
 use Icinga\Module\Director\Web\Form\DirectorObjectForm;
 use Icinga\Module\Director\Objects\IcingaHost;
+use Icinga\Module\Director\Objects\IcingaService;
 
 class IcingaServiceForm extends DirectorObjectForm
 {
     private $host;
 
+    private $apply;
+
     public function setup()
     {
         if (!$this->isNew() && $this->host === null) {
@@ -22,9 +25,23 @@ class IcingaServiceForm extends DirectorObjectForm
         }
     }
 
+    public function createApplyRuleFor(IcingaService $service)
+    {
+        $this->apply = $service;
+        $object = $this->object();
+        $object->imports = $service->object_name;
+        $object->object_type = 'apply';
+        $object->object_name = $service->object_name;
+        return $this;
+    }
+
     protected function setupServiceElements()
     {
-        $this->addHidden('object_type', 'template');
+        if ($this->object) {
+            $this->addHidden('object_type', $this->object->object_type);
+        } else {
+            $this->addHidden('object_type', 'template');
+        }
 
         $this->addNameElement()
              ->addHostObjectElement()



More information about the icinga-checkins mailing list