]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Web/Portlets/DirectiveTemplate.php
baculum: Revert back volume pool name in volume list window
[bacula/bacula] / gui / baculum / protected / Web / Portlets / DirectiveTemplate.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 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.TTemplateControl');
24 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
25 Prado::using('Application.Web.Portlets.IDirectiveField');
26
27 class DirectiveTemplate extends TTemplateControl implements IDirectiveField, IActiveControl {
28
29         const HOST = 'Host';
30         const COMPONENT_TYPE = 'ComponentType';
31         const COMPONENT_NAME = 'ComponentName';
32         const RESOURCE_TYPE = 'ResourceType';
33         const RESOURCE_NAME = 'ResourceName';
34         const DIRECTIVE_NAME = 'DirectiveName';
35         const DIRECTIVE_VALUE = 'DirectiveValue';
36         const DEFAULT_VALUE = 'DefaultValue';
37         const REQUIRED = 'Required';
38         const DATA = 'Data';
39         const RESOURCE = 'Resource';
40         const LABEL = 'Label';
41         const IN_CONFIG = 'InConfig';
42         const SHOW = 'Show';
43         const RESOURCE_NAMES = 'ResourceNames';
44         const PARENT_NAME = 'ParentName';
45         const GROUP_NAME = 'GroupName';
46         const IS_DIRECTIVE_CREATED = 'IsDirectiveCreated';
47
48         public $display_directive;
49
50         private $command_params = array('save', 'add');
51
52         public function __construct() {
53                 parent::__construct();
54                 $this->setAdapter(new TActiveControlAdapter($this));
55         }
56
57         public function getActiveControl() {
58                 return $this->getAdapter()->getBaseActiveControl();
59         }
60
61         public function bubbleEvent($sender, $param) {
62                 if ($param instanceof TCommandEventParameter) {
63                         $this->raiseBubbleEvent($this, $param);
64                         return true;
65                 } else {
66                         return false;
67                 }
68         }
69
70         public function saveValue($sender, $param) {
71                 if (!$this->getPage()->IsPostBack) {
72                         return;
73                 }
74                 $command_param = $this->getCmdParam();
75                 if ($command_param === 'save' && method_exists($this, 'getValue')) {
76                         $new_value = $this->getValue();
77                         $this->setDirectiveValue($new_value);
78                 }
79         }
80
81         private function getCmdParam() {
82                 $command_param = null;
83                 if (method_exists($this->getPage()->CallBackEventTarget, 'getCommandParameter')) {
84                         $command_param = $this->getPage()->CallBackEventTarget->getCommandParameter();
85                 }
86                 return $command_param;
87         }
88
89         public function onPreRender($param) {
90                 parent::onPreRender($param);
91                 if (!$this->getIsDirectiveCreated()) {
92                         $this->createDirective();
93                         $this->setIsDirectiveCreated(true);
94                 }
95                 // show directives existing in config or all
96                 $this->display_directive = $this->getShow();
97         }
98
99         public function createDirective($value_loaded = false) {
100                 // so far nothing to do
101         }
102
103         public function loadValue($value_obj) {
104                 $value_obj->raisePostDataChangedEvent();
105         }
106
107         public function getHost() {
108                 return $this->getViewState(self::HOST);
109         }
110
111         public function setHost($host) {
112                 $this->setViewState(self::HOST, $host);
113         }
114
115         public function getComponentType() {
116                 return $this->getViewState(self::COMPONENT_TYPE);
117         }
118
119         public function setComponentType($type) {
120                 $this->setViewState(self::COMPONENT_TYPE, $type);
121         }
122
123         public function getComponentName() {
124                 return $this->getViewState(self::COMPONENT_NAME);
125         }
126
127         public function setComponentName($name) {
128                 $this->setViewState(self::COMPONENT_NAME, $name);
129         }
130
131         public function getResourceType() {
132                 return $this->getViewState(self::RESOURCE_TYPE);
133         }
134
135         public function setResourceType($type) {
136                 $this->setViewState(self::RESOURCE_TYPE, $type);
137         }
138
139         public function getResourceName() {
140                 return $this->getViewState(self::RESOURCE_NAME);
141         }
142
143         public function setResourceName($name) {
144                 $this->setViewState(self::RESOURCE_NAME, $name);
145         }
146
147         public function getDirectiveName() {
148                 return $this->getViewState(self::DIRECTIVE_NAME);
149         }
150
151         public function setDirectiveName($name) {
152                 $this->setViewState(self::DIRECTIVE_NAME, $name);
153         }
154
155         public function getDirectiveValue() {
156                 return $this->getViewState(self::DIRECTIVE_VALUE);
157         }
158
159         public function setDirectiveValue($value) {
160                 $this->setViewState(self::DIRECTIVE_VALUE, $value);
161         }
162
163         public function getDefaultValue() {
164                 return $this->getViewState(self::DEFAULT_VALUE);
165         }
166
167         public function setDefaultValue($value) {
168                 $this->setViewState(self::DEFAULT_VALUE, $value);
169         }
170
171         public function getRequired() {
172                 return $this->getViewState(self::REQUIRED);
173         }
174
175         public function setRequired($value) {
176                 $value = TPropertyValue::ensureBoolean($value);
177                 $this->setViewState(self::REQUIRED, $value);
178         }
179
180         public function getLabel() {
181                 return $this->getViewState(self::LABEL);
182         }
183
184         public function setLabel($label) {
185                 $this->setViewState(self::LABEL, $label);
186         }
187
188         public function getInConfig() {
189                 return $this->getViewState(self::IN_CONFIG, false);
190         }
191
192         public function setInConfig($in_config) {
193                 $this->setViewState(self::IN_CONFIG, $in_config);
194         }
195
196         public function getShow() {
197                 return $this->getViewState(self::SHOW);
198         }
199
200         public function setShow($show) {
201                 $this->setViewState(self::SHOW, $show);
202         }
203
204         public function getResourceNames() {
205                 return $this->getViewState(self::RESOURCE_NAMES);
206         }
207
208         public function setResourceNames($resource_names) {
209                 $this->setViewState(self::RESOURCE_NAMES, $resource_names);
210         }
211
212         public function getData() {
213                 return $this->getViewState(self::DATA);
214         }
215
216         public function setData($data) {
217                 $this->setViewState(self::DATA, $data);
218         }
219
220         // Re-think name of the Resource property and use more general name if possible
221         public function getResource() {
222                 return $this->getViewState(self::RESOURCE);
223         }
224
225         public function setResource($resource) {
226                 $this->setViewState(self::RESOURCE, $resource);
227         }
228
229         public function getParentName() {
230                 return $this->getViewState(self::PARENT_NAME);
231         }
232
233         public function setParentName($parent_name) {
234                 $this->setViewState(self::PARENT_NAME, $parent_name);
235         }
236
237         public function getGroupName() {
238                 return $this->getViewState(self::GROUP_NAME);
239         }
240
241         public function setGroupName($group_name) {
242                 $this->setViewState(self::GROUP_NAME, $group_name);
243         }
244
245         public function getIsDirectiveCreated() {
246                 return $this->getViewState(self::IS_DIRECTIVE_CREATED);
247         }
248
249         public function setIsDirectiveCreated($is_created) {
250                 $this->setViewState(self::IS_DIRECTIVE_CREATED, $is_created);
251         }
252 }
253 ?>