ONOS-4619: Web UI -- Support for chained dialog operations.
Also added bool() helper method to JsonUtils and RequestHandler. Change-Id: Ie3a9db983f0936b1ad48488ce19d1cdc2e20c16a
Showing
3 changed files
with
42 additions
and
8 deletions
... | @@ -27,7 +27,8 @@ public final class JsonUtils { | ... | @@ -27,7 +27,8 @@ public final class JsonUtils { |
27 | private static final ObjectMapper MAPPER = new ObjectMapper(); | 27 | private static final ObjectMapper MAPPER = new ObjectMapper(); |
28 | 28 | ||
29 | // non-instantiable | 29 | // non-instantiable |
30 | - private JsonUtils() { } | 30 | + private JsonUtils() { |
31 | + } | ||
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Wraps a message payload into an event structure for the given event | 34 | * Wraps a message payload into an event structure for the given event |
... | @@ -98,7 +99,7 @@ public final class JsonUtils { | ... | @@ -98,7 +99,7 @@ public final class JsonUtils { |
98 | /** | 99 | /** |
99 | * Returns the specified node property as a number. | 100 | * Returns the specified node property as a number. |
100 | * | 101 | * |
101 | - * @param node message event | 102 | + * @param node object node |
102 | * @param name property name | 103 | * @param name property name |
103 | * @return property as number | 104 | * @return property as number |
104 | */ | 105 | */ |
... | @@ -109,7 +110,7 @@ public final class JsonUtils { | ... | @@ -109,7 +110,7 @@ public final class JsonUtils { |
109 | /** | 110 | /** |
110 | * Returns the specified node property as a string. | 111 | * Returns the specified node property as a string. |
111 | * | 112 | * |
112 | - * @param node message event | 113 | + * @param node object node |
113 | * @param name property name | 114 | * @param name property name |
114 | * @return property as a string | 115 | * @return property as a string |
115 | */ | 116 | */ |
... | @@ -140,4 +141,14 @@ public final class JsonUtils { | ... | @@ -140,4 +141,14 @@ public final class JsonUtils { |
140 | return (ObjectNode) node.path(name); | 141 | return (ObjectNode) node.path(name); |
141 | } | 142 | } |
142 | 143 | ||
144 | + /** | ||
145 | + * Returns the specified node property as a boolean. | ||
146 | + * | ||
147 | + * @param node object node | ||
148 | + * @param name property name | ||
149 | + * @return property as a boolean | ||
150 | + */ | ||
151 | + public static boolean bool(ObjectNode node, String name) { | ||
152 | + return node.path(name).asBoolean(); | ||
153 | + } | ||
143 | } | 154 | } | ... | ... |
... | @@ -60,7 +60,6 @@ public abstract class RequestHandler { | ... | @@ -60,7 +60,6 @@ public abstract class RequestHandler { |
60 | public abstract void process(long sid, ObjectNode payload); | 60 | public abstract void process(long sid, ObjectNode payload); |
61 | 61 | ||
62 | 62 | ||
63 | - | ||
64 | // =================================================================== | 63 | // =================================================================== |
65 | // === Convenience methods... | 64 | // === Convenience methods... |
66 | 65 | ||
... | @@ -139,4 +138,17 @@ public abstract class RequestHandler { | ... | @@ -139,4 +138,17 @@ public abstract class RequestHandler { |
139 | return JsonUtils.string(node, key, defValue); | 138 | return JsonUtils.string(node, key, defValue); |
140 | } | 139 | } |
141 | 140 | ||
141 | + /** | ||
142 | + * Returns the specified node property as a boolean. More precisely, if | ||
143 | + * the value for the given key is the string "true" then this returns true, | ||
144 | + * false otherwise. | ||
145 | + * | ||
146 | + * @param node object node | ||
147 | + * @param key property name | ||
148 | + * @return property as a boolean | ||
149 | + */ | ||
150 | + protected boolean bool(ObjectNode node, String key) { | ||
151 | + return JsonUtils.bool(node, key); | ||
152 | + } | ||
153 | + | ||
142 | } | 154 | } | ... | ... |
... | @@ -96,15 +96,17 @@ | ... | @@ -96,15 +96,17 @@ |
96 | }; | 96 | }; |
97 | } | 97 | } |
98 | 98 | ||
99 | - function makeButton(callback, text, keyName) { | 99 | + function makeButton(callback, text, keyName, chained) { |
100 | var cb = fs.isF(callback), | 100 | var cb = fs.isF(callback), |
101 | key = fs.isS(keyName); | 101 | key = fs.isS(keyName); |
102 | 102 | ||
103 | function invoke() { | 103 | function invoke() { |
104 | cb && cb(); | 104 | cb && cb(); |
105 | + if (!chained) { | ||
105 | clearBindings(); | 106 | clearBindings(); |
106 | panel.hide(); | 107 | panel.hide(); |
107 | } | 108 | } |
109 | + } | ||
108 | 110 | ||
109 | if (key) { | 111 | if (key) { |
110 | keyBindings[key] = invoke; | 112 | keyBindings[key] = invoke; |
... | @@ -129,15 +131,23 @@ | ... | @@ -129,15 +131,23 @@ |
129 | return dApi; | 131 | return dApi; |
130 | } | 132 | } |
131 | 133 | ||
132 | - function addButton(cb, text, key) { | 134 | + function addButton(cb, text, key, chained) { |
133 | if (pApi) { | 135 | if (pApi) { |
134 | - pApi.appendFooter(makeButton(cb, text, key)); | 136 | + pApi.appendFooter(makeButton(cb, text, key, chained)); |
135 | } | 137 | } |
136 | return dApi; | 138 | return dApi; |
137 | } | 139 | } |
138 | 140 | ||
141 | + function _addOk(cb, text, chained) { | ||
142 | + return addButton(cb, text || 'OK', 'enter', chained); | ||
143 | + } | ||
144 | + | ||
139 | function addOk(cb, text) { | 145 | function addOk(cb, text) { |
140 | - return addButton(cb, text || 'OK', 'enter'); | 146 | + return _addOk(cb, text, false); |
147 | + } | ||
148 | + | ||
149 | + function addOkChained(cb, text) { | ||
150 | + return _addOk(cb, text, true); | ||
141 | } | 151 | } |
142 | 152 | ||
143 | function addCancel(cb, text) { | 153 | function addCancel(cb, text) { |
... | @@ -164,6 +174,7 @@ | ... | @@ -164,6 +174,7 @@ |
164 | addContent: addContent, | 174 | addContent: addContent, |
165 | addButton: addButton, | 175 | addButton: addButton, |
166 | addOk: addOk, | 176 | addOk: addOk, |
177 | + addOkChained: addOkChained, | ||
167 | addCancel: addCancel, | 178 | addCancel: addCancel, |
168 | bindKeys: function () { | 179 | bindKeys: function () { |
169 | ks.dialogKeys(keyBindings); | 180 | ks.dialogKeys(keyBindings); | ... | ... |
-
Please register or login to post a comment