Debian Codegraph @

pkg/playground/service.js

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 import cockpit from "cockpit";
3
4 import '../lib/patternfly/patternfly-6-cockpit.scss';
5
6 import * as service from "service";
7
8 document.addEventListener("DOMContentLoaded", () => {
9 let proxy;
10
11 function navigate() {
12 proxy = service.proxy(cockpit.location.path[0] || "");
13
14 function show() {
15 function s(t) {
16 document.getElementById(t).textContent = JSON.stringify(proxy[t]);
17 }
18 s('exists');
19 s('state');
20 s('enabled');
21 }
22
23 proxy.addEventListener("changed", show);
24 show();
25
26 document.body.removeAttribute("hidden");
27 }
28
29 function b(t) {
30 document.getElementById(t).addEventListener("click", () => {
31 proxy[t]()
32 .catch(error => console.error("action", t, "failed:", JSON.stringify(error)));
33 });
34 }
35
36 b('start');
37 b('stop');
38 b('enable');
39 b('disable');
40
41 cockpit.addEventListener("locationchanged", navigate);
42 navigate();
43 });