[icinga-checkins] icinga.org: icingaweb2-module-director/master: DirectorObjectForm: prepare object type access

git at icinga.org git at icinga.org
Thu Feb 4 16:53:56 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: ac6464c5e4a52fd745145316b863cf59f84e8b84
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=ac6464c5e4a52fd745145316b863cf59f84e8b84

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Feb  4 16:52:34 2016 +0100

DirectorObjectForm: prepare object type access

Introduces addObjectTypeElement(), this will allow for context- and
permission-dependent forms. We will then finally get rid of the "Add
object / template" distinction.

---

 library/Director/Web/Form/DirectorObjectForm.php |   37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php
index bb0a50d..623970b 100644
--- a/library/Director/Web/Form/DirectorObjectForm.php
+++ b/library/Director/Web/Form/DirectorObjectForm.php
@@ -789,6 +789,43 @@ abstract class DirectorObjectForm extends QuickForm
         return $this;
     }
 
+    protected function addObjectTypeElement()
+    {
+        $default = 'object';
+
+        if ($this->object()->supportsImports()) {
+            $templates = $this->enumAllowedTemplates();
+
+            if (empty($templates)) {
+                $default = 'template';
+                $types = array('template' => $this->translate('Template'));
+            } else {
+                $types = array(
+                    'object'   => $this->translate('Object'),
+                    'template' => $this->translate('Template'),
+                );
+            }
+        } else {
+             $types = array('object' => $this->translate('Object'));
+        }
+
+        $types['external_object'] = $this->translate('External Object');
+
+        if (! $this->hasObject()) {
+            $this->object()->object_type = $default;
+        }
+
+        $this->addElement('select', 'object_type', array(
+            'label' => $this->translate('Object type'),
+            'description'  => $this->translate('Whether this should be a template'),
+            'multiOptions' => $this->optionalEnum($types),
+            'value'        => $default,
+            'class'        => 'autosubmit'
+        ));
+
+        return $this;
+    }
+
     protected function addZoneElement()
     {
         if ($this->isTemplate()) {



More information about the icinga-checkins mailing list