Skip to content

Commit 4ddea20

Browse files
Erwin Dondorperwindon
authored andcommitted
use new menus
1 parent cdc37c9 commit 4ddea20

26 files changed

+351
-285
lines changed

saltgui/static/scripts/CommandBox.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {Character} from "./Character.js";
44
import {Documentation} from "./Documentation.js";
5-
import {DropDownMenu} from "./DropDown.js";
5+
import {DropDownMenuCmd} from "./DropDownCmd.js";
66
import {Output} from "./output/Output.js";
77
import {ParseCommandLine} from "./ParseCommandLine.js";
88
import {Router} from "./Router.js";
@@ -17,14 +17,15 @@ export class CommandBox {
1717
this.api = pApi;
1818

1919
const cmdbox = document.getElementById("cmd-box");
20-
this.cmdmenu = new DropDownMenu(cmdbox);
20+
this.cmdmenu = new DropDownMenuCmd(cmdbox);
2121

22-
this.documentation = new Documentation(this.router, this);
2322
this._registerCommandBoxEventListeners();
2423

2524
RunType.createMenu();
2625
TargetType.createMenu();
2726

27+
this.documentation = new Documentation(pRouter, this);
28+
2829
const manualRun = document.getElementById("popup-run-command");
2930
Utils.addTableHelp(manualRun, "Click for help", "bottom-center");
3031
const helpButton = manualRun.querySelector("#help");
@@ -41,7 +42,7 @@ export class CommandBox {
4142
// since the storage-item is then not populated yet.
4243
return;
4344
}
44-
const menu = new DropDownMenu(titleElement);
45+
const menu = new DropDownMenuCmd(titleElement);
4546
const templatesText = Utils.getStorageItem("session", "templates", "{}");
4647
const templates = JSON.parse(templatesText);
4748
const keys = Object.keys(templates).sort();
@@ -51,7 +52,7 @@ export class CommandBox {
5152
if (!description) {
5253
description = "(" + key + ")";
5354
}
54-
menu.addMenuItem(
55+
menu.addMenuItemCmd(
5556
description,
5657
() => {
5758
CommandBox._applyTemplate(template);
@@ -178,7 +179,7 @@ export class CommandBox {
178179
TargetType.setTargetType(targetType);
179180
} else {
180181
// not in the template, revert to default
181-
TargetType.setTargetTypeDefault();
182+
TargetType.setTargetType(null);
182183
}
183184

184185
if (template.target) {
@@ -238,7 +239,7 @@ export class CommandBox {
238239
const commandField = document.getElementById("command");
239240
const commandValue = commandField.value;
240241

241-
const targetType = TargetType.menuTargetType._value;
242+
const targetType = TargetType.menuTargetType.getValue();
242243

243244
const patWhitespaceAll = /\s/g;
244245
const commandValueNoTabs = commandValue.replace(patWhitespaceAll, " ");
@@ -386,7 +387,7 @@ export class CommandBox {
386387

387388
// reset to default, so that its value is initially hidden
388389
RunType.setRunTypeDefault();
389-
TargetType.setTargetTypeDefault();
390+
TargetType.setTargetType(null);
390391

391392
if (Router.currentPage) {
392393
Router.currentPage.refreshPage();

saltgui/static/scripts/Documentation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ export class Documentation {
1717
this.router = pRouter;
1818
this.commandbox = pCommandBox;
1919

20-
pCommandBox.cmdmenu.addMenuItem(
20+
pCommandBox.cmdmenu.addMenuItemCmd(
2121
() => Documentation._manualRunMenuSysDocPrepare(),
2222
() => this._manualRunMenuSysDocRun());
23-
pCommandBox.cmdmenu.addMenuItem(
23+
pCommandBox.cmdmenu.addMenuItemCmd(
2424
() => Documentation._manualRunMenuHtmlDocPrepare(),
2525
() => Documentation._manualRunMenuHtmlDocRun());
26-
pCommandBox.cmdmenu.addMenuItem(
26+
pCommandBox.cmdmenu.addMenuItemCmd(
2727
() => Documentation._manualRunMenuBeaconNamePrepare(),
2828
() => Documentation._manualRunMenuBeaconNameRun());
2929

@@ -117,7 +117,7 @@ export class Documentation {
117117
dummyCommand = "sys.doc " + cmd;
118118
}
119119

120-
const targetType = TargetType.menuTargetType._value;
120+
const targetType = TargetType.menuTargetType.getValue();
121121

122122
const func = this.commandbox.getRunParams(targetType, target, docCommand, true);
123123
if (func === null) {

saltgui/static/scripts/DropDown.js

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global */
2+
13
import {Character} from "./Character.js";
24
import {Utils} from "./Utils.js";
35

@@ -8,7 +10,7 @@ import {Utils} from "./Utils.js";
810
// a) sets the title using pMenuItem.innerText = "xyz"
911
// b) arranges the visibility using pMenuItem.style.display = true/false
1012
// 2: the callback function
11-
// called when the menu item is selected: (pClickEvent) => { ... }
13+
// called when the menu item is selected: () => { ... }
1214
// all menu items are re-validated when the menu pops up
1315
// when all menu items are invisible, the menu-button must be made invisible
1416
// since this can happen at any time, this cannot be done when the menu is shown
@@ -18,6 +20,8 @@ import {Utils} from "./Utils.js";
1820
// the menu. when at least one item is visible, the menu is visible
1921
// remember to call verifyApp() when that is potentially the case
2022

23+
// superclass for DropDownMenuRadio, DropDownMenuCheckBox and DropDownMenuCmd
24+
2125
export class DropDownMenu {
2226

2327
// Creates an empty dropdown menu
@@ -70,19 +74,20 @@ export class DropDownMenu {
7074
let visibleCount = 0;
7175
if (this.menuDropdownContent) {
7276
for (const chld of this.menuDropdownContent.children) {
73-
const verifyCallBack = chld.verifyCallBack;
74-
if (verifyCallBack) {
75-
const title = verifyCallBack(chld);
77+
const titleCallBack = chld._titleCallBack;
78+
if (titleCallBack) {
79+
const title = titleCallBack(this, chld);
7680
if (title === null) {
7781
chld.style.display = "none";
7882
continue;
7983
}
80-
chld.innerText = DropDownMenu._sanitizeMenuItemTitle(title);
84+
chld.innerHTML = DropDownMenu._sanitizeMenuItemTitle(title);
8185
chld.style.removeProperty("display");
8286
}
8387
visibleCount += 1;
8488
}
8589
}
90+
8691
// hide the menu when it has no visible menu-items
8792
const displayVisible = this.menuDropdown.tagName === "TD" ? "table-cell" : "inline-block";
8893
const displayInvisible = "none";
@@ -102,32 +107,33 @@ export class DropDownMenu {
102107
// function is called each time the menu opens
103108
// This allows dynamic menuitem titles (use menuitem.innerText)
104109
// or visibility (use menuitem.style.display = "none"/"inline-block")
105-
addMenuItem (pTitle, pCallBack, pValue) {
110+
addMenuItem (pValue, pTitle, pCallBack) {
106111
const button = Utils.createDiv("run-command-button", "...");
107112
if (pValue) {
108113
button._value = pValue;
109114
}
110115
if (typeof pTitle === "string") {
111116
button.innerText = DropDownMenu._sanitizeMenuItemTitle(pTitle);
112117
} else {
113-
button.verifyCallBack = pTitle;
118+
button._titleCallBack = pTitle;
114119
}
115120
button.addEventListener("click", (pClickEvent) => {
116121
pClickEvent.target.parentElement.style.display = "none";
117122
setTimeout(() => {
118123
pClickEvent.target.parentElement.style.display = "";
119124
}, 500);
120-
this._callback(pClickEvent, pCallBack, pValue);
125+
this._callback(pCallBack, pValue);
121126
pClickEvent.stopPropagation();
122127
});
123128
this.menuDropdownContent.appendChild(button);
124129
this.verifyAll();
125130
return button;
126131
}
127132

128-
_callback (pClickEvent, pCallBack, pValue) {
133+
_callback (pCallBack, pValue) {
129134
this._value = pValue;
130-
pCallBack(pClickEvent);
135+
pCallBack(this, pValue);
136+
this.verifyAll();
131137
}
132138

133139
setTitle (pTitle) {
@@ -140,18 +146,4 @@ export class DropDownMenu {
140146
pTitle += Character.BLACK_DOWN_POINTING_TRIANGLE;
141147
this.menuButton.innerText = DropDownMenu._sanitizeMenuItemTitle(pTitle);
142148
}
143-
144-
__showMenu () {
145-
this.menuDropdown.style.display = "inline-block";
146-
}
147-
148-
__hideMenu () {
149-
this.menuDropdown.style.display = "none";
150-
}
151-
152-
clearMenu () {
153-
while (this.menuDropdownContent.firstChild) {
154-
this.menuDropdownContent.removeChild(this.menuDropdownContent.firstChild);
155-
}
156-
}
157149
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* global */
2+
3+
import {Character} from "./Character.js";
4+
import {DropDownMenu} from "./DropDown.js";
5+
6+
export class DropDownMenuCheckBox extends DropDownMenu {
7+
// constructor (pParentElement) {
8+
// super(pParentElement);
9+
// }
10+
11+
addMenuItemCheckBox (pValue, pTitle, pCallBack) {
12+
const menuItem = super.addMenuItem(pValue, pTitle, () => {
13+
menuItem._selected = !menuItem._selected;
14+
15+
if (menuItem._selected === true) {
16+
menuItem.innerText = Character.HEAVY_CHECK_MARK + " " + pTitle;
17+
} else {
18+
menuItem.innerText = pTitle;
19+
}
20+
21+
if (pCallBack) {
22+
pCallBack();
23+
}
24+
});
25+
}
26+
27+
isSet (pValue) {
28+
for (const menuItem of this.menuDropdownContent.childNodes) {
29+
if (menuItem._selected === true && menuItem._value === pValue) {
30+
return true;
31+
}
32+
}
33+
return false;
34+
}
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* global */
2+
3+
import {DropDownMenu} from "./DropDown.js";
4+
5+
export class DropDownMenuCmd extends DropDownMenu {
6+
// constructor (pParentElement) {
7+
// super(pParentElement);
8+
// }
9+
10+
addMenuItemCmd (pTitle, pCallBack) {
11+
return super.addMenuItem(
12+
null,
13+
pTitle,
14+
pCallBack
15+
);
16+
}
17+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* global */
2+
3+
import {DropDownMenu} from "./DropDown.js";
4+
5+
export class DropDownMenuRadio extends DropDownMenu {
6+
constructor (pParentElement) {
7+
super(pParentElement);
8+
this._value = null;
9+
this._defaultValue = null;
10+
}
11+
12+
getValue () {
13+
if (this._value === null) {
14+
return this._defaultValue;
15+
}
16+
return this._value;
17+
}
18+
19+
setValue (pValue) {
20+
this._value = pValue;
21+
}
22+
23+
setDefaultValue (pDefaultValue) {
24+
this._defaultValue = pDefaultValue;
25+
}
26+
27+
static _menuItemLabelCallBack (pMenu, pMenuItem) {
28+
let title;
29+
if (!pMenuItem._title) {
30+
title = "...";
31+
} else if (typeof pMenuItem._title === "string") {
32+
title = pMenuItem._title;
33+
} else {
34+
title = pMenuItem._title(pMenuItem);
35+
}
36+
37+
if (title === null) {
38+
// menu item will be hidden
39+
} else if (pMenuItem._value === pMenu._value) {
40+
// 25CF = BLACK CIRCLE
41+
title = "\u25CF " + title;
42+
} else if (pMenu._value === null && pMenuItem._value === pMenu._defaultValue) {
43+
// 25CB = WHITE CIRCLE
44+
title = "\u25CB " + title;
45+
}
46+
return title;
47+
}
48+
49+
static _menuItemActionCallBack (pMenu, pEvent, pValue) {
50+
pMenu._value = pValue;
51+
const menuItem = pEvent.target;
52+
let menuTitle = menuItem._title;
53+
if (typeof menuTitle !== "string") {
54+
menuTitle = menuTitle(menuItem);
55+
}
56+
pMenu.setTitle(menuTitle);
57+
}
58+
59+
addMenuItemRadio (pValue, pTitle) {
60+
const menuItem = super.addMenuItem(
61+
pValue,
62+
DropDownMenuRadio._menuItemLabelCallBack,
63+
DropDownMenuRadio._menuItemActionCallBack);
64+
65+
menuItem._title = pTitle;
66+
}
67+
}

saltgui/static/scripts/ParseCommandLine.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global */
2+
13
// Function to parse a commandline
24
// The line is broken into individual tokens
35
// Each token that is recognized as a JS type will get that type

0 commit comments

Comments
 (0)