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') 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 From e09efe3212e86ac794de3fc8ecfc6cdef7b15181 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Wed, 30 May 2012 15:02:23 -0700 Subject: Objects Controller - Add bindable controller properties, and bindings getter --- js/controllers/objects-controller.js | 75 +++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 14 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/objects-controller.js b/js/controllers/objects-controller.js index 5bab9eab..cd0139a0 100644 --- a/js/controllers/objects-controller.js +++ b/js/controllers/objects-controller.js @@ -9,13 +9,13 @@ var Montage = require("montage/core/core").Montage, var objectsController = exports.ObjectsController = Montage.create(Component, { - _activeDocument : { + _currentDocument : { value : null, enumerable : false }, - activeDocument : { + currentDocument : { get : function() { - return this._activeDocument; + return this._currentDocument; }, set : function(doc) { if(!doc) { return false; } @@ -25,7 +25,7 @@ var objectsController = exports.ObjectsController = Montage.create(Component, { this.bindToModelObjects(); }.bind(this), 1000); - this._activeDocument = doc; + this._currentDocument = doc; }, enumerable : false }, @@ -46,7 +46,7 @@ var objectsController = exports.ObjectsController = Montage.create(Component, { } Object.defineBinding(this, 'objects', { - boundObject: this.activeDocument.model, + boundObject: this.currentDocument.model, boundObjectPropertyPath: 'objects', oneway: false }); @@ -58,28 +58,75 @@ var objectsController = exports.ObjectsController = Montage.create(Component, { ----------------------------- */ addBinding : { - value: function(bindingDescriptor) { - if(!bindingDescriptor.sourceObject || !bindingDescriptor.sourceObjectPropertyPath || !bindingDescriptor) { return; } + value: function(bindingArgs) { + if(!bindingArgs.sourceObject || !bindingArgs.sourceObjectPropertyPath || !bindingArgs) { return; } - Object.defineBinding(bindingDescriptor.sourceObject, bindingDescriptor.sourceObjectPropertyPath, bindingDescriptor); + Object.defineBinding(bindingArgs.sourceObject, bindingArgs.sourceObjectPropertyPath, bindingArgs); } }, removeBinding : { - value: function(bindingDescriptor) { - if(!bindingDescriptor) { return; } + value: function(bindingArgs) { + if(!bindingArgs) { return; } - Object.deleteBinding(bindingDescriptor.sourceObject, bindingDescriptor.sourceObjectPropertyBindingPath); + Object.deleteBinding(bindingArgs.sourceObject, bindingArgs.sourceObjectPropertyPath); } }, editBindingPropertyPath : { - value: function(bindingDescriptor, newPropertyPath) { - this.removeBinding(bindingDescriptor); + value: function(bindingArgs, newPropertyPath) { + this.removeBinding(bindingArgs); - //this.addBinding() + bindingArgs.boundObjectPropertyPath = 'newPropertyPath'; + this.addBinding(bindingArgs); + } + }, + + getObjectBindings : { + value: function(object) { + var descriptors = object._bindingDescriptors, + bindingsArray = [], + property, descriptor, bindingArgsObject; + + for(property in descriptors) { + if(descriptors.hasOwnProperty(property)) { + descriptor = descriptors[property]; + + bindingArgsObject = { + sourceObject : object, + sourceObjectPropertyPath : property, + boundObject : descriptor.boundObject, + boundObjectPropertyPath : descriptor.boundObjectPropertyPath, + onweway : descriptor.oneway + }; + + bindingsArray.push(bindingArgsObject); + } + } + + return bindingsArray; + } + }, + + /* ---- Bindable controller properties ---- */ + + currentObjectBindings : { + value: null + }, + _currentObject : { + value: null + }, + currentObject : { + get: function() { + return this._currentObject; + }, + set: function(value) { + if(value === this._currentObject) { return; } + + this.currentObjectBindings = this.getObjectBindings(value); + this._currentObject = value; } } -- cgit v1.2.3 From 0f59ef2a4b78fbcee402255857e8355a67fa7e66 Mon Sep 17 00:00:00 2001 From: Eric Guzman Date: Fri, 1 Jun 2012 12:53:24 -0700 Subject: Bindings Panel - Update binding panel components --- js/controllers/objects-controller.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'js/controllers') diff --git a/js/controllers/objects-controller.js b/js/controllers/objects-controller.js index cd0139a0..a02c3045 100644 --- a/js/controllers/objects-controller.js +++ b/js/controllers/objects-controller.js @@ -109,6 +109,26 @@ var objectsController = exports.ObjectsController = Montage.create(Component, { } }, + /* ---- Bindable Properties ---- */ + + getEnumerableProperties : { + value: function(object, excludeUnderscoreProperties) { + var properties = []; + + for(var key in object) { + properties.push(key); + } + + if(excludeUnderscoreProperties) { + properties = properties.filter(function(property) { + return property[0] !== '_'; + }, this); + } + + return properties.sort(); + } + }, + /* ---- Bindable controller properties ---- */ currentObjectBindings : { -- cgit v1.2.3