Skip to content

Commit

Permalink
Merge pull request cypht-org#1026 from josaphatim/fix-multiple-alerts…
Browse files Browse the repository at this point in the history
…-in-msg-from-backend

Fixed unclosed divs when there are multiple alert messages from backend
  • Loading branch information
kroky authored May 16, 2024
2 parents f72132a + 57571d3 commit cea402c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,13 @@ protected function output() {
$logged_out_class = ' logged_out';
}
$res .= '<div class="d-none position-fixed top-0 end-0 mt-3 me-3 sys_messages'.$logged_out_class.'">';
if (!empty($msgs)) {
$res .= implode(',', array_map(function($v) {
if (preg_match("/ERR/", $v)) {
return sprintf('<div class="alert alert-danger alert-dismissible fade show" role="alert"><i class="bi bi-exclamation-triangle me-2"></i><span class="danger">%s</span>', $this->trans(substr((string) $v, 3)));
}
else {
return sprintf('<div class="alert alert-success alert-dismissible fade show" role="alert"><i class="bi bi-check-circle me-2"></i><span class="info">%s</span>', $this->trans($v));
}
}, $msgs));
foreach ($msgs as $msg) {
if (preg_match("/ERR/", $msg)) {
$res .= sprintf('<div class="alert alert-danger alert-dismissible fade show" role="alert"><i class="bi bi-exclamation-triangle me-2"></i><span class="danger">%s</span>', $this->trans(substr((string) $msg, 3)));
}
else {
$res .= sprintf('<div class="alert alert-success alert-dismissible fade show" role="alert"><i class="bi bi-check-circle me-2"></i><span class="info">%s</span>', $this->trans($msg));
}
$res .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
}
$res .= '</div>';
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ public function test_msgs() {
$test = new Output_Test('msgs', 'core');
$test->handler_response = array('router_login_state' => false);
$res = $test->run();
$this->assertEquals(array('<div class="d-none position-fixed top-0 end-0 mt-3 me-3 sys_messages logged_out"><div class="alert alert-danger alert-dismissible fade show" role="alert"><i class="bi bi-exclamation-triangle me-2"></i><span class="danger">foo</span>,<div class="alert alert-success alert-dismissible fade show" role="alert"><i class="bi bi-check-circle me-2"></i><span class="info">foo</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div></div>'), $res->output_response);
$this->assertEquals(array('<div class="d-none position-fixed top-0 end-0 mt-3 me-3 sys_messages logged_out"><div class="alert alert-danger alert-dismissible fade show" role="alert"><i class="bi bi-exclamation-triangle me-2"></i><span class="danger">foo</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div><div class="alert alert-success alert-dismissible fade show" role="alert"><i class="bi bi-check-circle me-2"></i><span class="info">foo</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div></div>'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit cea402c

Please sign in to comment.