From b97cb14e0584c69242af874c02dc55c88e54a71a Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 30 Jul 2015 09:49:01 +0200 Subject: [PATCH] Objects: add template tree --- .../views/scripts/hosttemplates/tree.phtml | 65 +++++++++++++++++++ .../Web/Controller/ObjectsController.php | 17 +++-- 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 application/views/scripts/hosttemplates/tree.phtml diff --git a/application/views/scripts/hosttemplates/tree.phtml b/application/views/scripts/hosttemplates/tree.phtml new file mode 100644 index 00000000..a97bba7a --- /dev/null +++ b/application/views/scripts/hosttemplates/tree.phtml @@ -0,0 +1,65 @@ +children); + if ($level === 0) { + $class = 'root'; + } else { + $class = 'host'; + } + + if ($hasChildren) { + $collapsed = ''; + } else { + $collapsed = ' class="collapsed"'; + } + + $html = ''; + if ($hasChildren) { + ksort($tree->children); + $html .= ' '; + } + + if ($level === 0) { + $html .= '' . $self->escape($tree->name) . ''; + } else { + $html .= $self->qlink( + $tree->name, + 'director/host', + array('name' => $tree->name), + array('class' => $class) + ); + } + + if ($hasChildren) { + $html .= ''; + } + $html .= "\n"; + return $html; +} + +?> +
+tabs ?> +

translate('Host template tree') ?>

+
+ +
+
    + + 'Templates', + 'children' => $this->tree + ), + $this +) ?> +
+
diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index f78f1ccc..ec74945e 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -16,14 +16,12 @@ abstract class ObjectsController extends ActionController public function init() { + $tabs = $this->getTabs(); $type = $this->getType(); - $ltype = strtolower($type); - - $object = $this->dummyObject(); if (in_array(ucfirst($type), $this->globalTypes)) { + $ltype = strtolower($type); - $tabs = $this->getTabs(); foreach ($this->globalTypes as $tabType) { $ltabType = strtolower($tabType); $tabs->add($ltabType, array( @@ -60,6 +58,11 @@ abstract class ObjectsController extends ActionController } } + + $tabs->add('tree', array( + 'url' => sprintf('director/%stemplates/tree', $type), + 'label' => $this->translate('Tree'), + )); } public function indexAction() @@ -103,6 +106,12 @@ abstract class ObjectsController extends ActionController $this->render('objects/table', null, true); } + public function treeAction() + { + $this->getTabs()->activate('tree'); + $this->view->tree = $this->db()->fetchTemplateTree(strtolower($this->getType())); + } + protected function dummyObject() { if ($this->dummy === null) {