3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
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.
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.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 Prado::using('System.Web.UI.TTemplateControl');
24 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
25 Prado::using('Application.Web.Portlets.IDirectiveField');
27 class DirectiveTemplate extends TTemplateControl implements IDirectiveField, IActiveControl {
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';
39 const RESOURCE = 'Resource';
40 const LABEL = 'Label';
41 const IN_CONFIG = 'InConfig';
43 const RESOURCE_NAMES = 'ResourceNames';
44 const PARENT_NAME = 'ParentName';
45 const GROUP_NAME = 'GroupName';
46 const IS_DIRECTIVE_CREATED = 'IsDirectiveCreated';
48 public $display_directive;
50 private $command_params = array('save', 'add');
52 public function __construct() {
53 parent::__construct();
54 $this->setAdapter(new TActiveControlAdapter($this));
57 public function getActiveControl() {
58 return $this->getAdapter()->getBaseActiveControl();
61 public function bubbleEvent($sender, $param) {
62 if ($param instanceof TCommandEventParameter) {
63 $this->raiseBubbleEvent($this, $param);
70 public function saveValue($sender, $param) {
71 if (!$this->getPage()->IsPostBack) {
74 $command_param = $this->getCmdParam();
75 if ($command_param === 'save' && method_exists($this, 'getValue')) {
76 $new_value = $this->getValue();
77 $this->setDirectiveValue($new_value);
81 private function getCmdParam() {
82 $command_param = null;
83 if (method_exists($this->getPage()->CallBackEventTarget, 'getCommandParameter')) {
84 $command_param = $this->getPage()->CallBackEventTarget->getCommandParameter();
86 return $command_param;
89 public function onPreRender($param) {
90 parent::onPreRender($param);
91 if (!$this->getIsDirectiveCreated()) {
92 $this->createDirective();
93 $this->setIsDirectiveCreated(true);
95 // show directives existing in config or all
96 $this->display_directive = $this->getShow();
99 public function createDirective($value_loaded = false) {
100 // so far nothing to do
103 public function loadValue($value_obj) {
104 $value_obj->raisePostDataChangedEvent();
107 public function getHost() {
108 return $this->getViewState(self::HOST);
111 public function setHost($host) {
112 $this->setViewState(self::HOST, $host);
115 public function getComponentType() {
116 return $this->getViewState(self::COMPONENT_TYPE);
119 public function setComponentType($type) {
120 $this->setViewState(self::COMPONENT_TYPE, $type);
123 public function getComponentName() {
124 return $this->getViewState(self::COMPONENT_NAME);
127 public function setComponentName($name) {
128 $this->setViewState(self::COMPONENT_NAME, $name);
131 public function getResourceType() {
132 return $this->getViewState(self::RESOURCE_TYPE);
135 public function setResourceType($type) {
136 $this->setViewState(self::RESOURCE_TYPE, $type);
139 public function getResourceName() {
140 return $this->getViewState(self::RESOURCE_NAME);
143 public function setResourceName($name) {
144 $this->setViewState(self::RESOURCE_NAME, $name);
147 public function getDirectiveName() {
148 return $this->getViewState(self::DIRECTIVE_NAME);
151 public function setDirectiveName($name) {
152 $this->setViewState(self::DIRECTIVE_NAME, $name);
155 public function getDirectiveValue() {
156 return $this->getViewState(self::DIRECTIVE_VALUE);
159 public function setDirectiveValue($value) {
160 $this->setViewState(self::DIRECTIVE_VALUE, $value);
163 public function getDefaultValue() {
164 return $this->getViewState(self::DEFAULT_VALUE);
167 public function setDefaultValue($value) {
168 $this->setViewState(self::DEFAULT_VALUE, $value);
171 public function getRequired() {
172 return $this->getViewState(self::REQUIRED);
175 public function setRequired($value) {
176 $value = TPropertyValue::ensureBoolean($value);
177 $this->setViewState(self::REQUIRED, $value);
180 public function getLabel() {
181 return $this->getViewState(self::LABEL);
184 public function setLabel($label) {
185 $this->setViewState(self::LABEL, $label);
188 public function getInConfig() {
189 return $this->getViewState(self::IN_CONFIG, false);
192 public function setInConfig($in_config) {
193 $this->setViewState(self::IN_CONFIG, $in_config);
196 public function getShow() {
197 return $this->getViewState(self::SHOW);
200 public function setShow($show) {
201 $this->setViewState(self::SHOW, $show);
204 public function getResourceNames() {
205 return $this->getViewState(self::RESOURCE_NAMES);
208 public function setResourceNames($resource_names) {
209 $this->setViewState(self::RESOURCE_NAMES, $resource_names);
212 public function getData() {
213 return $this->getViewState(self::DATA);
216 public function setData($data) {
217 $this->setViewState(self::DATA, $data);
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);
225 public function setResource($resource) {
226 $this->setViewState(self::RESOURCE, $resource);
229 public function getParentName() {
230 return $this->getViewState(self::PARENT_NAME);
233 public function setParentName($parent_name) {
234 $this->setViewState(self::PARENT_NAME, $parent_name);
237 public function getGroupName() {
238 return $this->getViewState(self::GROUP_NAME);
241 public function setGroupName($group_name) {
242 $this->setViewState(self::GROUP_NAME, $group_name);
245 public function getIsDirectiveCreated() {
246 return $this->getViewState(self::IS_DIRECTIVE_CREATED);
249 public function setIsDirectiveCreated($is_created) {
250 $this->setViewState(self::IS_DIRECTIVE_CREATED, $is_created);