migrations/index: Let the migrate all button submit the migration form

This commit is contained in:
Johannes Meyer 2023-09-15 16:56:22 +02:00
parent 8a1c224461
commit 4a8d171aec
2 changed files with 22 additions and 12 deletions

View File

@ -14,6 +14,7 @@ use Icinga\Web\Notification;
use Icinga\Web\Widget\ItemList\MigrationList;
use Icinga\Web\Widget\Tabextension\OutputFormat;
use ipl\Html\Attributes;
use ipl\Html\FormElement\SubmitButtonElement;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Web\Compat\CompatController;
@ -53,22 +54,25 @@ class MigrationsController extends CompatController
}
$migrateListForm = new MigrationForm();
$migrateListForm->setAttribute('id', $this->getRequest()->protectId('migration-form'));
$migrateListForm->setRenderDatabaseUserChange(! $mm->validateDatabasePrivileges());
$migrateGlobalForm = new MigrationForm();
$migrateGlobalForm->getAttributes()->set('name', sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS));
if ($canApply && $mm->hasPendingMigrations()) {
$migrateGlobalForm->addElement('submit', sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS), [
'required' => true,
'label' => $this->translate('Migrate All'),
'title' => $this->translate('Migrate all pending migrations')
$migrateAllButton = new SubmitButtonElement(sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS), [
'form' => $migrateListForm->getAttribute('id')->getValue(),
'label' => $this->translate('Migrate All'),
'title' => $this->translate('Migrate all pending migrations')
]);
$this->controls->getAttributes()->add('class', 'default-layout');
$this->handleMigrateRequest($migrateGlobalForm);
// Is the first button, so will be cloned and that the visible
// button is outside the form doesn't matter for Web's JS
$migrateListForm->registerElement($migrateAllButton);
$this->addControl($migrateGlobalForm);
// Make sure it looks familiar, even if not inside a form
$migrateAllButton->setWrapper(new HtmlElement('div', Attributes::create(['class' => 'icinga-controls'])));
$this->controls->getAttributes()->add('class', 'default-layout');
$this->addControl($migrateAllButton);
}
$this->handleFormatRequest($mm->toArray());

View File

@ -6,7 +6,6 @@ namespace Icinga\Forms;
use Icinga\Application\MigrationManager;
use ipl\Html\Attributes;
use ipl\Html\Form;
use ipl\Html\FormElement\CheckboxElement;
use ipl\Html\FormElement\FieldsetElement;
use ipl\Html\HtmlElement;
@ -15,10 +14,11 @@ use ipl\I18n\Translation;
use ipl\Validator\CallbackValidator;
use ipl\Web\Common\CsrfCounterMeasure;
use ipl\Web\Common\FormUid;
use ipl\Web\Compat\CompatForm;
use ipl\Web\FormDecorator\IcingaFormDecorator;
use PDOException;
class MigrationForm extends Form
class MigrationForm extends CompatForm
{
use CsrfCounterMeasure;
use FormUid;
@ -50,6 +50,12 @@ class MigrationForm extends Form
return $this;
}
public function hasDefaultElementDecorator()
{
// The base implementation registers a decorator we don't want here
return false;
}
protected function assemble(): void
{
$this->addHtml($this->createUidElement());