From 128624ecd3b0e3d862ff60c8531683b5f758272d Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 8 Apr 2024 18:24:15 +0200 Subject: [PATCH] WIP --- .../EscalationCondition.php | 6 +-- .../EscalationRecipient.php | 54 +++++++++---------- public/css/event-rule-config.less | 8 +-- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/application/forms/EventRuleConfigElements/EscalationCondition.php b/application/forms/EventRuleConfigElements/EscalationCondition.php index 1bbbc1ff3..74128a278 100644 --- a/application/forms/EventRuleConfigElements/EscalationCondition.php +++ b/application/forms/EventRuleConfigElements/EscalationCondition.php @@ -110,7 +110,7 @@ protected function assemble(): void 'select', $opName, [ - 'class' => ['class' => 'operator-input', 'autosubmit'], + 'class' => ['class' => 'operator-input'], 'options' => array_combine($operators, $operators), 'required' => true ] @@ -123,7 +123,7 @@ protected function assemble(): void 'select', $valName, [ - 'class' => ['autosubmit', 'right-operand'], + 'class' => ['right-operand'], 'options' => [ 'ok' => $this->translate('Ok', 'notification.severity'), 'debug' => $this->translate('Debug', 'notification.severity'), @@ -158,7 +158,7 @@ protected function assemble(): void $valName, [ 'required' => true, - 'class' => ['autosubmit', 'right-operand'], + 'class' => ['right-operand'], 'validators' => [ new CallbackValidator(function ($value, $validator) { if (! preg_match('~^\d+(?:\.?\d*)?[hms]{1}$~', $value)) { diff --git a/application/forms/EventRuleConfigElements/EscalationRecipient.php b/application/forms/EventRuleConfigElements/EscalationRecipient.php index c61faf388..458fc3fbd 100644 --- a/application/forms/EventRuleConfigElements/EscalationRecipient.php +++ b/application/forms/EventRuleConfigElements/EscalationRecipient.php @@ -14,6 +14,7 @@ use ipl\Html\FormElement\FieldsetElement; use ipl\Html\FormElement\SelectElement; use ipl\Html\FormElement\SubmitButtonElement; +use ipl\Validator\CallbackValidator; use ipl\Web\Widget\Icon; class EscalationRecipient extends FieldsetElement @@ -62,7 +63,7 @@ protected function assemble(): void 'select', 'column_' . $i, [ - 'class' => ['autosubmit', 'left-operand'], + 'class' => ['left-operand'], 'options' => [ '' => sprintf(' - %s - ', $this->translate('Please choose')) ] + $this->fetchOptions(), @@ -73,8 +74,11 @@ protected function assemble(): void ); $this->registerElement($col); + /** @var string $recipientVal */ + $recipientVal = $this->getValue('column_' . $i) ?? ''; + $recipient = explode('_', $recipientVal); - $options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))]; + $options = ['' => sprintf('%s', $this->translate('Default User Channel'))]; $options += Channel::fetchChannelNames(Database::get()); /** @var SelectElement $val */ @@ -82,37 +86,33 @@ protected function assemble(): void 'select', 'val_' . $i, [ - 'class' => ['autosubmit', 'right-operand'], + 'class' => ['right-operand'], 'options' => $options, 'disabledOptions' => [''], - 'value' => $this->getPopulatedValue('val_' . $i) + 'value' => $this->getPopulatedValue('val_' . $i), + 'validators' => [ + new CallbackValidator(function ($value, $validator) use ($recipient) { + if ($recipient[0] !== 'contact' && $value !== '') { + $validator->addMessage( + $this->translate( + 'The channel cannot be the default channel for the recipient type ' + . $recipient[0] + ) + ); + + return false; + } + + $validator->clearMessages(); + return true; + }) + ] ] ); - /** @var string $recipientVal */ - $recipientVal = $this->getValue('column_' . $i); - if ($recipientVal !== null) { - $recipient = explode('_', $recipientVal); - if ($recipient[0] === 'contact') { - $options[''] = $this->translate('Default User Channel'); - - $val->setOptions($options); - - $val->setDisabledOptions([]); + $val->setDisabledOptions([]); - if ($this->getPopulatedValue('val_' . $i, '') === '') { - $val->addAttributes(['class' => 'default-channel']); - } - } - } else { - /** @var BaseFormElement $val */ - $val = $this->createElement('text', 'val_' . $i, [ - 'class' => 'right-operand', - 'placeholder' => $this->translate('Please make a decision'), - 'disabled' => true, - 'value' => $this->getPopulatedValue('val_' . $i) - ]); - } + $val->getOption('')->setAttribute('class', 'default-channel'); $this->registerElement($val); diff --git a/public/css/event-rule-config.less b/public/css/event-rule-config.less index 241976a90..8a80381ea 100644 --- a/public/css/event-rule-config.less +++ b/public/css/event-rule-config.less @@ -184,10 +184,6 @@ } } - .default-channel { - color: @disabled-gray; - } - select, input { min-width: 10em; text-align: center; @@ -203,6 +199,10 @@ background-repeat: no-repeat; } + .right-operand:has(> .default-channel) { + color: @disabled-gray; + } + .left-operand { border-radius: 0.4em 0 0 0.4em; margin-right: 1px;