Simon Hunt

ONOS-4619: Web UI -- Support for chained dialog operations.

Also added bool() helper method to JsonUtils and RequestHandler.

Change-Id: Ie3a9db983f0936b1ad48488ce19d1cdc2e20c16a
......@@ -27,7 +27,8 @@ public final class JsonUtils {
private static final ObjectMapper MAPPER = new ObjectMapper();
// non-instantiable
private JsonUtils() { }
private JsonUtils() {
}
/**
* Wraps a message payload into an event structure for the given event
......@@ -98,7 +99,7 @@ public final class JsonUtils {
/**
* Returns the specified node property as a number.
*
* @param node message event
* @param node object node
* @param name property name
* @return property as number
*/
......@@ -109,7 +110,7 @@ public final class JsonUtils {
/**
* Returns the specified node property as a string.
*
* @param node message event
* @param node object node
* @param name property name
* @return property as a string
*/
......@@ -140,4 +141,14 @@ public final class JsonUtils {
return (ObjectNode) node.path(name);
}
/**
* Returns the specified node property as a boolean.
*
* @param node object node
* @param name property name
* @return property as a boolean
*/
public static boolean bool(ObjectNode node, String name) {
return node.path(name).asBoolean();
}
}
......
......@@ -53,14 +53,13 @@ public abstract class RequestHandler {
/**
* Processes the incoming message payload from the client.
*
* @param sid message sequence identifier
* @param sid message sequence identifier
* @param payload request message payload
*/
// TODO: remove sid from signature
public abstract void process(long sid, ObjectNode payload);
// ===================================================================
// === Convenience methods...
......@@ -120,7 +119,7 @@ public abstract class RequestHandler {
* Returns the specified node property as a string.
*
* @param node message event
* @param key property name
* @param key property name
* @return property as a string
*/
protected String string(ObjectNode node, String key) {
......@@ -130,13 +129,26 @@ public abstract class RequestHandler {
/**
* Returns the specified node property as a string, with a default fallback.
*
* @param node object node
* @param key property name
* @param defValue fallback value if property is absent
* @param node object node
* @param key property name
* @param defValue fallback value if property is absent
* @return property as a string
*/
protected String string(ObjectNode node, String key, String defValue) {
return JsonUtils.string(node, key, defValue);
}
/**
* Returns the specified node property as a boolean. More precisely, if
* the value for the given key is the string "true" then this returns true,
* false otherwise.
*
* @param node object node
* @param key property name
* @return property as a boolean
*/
protected boolean bool(ObjectNode node, String key) {
return JsonUtils.bool(node, key);
}
}
......
......@@ -96,14 +96,16 @@
};
}
function makeButton(callback, text, keyName) {
function makeButton(callback, text, keyName, chained) {
var cb = fs.isF(callback),
key = fs.isS(keyName);
function invoke() {
cb && cb();
clearBindings();
panel.hide();
if (!chained) {
clearBindings();
panel.hide();
}
}
if (key) {
......@@ -129,15 +131,23 @@
return dApi;
}
function addButton(cb, text, key) {
function addButton(cb, text, key, chained) {
if (pApi) {
pApi.appendFooter(makeButton(cb, text, key));
pApi.appendFooter(makeButton(cb, text, key, chained));
}
return dApi;
}
function _addOk(cb, text, chained) {
return addButton(cb, text || 'OK', 'enter', chained);
}
function addOk(cb, text) {
return addButton(cb, text || 'OK', 'enter');
return _addOk(cb, text, false);
}
function addOkChained(cb, text) {
return _addOk(cb, text, true);
}
function addCancel(cb, text) {
......@@ -164,6 +174,7 @@
addContent: addContent,
addButton: addButton,
addOk: addOk,
addOkChained: addOkChained,
addCancel: addCancel,
bindKeys: function () {
ks.dialogKeys(keyBindings);
......