ONOS-4619: Web UI -- Support for chained dialog operations.
Also added bool() helper method to JsonUtils and RequestHandler. Change-Id: Ie3a9db983f0936b1ad48488ce19d1cdc2e20c16a (cherry picked from commit 9bf93564)
Showing
3 changed files
with
49 additions
and
15 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 | } | ... | ... |
... | @@ -53,14 +53,13 @@ public abstract class RequestHandler { | ... | @@ -53,14 +53,13 @@ public abstract class RequestHandler { |
53 | /** | 53 | /** |
54 | * Processes the incoming message payload from the client. | 54 | * Processes the incoming message payload from the client. |
55 | * | 55 | * |
56 | - * @param sid message sequence identifier | 56 | + * @param sid message sequence identifier |
57 | * @param payload request message payload | 57 | * @param payload request message payload |
58 | */ | 58 | */ |
59 | // TODO: remove sid from signature | 59 | // TODO: remove sid from signature |
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 | ||
... | @@ -120,7 +119,7 @@ public abstract class RequestHandler { | ... | @@ -120,7 +119,7 @@ public abstract class RequestHandler { |
120 | * Returns the specified node property as a string. | 119 | * Returns the specified node property as a string. |
121 | * | 120 | * |
122 | * @param node message event | 121 | * @param node message event |
123 | - * @param key property name | 122 | + * @param key property name |
124 | * @return property as a string | 123 | * @return property as a string |
125 | */ | 124 | */ |
126 | protected String string(ObjectNode node, String key) { | 125 | protected String string(ObjectNode node, String key) { |
... | @@ -130,13 +129,26 @@ public abstract class RequestHandler { | ... | @@ -130,13 +129,26 @@ public abstract class RequestHandler { |
130 | /** | 129 | /** |
131 | * Returns the specified node property as a string, with a default fallback. | 130 | * Returns the specified node property as a string, with a default fallback. |
132 | * | 131 | * |
133 | - * @param node object node | 132 | + * @param node object node |
134 | - * @param key property name | 133 | + * @param key property name |
135 | - * @param defValue fallback value if property is absent | 134 | + * @param defValue fallback value if property is absent |
136 | * @return property as a string | 135 | * @return property as a string |
137 | */ | 136 | */ |
138 | protected String string(ObjectNode node, String key, String defValue) { | 137 | protected String string(ObjectNode node, String key, String defValue) { |
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,14 +96,16 @@ | ... | @@ -96,14 +96,16 @@ |
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 | - clearBindings(); | 105 | + if (!chained) { |
106 | - panel.hide(); | 106 | + clearBindings(); |
107 | + panel.hide(); | ||
108 | + } | ||
107 | } | 109 | } |
108 | 110 | ||
109 | if (key) { | 111 | if (key) { |
... | @@ -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