From 5b303f858ab78877f26f61e87230b010460ee03b Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 20 Jun 2012 11:28:32 -0700 Subject: Objects Tray - Filter list of components for those without visual representation --- js/controllers/objects-controller.js | 14 ++++++++++++++ js/panels/objects/object.reel/object.js | 16 ++++++++++++++++ js/stage/objects-tray.reel/objects-tray.html | 8 +++++++- js/stage/objects-tray.reel/objects-tray.js | 23 ++++++++++++++++------- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/js/controllers/objects-controller.js b/js/controllers/objects-controller.js index b8efd432..54ff14ba 100644 --- a/js/controllers/objects-controller.js +++ b/js/controllers/objects-controller.js @@ -190,6 +190,8 @@ var objectsController = exports.ObjectsController = Montage.create(Montage, { } }, + /* ----- Utils ----- */ + _hasPrototype : { value: function(object, prototypeName) { var prototypes = this.getPrototypes(object).map(function(proto) { @@ -201,6 +203,18 @@ var objectsController = exports.ObjectsController = Montage.create(Montage, { } }, + ///// Returns true if the element is "non-visual", i.e. is not a component, + ///// and has not element property + + isOffStageObject : { + value: function(object) { + var isComponent = this._hasPrototype(object, "Component"), + hasValidElement = object.element && object.element.parentNode; + + return !isComponent || !hasValidElement; + } + }, + /* ---- Bindable controller properties ---- */ currentObjectBindings : { diff --git a/js/panels/objects/object.reel/object.js b/js/panels/objects/object.reel/object.js index 76f1b5bf..b8bf1b1e 100644 --- a/js/panels/objects/object.reel/object.js +++ b/js/panels/objects/object.reel/object.js @@ -75,6 +75,22 @@ exports.Object = Montage.create(Component, { }, + /* --------------------- + Event Handlers + --------------------- */ + + handleClick: { + value: function(e) { + this.parentComponent.parentComponent.displayHUDForObject(this.sourceObject); + } + }, + + prepareForDraw : { + value: function() { + this.iconElement.addEventListener('click', this, false); + } + }, + draw : { value: function() { if(this.type) { diff --git a/js/stage/objects-tray.reel/objects-tray.html b/js/stage/objects-tray.reel/objects-tray.html index 710e3edf..5a0db85e 100644 --- a/js/stage/objects-tray.reel/objects-tray.html +++ b/js/stage/objects-tray.reel/objects-tray.html @@ -39,7 +39,13 @@ "bindings": { "sourceObject" : {"<-": "@repetition.objectAtCurrentIteration"}, "identifier" : {"<-": "@repetition.objectAtCurrentIteration.identifier"} - } + }, + "listeners": [ + { + "type": "click", + "listener": {"@": "owner"} + } + ] } } diff --git a/js/stage/objects-tray.reel/objects-tray.js b/js/stage/objects-tray.reel/objects-tray.js index 3872c8b6..360d6037 100644 --- a/js/stage/objects-tray.reel/objects-tray.js +++ b/js/stage/objects-tray.reel/objects-tray.js @@ -66,10 +66,7 @@ exports.ObjectsTray = Montage.create(Component, { return true; } - var isComponent = this.application.ninja.objectsController._hasPrototype(obj, "Component"), - hasValidElement = obj.element && obj.element.parentNode; - - return !isComponent || !hasValidElement; + return this.application.ninja.objectsController.isOffStageObject(obj); } }, @@ -85,6 +82,15 @@ exports.ObjectsTray = Montage.create(Component, { } }, + displayHUDForObject : { + value: function(object) { + this.parentComponent.boundComponents.push(object); + } + }, + + /* --------------------- + Draw Cycle + --------------------- */ templateDidLoad: { value: function() { @@ -107,12 +113,15 @@ exports.ObjectsTray = Montage.create(Component, { "oneway": true }); + } + }, + willDraw : { + value: function() { if(this.objects) { - this.empty = !this.objects.length; + this._empty = !this.offStageObjectsController.organizedObjects.length; } else { - this.empty = true; + this._empty = true; } - } }, draw : { -- cgit v1.2.3