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();
}
}
......
......@@ -60,7 +60,6 @@ public abstract class RequestHandler {
public abstract void process(long sid, ObjectNode payload);
// ===================================================================
// === Convenience methods...
......@@ -139,4 +138,17 @@ public abstract class RequestHandler {
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,15 +96,17 @@
};
}
function makeButton(callback, text, keyName) {
function makeButton(callback, text, keyName, chained) {
var cb = fs.isF(callback),
key = fs.isS(keyName);
function invoke() {
cb && cb();
if (!chained) {
clearBindings();
panel.hide();
}
}
if (key) {
keyBindings[key] = invoke;
......@@ -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);
......