diff --git a/application/forms/Dashboard/HomeForm.php b/application/forms/Dashboard/HomeForm.php new file mode 100644 index 000000000..aebd1be42 --- /dev/null +++ b/application/forms/Dashboard/HomeForm.php @@ -0,0 +1,61 @@ +populate(['title' => $dashboard->getTitle()]); + } + + protected function assemble() + { + $this->addElement('text', 'title', [ + 'required' => true, + 'label' => t('Title'), + 'placeholder' => t('Create new Dashboard Home'), + 'description' => $this->isUpdating() ? t('Edit the title of this dashboard home') : t('Add new dashboard.') + ]); + + $formControls = $this->createFormControls(); + $formControls->addHtml($this->registerSubmitButton($this->isUpdating() ? t('Update Home') : t('Add Home'))); + + if ($this->isUpdating()) { + $removeTargetUrl = (clone $this->requestUrl)->setPath(Dashboard::BASE_ROUTE . '/remove-home'); + $formControls->addHtml($this->createRemoveButton($removeTargetUrl, t('Remove Home'))); + } + + $formControls->addHtml($this->createCancelButton()); + $this->addHtml($formControls); + } + + protected function onSuccess() + { + if ($this->isUpdating()) { + $home = $this->dashboard->getActiveHome(); + $home->setTitle($this->getPopulatedValue('title')); + + $this->dashboard->manageEntry($home); + + Notification::success(sprintf(t('Updated dashboard home "%s" successfully'), $home->getTitle())); + } else { + $home = new DashboardHome($this->getPopulatedValue('title')); + if ($this->dashboard->hasEntry($home->getName())) { + Notification::error(sprintf(t('Dashboard home "%s" already exists'), $home->getName())); + return; + } + + $this->dashboard->manageEntry($home); + + Notification::success(sprintf(t('Added dashboard home "%s" successfully'), $home->getName())); + } + } +}