]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/BaculaConfigComponents.php
baculum: Add link to go back from job configuration window
[bacula/bacula] / gui / baculum / protected / Web / Portlets / BaculaConfigComponents.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2017 Kern Sibbald
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
24 Prado::using('System.Web.UI.ActiveControls.TActiveRepeater');
25 Prado::using('Application.Web.Portlets.ComponentListTemplate');
26 Prado::using('Application.Web.Portlets.NewResourceMenu');
27 Prado::using('Application.Web.Class.Miscellaneous');
28
29 class BaculaConfigComponents extends ComponentListTemplate {
30
31         const CHILD_CONTROL = 'BaculaConfigResources';
32
33         const MENU_CONTROL = 'NewResourceMenu';
34
35         private function getConfigData($host) {
36                 $params = array('config');
37                 $result = $this->Application->getModule('api')->get($params, $host, false);
38                 $config = array();
39                 $this->ErrorMsg->Display = 'None';
40                 if (is_object($result) && $result->error === 0 && is_array($result->output)) {
41                         $config = $result->output;
42                 } else {
43                         $this->ErrorMsg->Text = print_r($result, true);
44                         $this->ErrorMsg->Display = 'Dynamic';
45                 }
46                 return $config;
47         }
48
49         public function loadConfig() {
50                 $components = array();
51                 $host = $this->getHost();
52                 $config = $this->getConfigData($host);
53                 for ($i = 0; $i < count($config); $i++) {
54                         $component = (array)$config[$i];
55                         if (array_key_exists('component_type', $component) && array_key_exists('component_name', $component)) {
56                                 $component['host'] = $host;
57                                 $component['label'] = $this->getModule('misc')->getComponentFullName($component['component_type']);
58                                 array_push($components, $component);
59                         }
60                 }
61                 $this->RepeaterComponents->DataSource = $components;
62                 $this->RepeaterComponents->dataBind();
63         }
64
65         public function createComponentListElement($sender, $param) {
66                 $controls = array(self::CHILD_CONTROL, self::MENU_CONTROL);
67                 for ($i = 0; $i < count($controls); $i++) {
68                         $control = $this->getChildControl($param->Item, $controls[$i]);
69                         if (is_object($control)) {
70                                 $control->setHost($param->Item->DataItem['host']);
71                                 $control->setComponentType($param->Item->DataItem['component_type']);
72                                 $control->setComponentName($param->Item->DataItem['component_name']);
73                         }
74                 }
75         }
76
77         public function getResources($sender, $param) {
78                 $control = $this->getChildControl($sender->getParent(), self::CHILD_CONTROL);
79                 if (is_object($control)) {
80                         $control->raiseEvent('OnResourceListLoad', $this, null);
81                 }
82         }
83
84         public function newResource($sender, $param) {
85                 list($resource_type, $host, $component_type, $component_name) = explode('|', $param->getCommandParameter(), 4);
86                 $this->NewResource->setHost($host);
87                 $this->NewResource->setComponentType($component_type);
88                 $this->NewResource->setComponentName($component_name);
89                 $this->NewResource->setResourceType($resource_type);
90                 $this->NewResource->setLoadValues(false);
91                 $this->NewResource->raiseEvent('OnDirectiveListLoad', $this, null);
92
93         }
94 }
95 ?>