PreferenceForm: Properly process autosubmits

Otherwise the default value of element `auto_refresh_speed`
is not applied after enabling element `auto_refresh`.
This commit is contained in:
Johannes Meyer 2020-11-30 11:41:23 +01:00
parent 79ad7a4197
commit 0f400ea4ef
1 changed files with 18 additions and 9 deletions

View File

@ -44,6 +44,7 @@ class PreferenceForm extends Form
public function init() public function init()
{ {
$this->setName('form_config_preferences'); $this->setName('form_config_preferences');
$this->setSubmitLabel($this->translate('Save to the Preferences'));
} }
/** /**
@ -90,12 +91,6 @@ class PreferenceForm extends Form
*/ */
public function onSuccess() public function onSuccess()
{ {
if (!($this->getElement('btn_submit_preferences')->isChecked()
|| $this->getElement('btn_submit_session')->isChecked()
)) {
return false;
}
$this->preferences = new Preferences($this->store ? $this->store->load() : array()); $this->preferences = new Preferences($this->store ? $this->store->load() : array());
$oldTheme = $this->preferences->getValue('icingaweb', 'theme'); $oldTheme = $this->preferences->getValue('icingaweb', 'theme');
@ -124,7 +119,7 @@ class PreferenceForm extends Form
} }
try { try {
if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) { if ($this->store && $this->getElement('btn_submit')->isChecked()) {
$this->save(); $this->save();
Notification::success($this->translate('Preferences successfully saved')); Notification::success($this->translate('Preferences successfully saved'));
} else { } else {
@ -330,7 +325,7 @@ class PreferenceForm extends Form
if ($this->store) { if ($this->store) {
$this->addElement( $this->addElement(
'submit', 'submit',
'btn_submit_preferences', 'btn_submit',
array( array(
'ignore' => true, 'ignore' => true,
'label' => $this->translate('Save to the Preferences'), 'label' => $this->translate('Save to the Preferences'),
@ -363,7 +358,7 @@ class PreferenceForm extends Form
); );
$this->addDisplayGroup( $this->addDisplayGroup(
array('btn_submit_preferences', 'btn_submit_session', 'preferences-progress'), array('btn_submit', 'btn_submit_session', 'preferences-progress'),
'submit_buttons', 'submit_buttons',
array( array(
'decorators' => array( 'decorators' => array(
@ -374,6 +369,20 @@ class PreferenceForm extends Form
); );
} }
public function addSubmitButton()
{
return $this;
}
public function isSubmitted()
{
if (parent::isSubmitted()) {
return true;
}
return $this->getElement('btn_submit_session')->isChecked();
}
/** /**
* Return the current default timezone * Return the current default timezone
* *