|
1 | 1 | /* global console document */ |
2 | 2 |
|
3 | 3 | import {Character} from "./Character.js"; |
4 | | -import {DropDownMenu} from "./DropDown.js"; |
| 4 | +import {DropDownMenuRadio} from "./DropDownRadio.js"; |
5 | 5 | import {Utils} from "./Utils.js"; |
6 | 6 |
|
7 | 7 | export class TargetType { |
8 | 8 |
|
9 | 9 | static createMenu () { |
10 | 10 | const targetbox = document.getElementById("target-box"); |
11 | | - TargetType.menuTargetType = new DropDownMenu(targetbox); |
| 11 | + TargetType.menuTargetType = new DropDownMenuRadio(targetbox); |
12 | 12 | // do not show the menu title at first |
13 | | - TargetType.menuTargetType.addMenuItem("Normal", this._manualUpdateTargetTypeText, "glob"); |
14 | | - TargetType.menuTargetType.addMenuItem("List", this._manualUpdateTargetTypeText, "list"); |
15 | | - TargetType.menuTargetType.addMenuItem(TargetType._targetTypeNodeGroupPrepare, this._manualUpdateTargetTypeText, "nodegroup"); |
16 | | - TargetType.menuTargetType.addMenuItem("Compound", this._manualUpdateTargetTypeText, "compound"); |
17 | | - TargetType.setTargetTypeDefault(); |
| 13 | + TargetType.menuTargetType.setTitle(""); |
| 14 | + TargetType.menuTargetType.addMenuItemRadio("glob", "Normal"); |
| 15 | + TargetType.menuTargetType.addMenuItemRadio("list", "List"); |
| 16 | + TargetType.menuTargetType.addMenuItemRadio("nodegroup", (pMenuItem) => TargetType._targetTypeNodeGroupPrepare(pMenuItem)); |
| 17 | + TargetType.menuTargetType.addMenuItemRadio("compound", "Compound"); |
| 18 | + TargetType.autoSelectTargetType(""); |
18 | 19 | } |
19 | 20 |
|
20 | 21 | // It takes a while before we known the list of nodegroups |
@@ -85,46 +86,34 @@ export class TargetType { |
85 | 86 | } |
86 | 87 | menuItems[i].innerText = menuItemText; |
87 | 88 | } |
| 89 | + return null; |
88 | 90 | } |
89 | 91 |
|
90 | 92 | static autoSelectTargetType (pTarget) { |
91 | 93 |
|
92 | | - if (!TargetType.menuTargetType._system) { |
93 | | - // user has selected the value, do not touch it |
94 | | - return; |
95 | | - } |
96 | | - |
97 | 94 | if (pTarget.includes("@") || pTarget.includes(" ") || |
98 | 95 | pTarget.includes("(") || pTarget.includes(")")) { |
99 | 96 | // "@" is a strong indicator for compound target |
100 | 97 | // but "space", "(" and ")" are also typical for compound target |
101 | | - TargetType.menuTargetType._value = "compound"; |
| 98 | + TargetType.menuTargetType.setDefaultValue("compound"); |
102 | 99 | } else if (pTarget.includes(",")) { |
103 | 100 | // "," is a strong indicator for list target (when it is also not compound) |
104 | | - TargetType.menuTargetType._value = "list"; |
| 101 | + TargetType.menuTargetType.setDefaultValue("list"); |
105 | 102 | } else if (pTarget.startsWith("#")) { |
106 | 103 | // "#" at the start of a line is a strong indicator for nodegroup target |
107 | 104 | // this is not a SALTSTACK standard, but our own invention |
108 | | - TargetType.menuTargetType._value = "nodegroup"; |
| 105 | + TargetType.menuTargetType.setDefaultValue("nodegroup"); |
109 | 106 | } else { |
110 | | - TargetType.menuTargetType._value = "glob"; |
| 107 | + TargetType.menuTargetType.setDefaultValue("glob"); |
111 | 108 | } |
112 | | - |
113 | | - // show the new title |
114 | | - TargetType._updateTargetTypeText(); |
115 | 109 | } |
116 | 110 |
|
117 | 111 | static setTargetType (pTargetType) { |
118 | | - TargetType.menuTargetType._value = pTargetType; |
119 | | - TargetType.menuTargetType._system = true; |
120 | | - TargetType._updateTargetTypeText(); |
| 112 | + TargetType.menuTargetType.setValue(pTargetType); |
121 | 113 | } |
122 | 114 |
|
123 | 115 | static _getTargetType () { |
124 | | - const targetType = TargetType.menuTargetType._value; |
125 | | - if (targetType === undefined || targetType === "") { |
126 | | - return "glob"; |
127 | | - } |
| 116 | + const targetType = TargetType.menuTargetType.getValue(); |
128 | 117 | return targetType; |
129 | 118 | } |
130 | 119 |
|
|
0 commit comments