Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Apr 8, 2024
1 parent 375cdd7 commit 128624e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand All @@ -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'),
Expand Down Expand Up @@ -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)) {
Expand Down
54 changes: 27 additions & 27 deletions application/forms/EventRuleConfigElements/EscalationRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -73,46 +74,45 @@ 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 */
$val = $this->createElement(
'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);

Expand Down
8 changes: 4 additions & 4 deletions public/css/event-rule-config.less
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@
}
}

.default-channel {
color: @disabled-gray;
}

select, input {
min-width: 10em;
text-align: center;
Expand All @@ -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;
Expand Down

0 comments on commit 128624e

Please sign in to comment.