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 +++++++++++++++++++++++++----------- js/document/models/html.js | 5 +++ js/document/templates/app/main.js | 1 + js/document/views/design.js | 6 ++- 4 files changed, 69 insertions(+), 26 deletions(-) (limited to '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 diff --git a/js/document/models/html.js b/js/document/models/html.js index 9cc8ce92..10112565 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js @@ -69,6 +69,7 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { setComponentInstance: { value: function(instance, el) { this.userComponents[el.uuid] = instance; + this.objects.push(instance); } }, //////////////////////////////////////////////////////////////////// @@ -81,6 +82,10 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { return null; } } + }, + //////////////////////////////////////////////////////////////////// + objects : { + value: null } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// diff --git a/js/document/templates/app/main.js b/js/document/templates/app/main.js index a406abdb..91c46fda 100644 --- a/js/document/templates/app/main.js +++ b/js/document/templates/app/main.js @@ -29,6 +29,7 @@ exports.Main = Montage.create(Component, { var componentRequire = component[data.name]; var componentInstance = componentRequire.create(); + componentInstance._montage_metadata.label = data.name; componentInstance.element = element; componentInstance.needsDraw = true; diff --git a/js/document/views/design.js b/js/document/views/design.js index b3887fdf..75eb3695 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -363,11 +363,15 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { initMontage: { value: function (scripttags) { // + //debugger; this.iframe.contentWindow.document.body.addEventListener('mjsTemplateReady', function () { //Initializing template with user's seriliazation var template = this.iframe.contentWindow.mjsTemplate.create(); + template.initWithDocument(this.iframe.contentWindow.document); - template.instantiateWithOwnerAndDocument(null, this.iframe.contentWindow.document, function (e){/*Nothing just a required extra parameter*/}); + template.instantiateWithOwnerAndDocument(null, this.iframe.contentWindow.document, function (e){ + this.model.objects = template.deserializer.getObjectsFromLastDeserialization(); + }.bind(this)); }.bind(this), false); } }, -- cgit v1.2.3