1
0
Fork 0
fgdata/webgui/lib/props2.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* Wraps json properties into something like SGPropertyNodes
*/
(function(factory) {
if (typeof define === "function" && define.amd)// AMD. Register as an anonymous module.
define([
], factory); else // Browser globals
factory();
}(function() {
var SGPropertyNode = function(json) {
this.json = json;
};
SGPropertyNode.prototype.getValue = function() {
return this.json.value;
}
SGPropertyNode.prototype.getName = function() {
return this.json.name;
}
SGPropertyNode.prototype.getPath = function() {
return this.json.path;
}
SGPropertyNode.prototype.getIndex = function() {
return this.json.index;
}
SGPropertyNode.prototype.getChildren = function(name) {
var reply = [];
this.json.children.forEach(function(child) {
if (name && child.name == name)
reply.push(new SGPropertyNode(child));
});
return reply;
}
SGPropertyNode.prototype.getNode = function(name, index) {
if (!index)
index = 0;
for (var i = 0; i < this.json.children.length; i++) {
var child = this.json.children[i];
if (child.name == name && child.index == index)
return new SGPropertyNode(child);
}
}
return SGPropertyNode;
}));