Skip to content
Browse files

Array mods in layout structure. #47

  • Loading branch information...
1 parent 22b27ff commit e6d05a673dfde48f3f574a421c0e1c008068bfa7 @jvalkeal jvalkeal committed Dec 31, 2011
Showing with 17 additions and 3 deletions.
  1. +7 −0 dojo-release-1.5.0-src/hyperic/util/Util.js
  2. +10 −3 dojo-release-1.5.0-src/hyperic/wallmount/Player.js
View
7 dojo-release-1.5.0-src/hyperic/util/Util.js
@@ -36,3 +36,10 @@ hyperic.util.Util.zeroMinInsets = function(/*Object*/obj){
right: Math.max(obj.right,0)
};
};
+
+hyperic.util.Util.toArray = function(t){
+ // summary:
+ // Converts object to array of size 1. If it's
+ // already an array, return it unmodified.
+ return dojo.isArray(t) ? t : [t];
+};
View
13 dojo-release-1.5.0-src/hyperic/wallmount/Player.js
@@ -27,6 +27,7 @@
dojo.provide("hyperic.wallmount.Player");
dojo.require("hyperic.wallmount.WindowUtil");
+dojo.require("hyperic.util.Util");
dojo.require("hyperic.data.MetricStore");
hyperic.wallmount.Player.loadLayout = function(/*String*/url, /*Boolean*/ sendAnim, /*String*/node) {
@@ -84,7 +85,11 @@ hyperic.wallmount.Player.createLayout = function(/*jsondata*/data, /*String*/nod
dojo.style(wallmountPane,'width',data.w||9999);
dojo.style(wallmountPane,'height',data.h||9999);
- var items = data.items;
+ // items should be a list (items:[{},{}...]
+ // if it's an object, we assume list with one object
+ // -> make conversion
+ var items = hyperic.util.Util.toArray(data.items);
+
for(var i=0; i<items.length; i++) {
var args = {
x: items[i].x,
@@ -119,8 +124,10 @@ hyperic.wallmount.Player.createLayout = function(/*jsondata*/data, /*String*/nod
source = hyperic.wallmount.WindowUtil.newWindow(args, wallmountPane);
}
- for(var j = 0; j<items[i].items.length; j++){
- var witem = items[i].items[j];
+ var widgetItems = hyperic.util.Util.toArray(items[i].items);
+
+ for(var j = 0; j<widgetItems.length; j++){
+ var witem = widgetItems[j];
source.insertNodes(false, [witem]);
}
}

0 comments on commit e6d05a6

Please sign in to comment.
Something went wrong with that request. Please try again.