diff --git a/application/forms/ChannelForm.php b/application/forms/ChannelForm.php index 7bb56455a..8fdc4ec7b 100644 --- a/application/forms/ChannelForm.php +++ b/application/forms/ChannelForm.php @@ -7,6 +7,8 @@ use Icinga\Exception\Http\HttpNotFoundException; use Icinga\Module\Notifications\Model\Channel; use Icinga\Module\Notifications\Model\AvailableChannelType; +use Icinga\Module\Notifications\Model\Contact; +use Icinga\Module\Notifications\Model\RuleEscalationRecipient; use Icinga\Web\Session; use ipl\Html\Contract\FormSubmitElement; use ipl\Html\FormElement\BaseFormElement; @@ -52,6 +54,7 @@ public function __construct(Connection $db) protected function assemble() { + $this->addAttributes(['class' => 'channel-form']); $this->addElement($this->createCsrfCounterMeasure(Session::getSession()->getId())); $this->addElement( @@ -111,6 +114,15 @@ protected function assemble() ); if ($this->channelId !== null) { + $isInUse = RuleEscalationRecipient::on($this->db) + ->columns('1') + ->filter(Filter::all( + Filter::equal('deleted', 'n'), + Filter::equal('channel_id', $this->channelId) + )) + ->count() > 0; + //TODO: EscalationRecipientForm: Insert channel id to escalation_recipient table when default channel is selected + /** @var FormSubmitElement $deleteButton */ $deleteButton = $this->createElement( 'submit', @@ -118,7 +130,11 @@ protected function assemble() [ 'label' => $this->translate('Delete'), 'class' => 'btn-remove', - 'formnovalidate' => true + 'formnovalidate' => true, + 'disabled' => $isInUse, + 'title' => $isInUse + ? $this->translate('Cannot delete channel, contacts or event rules are using it') + : null ] ); diff --git a/public/css/form.less b/public/css/form.less index ca2a24062..c9626b665 100644 --- a/public/css/form.less +++ b/public/css/form.less @@ -108,3 +108,11 @@ .source-form textarea { .monospace-font(); } + +.channel-form { + .btn-remove:disabled { + background: @gray-light; + color: @disabled-gray; + border-color: transparent; + } +}