Skip to content

Commit 128624e

Browse files
committed
WIP
1 parent 375cdd7 commit 128624e

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

application/forms/EventRuleConfigElements/EscalationCondition.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function assemble(): void
110110
'select',
111111
$opName,
112112
[
113-
'class' => ['class' => 'operator-input', 'autosubmit'],
113+
'class' => ['class' => 'operator-input'],
114114
'options' => array_combine($operators, $operators),
115115
'required' => true
116116
]
@@ -123,7 +123,7 @@ protected function assemble(): void
123123
'select',
124124
$valName,
125125
[
126-
'class' => ['autosubmit', 'right-operand'],
126+
'class' => ['right-operand'],
127127
'options' => [
128128
'ok' => $this->translate('Ok', 'notification.severity'),
129129
'debug' => $this->translate('Debug', 'notification.severity'),
@@ -158,7 +158,7 @@ protected function assemble(): void
158158
$valName,
159159
[
160160
'required' => true,
161-
'class' => ['autosubmit', 'right-operand'],
161+
'class' => ['right-operand'],
162162
'validators' => [
163163
new CallbackValidator(function ($value, $validator) {
164164
if (! preg_match('~^\d+(?:\.?\d*)?[hms]{1}$~', $value)) {

application/forms/EventRuleConfigElements/EscalationRecipient.php

+27-27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ipl\Html\FormElement\FieldsetElement;
1515
use ipl\Html\FormElement\SelectElement;
1616
use ipl\Html\FormElement\SubmitButtonElement;
17+
use ipl\Validator\CallbackValidator;
1718
use ipl\Web\Widget\Icon;
1819

1920
class EscalationRecipient extends FieldsetElement
@@ -62,7 +63,7 @@ protected function assemble(): void
6263
'select',
6364
'column_' . $i,
6465
[
65-
'class' => ['autosubmit', 'left-operand'],
66+
'class' => ['left-operand'],
6667
'options' => [
6768
'' => sprintf(' - %s - ', $this->translate('Please choose'))
6869
] + $this->fetchOptions(),
@@ -73,46 +74,45 @@ protected function assemble(): void
7374
);
7475

7576
$this->registerElement($col);
77+
/** @var string $recipientVal */
78+
$recipientVal = $this->getValue('column_' . $i) ?? '';
79+
$recipient = explode('_', $recipientVal);
7680

77-
$options = ['' => sprintf(' - %s - ', $this->translate('Please choose'))];
81+
$options = ['' => sprintf('%s', $this->translate('Default User Channel'))];
7882
$options += Channel::fetchChannelNames(Database::get());
7983

8084
/** @var SelectElement $val */
8185
$val = $this->createElement(
8286
'select',
8387
'val_' . $i,
8488
[
85-
'class' => ['autosubmit', 'right-operand'],
89+
'class' => ['right-operand'],
8690
'options' => $options,
8791
'disabledOptions' => [''],
88-
'value' => $this->getPopulatedValue('val_' . $i)
92+
'value' => $this->getPopulatedValue('val_' . $i),
93+
'validators' => [
94+
new CallbackValidator(function ($value, $validator) use ($recipient) {
95+
if ($recipient[0] !== 'contact' && $value !== '') {
96+
$validator->addMessage(
97+
$this->translate(
98+
'The channel cannot be the default channel for the recipient type '
99+
. $recipient[0]
100+
)
101+
);
102+
103+
return false;
104+
}
105+
106+
$validator->clearMessages();
107+
return true;
108+
})
109+
]
89110
]
90111
);
91112

92-
/** @var string $recipientVal */
93-
$recipientVal = $this->getValue('column_' . $i);
94-
if ($recipientVal !== null) {
95-
$recipient = explode('_', $recipientVal);
96-
if ($recipient[0] === 'contact') {
97-
$options[''] = $this->translate('Default User Channel');
98-
99-
$val->setOptions($options);
100-
101-
$val->setDisabledOptions([]);
113+
$val->setDisabledOptions([]);
102114

103-
if ($this->getPopulatedValue('val_' . $i, '') === '') {
104-
$val->addAttributes(['class' => 'default-channel']);
105-
}
106-
}
107-
} else {
108-
/** @var BaseFormElement $val */
109-
$val = $this->createElement('text', 'val_' . $i, [
110-
'class' => 'right-operand',
111-
'placeholder' => $this->translate('Please make a decision'),
112-
'disabled' => true,
113-
'value' => $this->getPopulatedValue('val_' . $i)
114-
]);
115-
}
115+
$val->getOption('')->setAttribute('class', 'default-channel');
116116

117117
$this->registerElement($val);
118118

public/css/event-rule-config.less

+4-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@
184184
}
185185
}
186186

187-
.default-channel {
188-
color: @disabled-gray;
189-
}
190-
191187
select, input {
192188
min-width: 10em;
193189
text-align: center;
@@ -203,6 +199,10 @@
203199
background-repeat: no-repeat;
204200
}
205201

202+
.right-operand:has(> .default-channel) {
203+
color: @disabled-gray;
204+
}
205+
206206
.left-operand {
207207
border-radius: 0.4em 0 0 0.4em;
208208
margin-right: 1px;

0 commit comments

Comments
 (0)