From 9b8a24a7360416d5750828c9580e33dd336ff882 Mon Sep 17 00:00:00 2001 From: François Frisch Date: Fri, 16 Mar 2012 17:57:18 -0700 Subject: Getting ownerComponent bindings --- .../templates/montage-html/main.reel/main.js | 43 +++++++++++----------- node_modules/components-data/textfield.json | 4 ++ node_modules/montage/ui/text-input.js | 22 +++++++++++ 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/js/document/templates/montage-html/main.reel/main.js b/js/document/templates/montage-html/main.reel/main.js index 567f481c..ee23e844 100644 --- a/js/document/templates/montage-html/main.reel/main.js +++ b/js/document/templates/montage-html/main.reel/main.js @@ -17,7 +17,25 @@ exports.Main = Montage.create(Component, { */ templateDidLoad: { value: function(){ - window.addComponent = this.addComponentToUserDocument; + var self = this; + window.addComponent = function(element, data, callback) { + var component; + + component = require.async(data.path) + .then(function(component) { + var componentRequire = component[data.name]; + var componentInstance = componentRequire.create(); + + componentInstance.element = element; + //componentInstance.deserializedFromTemplate(); + componentInstance.needsDraw = true; + componentInstance.ownerComponent = self; + + callback(componentInstance, element); + }) + .end(); + + }; // window.addBinding = this.addBindingToUserDocument; // Dispatch event when this template has loaded. @@ -29,26 +47,9 @@ exports.Main = Montage.create(Component, { } }, - // Adding components to the user document by using a async require. - addComponentToUserDocument:{ - value:function(element, data, callback){ - - var component; - - component = require.async(data.path) - .then(function(component) { - var componentRequire = component[data.name]; - var componentInstance = componentRequire.create(); - - componentInstance.element = element; - //componentInstance.deserializedFromTemplate(); - componentInstance.needsDraw = true; - - callback(componentInstance, element); - }) - .end(); - - } + location: { + value:null, + enumerable:false } }); \ No newline at end of file diff --git a/node_modules/components-data/textfield.json b/node_modules/components-data/textfield.json index 7164b8b3..39c65eab 100644 --- a/node_modules/components-data/textfield.json +++ b/node_modules/components-data/textfield.json @@ -7,6 +7,10 @@ "properties": [ { + "name": "valueBinding", + "type": "string", + "default": null + },{ "name": "accept", "type": "string", "default": null diff --git a/node_modules/montage/ui/text-input.js b/node_modules/montage/ui/text-input.js index cdd20c78..d707fa69 100644 --- a/node_modules/montage/ui/text-input.js +++ b/node_modules/montage/ui/text-input.js @@ -79,6 +79,28 @@ var TextInput = exports.TextInput = Montage.create(NativeControl, { } }, + _valueBinding: { + value: null + }, + + valueBinding: { + get: function() { + return this._valueBinding; + }, + set: function(value) { + if (this._valueBinding !== value) { + if (this._valueBinding !== null) { + Object.deleteBinding(this, "value"); + } + this._valueBinding = value; + if (String.isString(value)) { + Object.defineBinding(this, "value", {boundObject: this.ownerComponent, boundObjectPropertyPath: value}); + + } + } + } + }, + // set value from user input /** @private -- cgit v1.2.3