Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions application/controllers/ContactGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Common\Links;
use Icinga\Module\Notifications\Forms\ContactGroupForm;
use Icinga\Module\Notifications\Model\Contact;
use Icinga\Module\Notifications\Model\Contactgroup;
use Icinga\Module\Notifications\View\ContactgroupRenderer;
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
use Icinga\Module\Notifications\Widget\MemberSuggestions;
use Icinga\Web\Notification;
use ipl\Html\Form;
use ipl\Html\Text;
use ipl\Html\HtmlElement;
use ipl\Html\TemplateString;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;
use ipl\Web\Compat\SearchControls;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
use ipl\Web\Filter\QueryString;
use ipl\Web\Layout\MinimalItemLayout;
use ipl\Web\Widget\ActionLink;
use ipl\Web\Widget\ButtonLink;
use ipl\Web\Widget\Tabs;

Expand Down Expand Up @@ -78,18 +81,41 @@ public function indexAction(): void
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($searchBar);
$this->addContent(
(new ButtonLink(
Text::create(t('Add Contact Group')),
Links::contactGroupsAdd()->with(['showCompact' => true, '_disableLayout' => 1]),
'plus',
['class' => 'add-new-component']
))->openInModal()

$addButton = new ButtonLink(
t('Add Contact Group'),
Links::contactGroupsAdd()->with(['showCompact' => true, '_disableLayout' => 1]),
'plus',
['class' => 'add-new-component']
);

$emptyStateMessage = null;
if (Contact::on(Database::get())->columns('1')->first() === null) {
$addButton
->setDisabled()
->addAttributes(['title' => t('A contact is required to add a contact group')]);

$emptyStateMessage = new HtmlElement(
'span',
null,
TemplateString::create(
t(
'No contact groups found. To add a new contact group,'
.' please {{#link}}add a contact{{/link}} first.'
),
['link' => new ActionLink(null, Links::contactAdd(), attributes: ['data-base-target' => '_next'])]
)
);
} else {
$addButton->openInModal();
}

$this->addContent($addButton);

$this->addContent(
(new ObjectList($groups, new ContactgroupRenderer()))
->setItemLayoutClass(MinimalItemLayout::class)
->setEmptyStateMessage($emptyStateMessage)
);

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function addAction(): void
->on(ContactForm::ON_SUCCESS, function (ContactForm $form) {
$form->addContact();
Notification::success(t('New contact has successfully been added'));
$this->redirectNow(Links::contacts());
$this->redirectNow('__CLOSE__');
})->handleRequest($this->getServerRequest());

$this->addContent($form);
Expand Down
Loading