From 1f7c17d688c3340b31d2e1c2b7205b10bd806968 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 25 May 2012 16:37:24 -0700 Subject: Objects Controller - Now keeps track of document's object instances, including added components --- js/controllers/objects-controller.js | 83 +++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 25 deletions(-) (limited to 'js/controllers/objects-controller.js') diff --git a/js/controllers/objects-controller.js b/js/controllers/objects-controller.js index 543aa96f..5bab9eab 100644 --- a/js/controllers/objects-controller.js +++ b/js/controllers/objects-controller.js @@ -8,46 +8,79 @@ var Montage = require("montage/core/core").Montage, Component = require("montage/ui/component").Component; var objectsController = exports.ObjectsController = Montage.create(Component, { - objects : { - value: [] - }, - - handleAppLoaded : { - value: function() { - ///// Bind app's activeDocument property to - ///// objects controller's _activeDocument property - } - }, - - deserializedFromTemplate : { - value: function() { - this.eventManager.addEventListener( "appLoaded", this, false); - }, - enumerable : false - }, _activeDocument : { value : null, enumerable : false }, - activeDocument : { get : function() { return this._activeDocument; }, - set : function(document) { - ///// If the document is null set default stylesheets to null - if(!document) { return false; } + set : function(doc) { + if(!doc) { return false; } + // TODO: remove setTimeout when timing of montage initialization is done setTimeout(function() { - this.objects = document._document.application._template._deserializer.getObjectsFromLastDeserialization(); + this.bindToModelObjects(); }.bind(this), 1000); - - ///// setting document via binding - this._activeDocument = document; + this._activeDocument = doc; }, enumerable : false + }, + + objects : { + value: [] + }, + + _isBoundToModelObjects : { + value: null + }, + bindToModelObjects : { + value: function() { + //// Remove any previous bindings if previously bound + if(!this._isBoundToModelObjects) { + Object.deleteBinding(this, 'objects'); + this._isBoundToModelObjects = true; + } + + Object.defineBinding(this, 'objects', { + boundObject: this.activeDocument.model, + boundObjectPropertyPath: 'objects', + oneway: false + }); + } + }, + + /* -------------------------- + Binding Methods + ----------------------------- */ + + addBinding : { + value: function(bindingDescriptor) { + if(!bindingDescriptor.sourceObject || !bindingDescriptor.sourceObjectPropertyPath || !bindingDescriptor) { return; } + + Object.defineBinding(bindingDescriptor.sourceObject, bindingDescriptor.sourceObjectPropertyPath, bindingDescriptor); + } + }, + + removeBinding : { + value: function(bindingDescriptor) { + if(!bindingDescriptor) { return; } + + Object.deleteBinding(bindingDescriptor.sourceObject, bindingDescriptor.sourceObjectPropertyBindingPath); + } + }, + + editBindingPropertyPath : { + value: function(bindingDescriptor, newPropertyPath) { + this.removeBinding(bindingDescriptor); + + //this.addBinding() + + + } } }); \ No newline at end of file -- cgit v1.2.3