Skip to content

Commit 9702912

Browse files
committed
Disable button while remote broker certificates are being created
It should only be possible to click the button once. It should only be possible to click the button again after a page reload. CMK-21644 Change-Id: Id89ae4aa4cdf0d93de9dded26efb1bb28bcd4c6b
1 parent e783bc7 commit 9702912

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

cmk/gui/htmllib/generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"render_qr_code",
5454
"render_stats_table",
5555
"insert_before",
56+
"lock_and_redirect",
5657
]
5758

5859

cmk/gui/wato/pages/sites.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from cmk.gui.exceptions import FinalizeRequest, MKUserError
4747
from cmk.gui.htmllib.generator import HTMLWriter
4848
from cmk.gui.htmllib.html import html
49+
from cmk.gui.htmllib.tag_rendering import render_end_tag
4950
from cmk.gui.http import request
5051
from cmk.gui.i18n import _
5152
from cmk.gui.log import logger
@@ -1224,12 +1225,21 @@ def _show_message_broker_connection(
12241225
) -> None:
12251226
table.cell("Message broker connection")
12261227
if is_replication_enabled(site):
1227-
login_url = make_action_link([("mode", "sites"), ("_trigger_certs_creation", site_id)])
1228+
trigger_url = make_action_link(
1229+
[("mode", "sites"), ("_trigger_certs_creation", site_id)]
1230+
)
1231+
html.open_ts_container(
1232+
container="div",
1233+
function_name="lock_and_redirect",
1234+
arguments={"redirect_url": trigger_url},
1235+
)
12281236
html.icon_button(
1229-
login_url,
1230-
_("Create remote broker certificates"),
1231-
"recreate_broker_certificate",
1237+
url="javascript:void(0)",
1238+
title=_("Create remote broker certificates"),
1239+
icon="recreate_broker_certificate",
1240+
class_=["lockable"],
12321241
)
1242+
html.write_html(render_end_tag("div"))
12331243

12341244
html.open_div(id_=f"message_broker_status_{site_id}", class_="connection_status")
12351245
if is_replication_enabled(site):

packages/cmk-frontend/src/js/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as host_diagnose from "./modules/host_diagnose";
3535
import * as hover from "./modules/hover";
3636
import * as keyboard_shortcuts from "./modules/keyboard_shortcuts";
3737
import {insert_before} from "./modules/layout";
38+
import {lock_and_redirect} from "./modules/sites";
3839
import * as license_usage_timeseries_graph from "./modules/license_usage/license_usage_timeseries_graph";
3940
import * as nodevis from "./modules/nodevis/main";
4041
import * as ntop_alerts from "./modules/ntop/ntop_alerts";
@@ -80,6 +81,7 @@ const callable_functions: {[name: string]: CallableFunction} = {
8081
render_stats_table: render_stats_table,
8182
render_qr_code: render_qr_code,
8283
insert_before: insert_before,
84+
lock_and_redirect: lock_and_redirect,
8385
};
8486

8587
$(() => {

packages/cmk-frontend/src/js/modules/sites.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import $ from "jquery";
88

99
import {call_ajax} from "./ajax";
10+
import {add_class} from "@/modules/utils";
1011

1112
interface AjaxJsonResponse<Result = any> {
1213
result_code: number;
@@ -80,3 +81,31 @@ function show_error(msg: string) {
8081
// Remove all loading icons
8182
$(".reloading").remove();
8283
}
84+
85+
export async function lock_and_redirect(
86+
iconButtonContainer: HTMLElement,
87+
options: Record<string, string>,
88+
) {
89+
if (!("redirect_url" in options)) {
90+
throw new Error(
91+
"lock_and_redirect has to set redirect_url in options!",
92+
);
93+
}
94+
const iconButtons = iconButtonContainer.getElementsByTagName("a");
95+
if (iconButtons.length != 1) {
96+
throw new Error(
97+
`lock_and_redirect: expected exactly one a-element, got ${iconButtons.length}`,
98+
);
99+
}
100+
const iconButton: HTMLAnchorElement = iconButtons[0];
101+
102+
const handler = function () {
103+
add_class(iconButton, "disabled");
104+
//@ts-ignore
105+
iconButton.disabled = true; // TODO: i don't think this has any effect on a non input element.
106+
window.location.href = options.redirect_url;
107+
// just to be sure, adding the disabled class normally should be enough
108+
iconButton.removeEventListener("click", handler);
109+
};
110+
iconButton.addEventListener("click", handler);
111+
}

packages/cmk-frontend/src/themes/facelift/scss/_wato.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
white-space: nowrap;
3333
}
3434
}
35+
a.disabled {
36+
pointer-events: none;
37+
opacity: $inactive-opacity;
38+
}
3539
}
3640

3741
.wato td.right {

0 commit comments

Comments
 (0)