Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WidgetForm.php « includes « clock « widgets « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac94bea7d6b89f45ac3d87a983218641a89ab190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php declare(strict_types = 0);
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


namespace Widgets\Clock\Includes;

use Zabbix\Widgets\{
	CWidgetField,
	CWidgetForm
};

use Zabbix\Widgets\Fields\{
	CWidgetFieldCheckBox,
	CWidgetFieldCheckBoxList,
	CWidgetFieldColor,
	CWidgetFieldIntegerBox,
	CWidgetFieldMultiSelectItem,
	CWidgetFieldRadioButtonList,
	CWidgetFieldSelect,
	CWidgetFieldTimeZone
};

use Widgets\Clock\Widget;

/**
 * Clock widget form.
 */
class WidgetForm extends CWidgetForm {

	private const SIZE_PERCENT_MIN = 1;
	private const SIZE_PERCENT_MAX = 100;

	private const DEFAULT_DATE_SIZE = 20;
	private const DEFAULT_TIME_SIZE = 30;
	private const DEFAULT_TIMEZONE_SIZE = 20;

	public function addFields(): self {
		$time_type = array_key_exists('time_type', $this->values) ? $this->values['time_type'] : null;

		return $this
			->addField(
				(new CWidgetFieldSelect('time_type', _('Time type'), [
					TIME_TYPE_LOCAL => _('Local time'),
					TIME_TYPE_SERVER => _('Server time'),
					TIME_TYPE_HOST => _('Host time')
				]))->setDefault(TIME_TYPE_LOCAL)
			)
			->addField($time_type == TIME_TYPE_HOST
				? (new CWidgetFieldMultiSelectItem('itemid', _('Item'), $this->templateid))
					->setFlags(CWidgetField::FLAG_NOT_EMPTY | CWidgetField::FLAG_LABEL_ASTERISK)
					->setMultiple(false)
				: null
			)
			->addField(
				(new CWidgetFieldRadioButtonList('clock_type', _('Clock type'), [
					Widget::TYPE_ANALOG => _('Analog'),
					Widget::TYPE_DIGITAL => _('Digital')
				]))->setDefault(Widget::TYPE_ANALOG)
			)
			->addField(
				(new CWidgetFieldCheckBoxList('show', _('Show'), [
					Widget::SHOW_DATE => _('Date'),
					Widget::SHOW_TIME => _('Time'),
					Widget::SHOW_TIMEZONE => _('Time zone')
				]))
					->setDefault([Widget::SHOW_TIME])
					->setFlags(CWidgetField::FLAG_LABEL_ASTERISK)
			)
			->addField(
				new CWidgetFieldCheckBox('adv_conf', _('Advanced configuration'))
			)
			->addField(
				(new CWidgetFieldColor('bg_color', _('Background color')))->allowInherited()
			)
			->addField(
				(new CWidgetFieldIntegerBox('date_size', _('Size'), self::SIZE_PERCENT_MIN, self::SIZE_PERCENT_MAX))
					->setDefault(self::DEFAULT_DATE_SIZE)
			)
			->addField(
				new CWidgetFieldCheckBox('date_bold', _('Bold'))
			)
			->addField(
				(new CWidgetFieldColor('date_color', _('Color')))->allowInherited()
			)
			->addField(
				(new CWidgetFieldIntegerBox('time_size', _('Size'), self::SIZE_PERCENT_MIN, self::SIZE_PERCENT_MAX))
					->setDefault(self::DEFAULT_TIME_SIZE)
			)
			->addField(
				new CWidgetFieldCheckBox('time_bold', _('Bold'))
			)
			->addField(
				(new CWidgetFieldColor('time_color', _('Color')))->allowInherited()
			)
			->addField(
				(new CWidgetFieldCheckBox('time_sec', _('Seconds')))->setDefault(1)
			)
			->addField(
				(new CWidgetFieldRadioButtonList('time_format', _('Format'), [
					Widget::HOUR_24 => _('24-hour'),
					Widget::HOUR_12 => _('12-hour')
				]))->setDefault(Widget::HOUR_24)
			)
			->addField(
				(new CWidgetFieldIntegerBox('tzone_size', _('Size'), self::SIZE_PERCENT_MIN, self::SIZE_PERCENT_MAX))
					->setDefault(self::DEFAULT_TIMEZONE_SIZE)
			)
			->addField(
				new CWidgetFieldCheckBox('tzone_bold', _('Bold'))
			)
			->addField(
				(new CWidgetFieldColor('tzone_color', _('Color')))->allowInherited()
			)
			->addField(
				(new CWidgetFieldTimeZone('tzone_timezone', _('Time zone')))
					->setDefault($time_type == TIME_TYPE_LOCAL ? TIMEZONE_DEFAULT_LOCAL : ZBX_DEFAULT_TIMEZONE)
			)
			->addField(
				(new CWidgetFieldRadioButtonList('tzone_format', _('Format'), [
					Widget::TIMEZONE_SHORT => _('Short'),
					Widget::TIMEZONE_FULL => _('Full')
				]))->setDefault(Widget::TIMEZONE_SHORT)
			);
	}
}