From 9274b3959384d21809c992f6f2e7860eb1682e06 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Tue, 5 Jun 2012 12:08:32 -0700 Subject: Binding Panel - Add getPropertyList and fix null currentObject --- js/controllers/objects-controller.js | 37 +++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'js/controllers/objects-controller.js') diff --git a/js/controllers/objects-controller.js b/js/controllers/objects-controller.js index 2c9f2d66..32f24d5c 100644 --- a/js/controllers/objects-controller.js +++ b/js/controllers/objects-controller.js @@ -113,12 +113,38 @@ var objectsController = exports.ObjectsController = Montage.create(Component, { /* ---- Bindable Properties ---- */ - getEnumerableProperties : { + getPropertyList : { value: function(object, excludeUnderscoreProperties) { + var object_i = object, + prototypes = [object_i]; + + ///// Collect prototypes + while(Object.getPrototypeOf(object_i)) { + object_i = Object.getPrototypeOf(object_i); + prototypes.push(object_i); + } + + return prototypes.map(function(proto) { + var metadata = proto._montage_metadata, + objectName = (metadata) ? metadata.objectName : "Object"; + + return { + category : objectName, + properties : this.getPropertiesFromObject(proto) + }; + }, this); + + } + }, + + getPropertiesFromObject : { + value: function (object, excludeUnderscoreProperties) { var properties = []; for(var key in object) { - properties.push(key); + if(object.hasOwnProperty(key)) { + properties.push(key); + } } if(excludeUnderscoreProperties) { @@ -146,7 +172,12 @@ var objectsController = exports.ObjectsController = Montage.create(Component, { set: function(value) { if(value === this._currentObject) { return; } - this.currentObjectBindings = this.getObjectBindings(value); + if(value) { + this.currentObjectBindings = this.getObjectBindings(value); + console.log("Property list", this.getPropertyList(value, true)); + } else { + this.currentObjectBindings = []; + } this._currentObject = value; } -- cgit v1.2.3