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
|
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Boxydash\Forms\Config;
use Exception;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Web\Form;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Exception\ConfigurationError;
use Icinga\Forms\ConfigForm;
use Icinga\Web\Notification;
/**
* Form class for creating/modifying monitoring Settings
*/
class SettingConfigForm extends ConfigForm
{
protected $resources;
public function init()
{
$this->setName('form_config_boxydash_settings');
$this->setSubmitLabel($this->translate('Save Changes'));
}
public function createElements(array $formData)
{
$this->addElement(
'text',
'setting_refresh',
array(
'label' => $this->translate('Dashboard Refresh'),
'description' => $this->translate('How quickly the dashboard should refresh (between 1 second and 20 minutes)'),
'value' => '10',
'validators' => array(
array(
'Between',
false,
array(
'min' => '1',
'max' => '1200',
'inclusive' => true,
)
)
)
)
);
$this->addElement(
'text',
'setting_boxsize',
array(
'label' => $this->translate('Box Size'),
'description' => $this->translate('The size of displayed boxes in pixels'),
'value' => '10',
'validators' => array(
array(
'Regex',
false,
array(
'pattern' => '/^[\d]+$/',
'messages' => array(
'regexNotMatch' => $this->translate(
'The application prefix must be a positive integer.'
)
)
)
)
)
)
);
$this->addElement(
'checkbox',
'include_softstate',
array(
'required' => true,
'value' => true,
'label' => $this->translate('Include Soft Status'),
'description' => $this->translate('Enable this to have soft status included')
)
);
$this->addElement(
'checkbox',
'requires_authentication',
array(
'required' => true,
'value' => true,
'label' => $this->translate('Require Authentication?'),
'description' => $this->translate('Does Boxydash require Authentication? Warning, this may expose sensitive network information.')
)
);
$this->addElement(
'checkbox',
'show_legend',
array(
'required' => true,
'value' => true,
'label' => $this->translate('Show the Legend'),
'description' => $this->translate('Do you want to show the legend?')
)
);
$this->addElement(
'text',
'path_prefix',
array(
'label' => $this->translate('URL path prefix'),
'description' => $this->translate('Prefix prepended to all links, eg "/icingaweb2". Required in case Icinga Web 2 is installed in a subfolder (eg "http://your-domain.tld/icingaweb2").'),
'value' => '',
)
);
}
public function onSuccess()
{
$this->config->setSection('settings', $this->getValues());
if ($this->save()) {
Notification::success($this->translate('New setings have successfully been stored'));
} else {
return false;
}
}
/**
* @see Form::onRequest()
*/
public function onRequest()
{
$this->populate($this->config->getSection('settings')->toArray());
}
}
|