diff options
author | Armen Kesablyan | 2012-06-01 13:13:21 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-06-01 13:13:21 -0700 |
commit | 10d97af27fca224752ad04551ca5c41982222d1f (patch) | |
tree | 27d2899cca3a9f28a0b6e222d39436d83009fafc | |
parent | 9e187e40d9982654081e52be656e00b3ca4d36b5 (diff) | |
parent | 77677e5ffb08a5dec4bf0be279130d7b1a99d03f (diff) | |
download | ninja-10d97af27fca224752ad04551ca5c41982222d1f.tar.gz |
Merge branch 'binding' of https://github.com/dhg637/ninja-internal into binding
-rw-r--r-- | js/controllers/objects-controller.js | 148 | ||||
-rwxr-xr-x | js/document/models/html.js | 5 | ||||
-rw-r--r-- | js/document/templates/app/main.js | 1 | ||||
-rwxr-xr-x | js/document/views/design.js | 6 | ||||
-rwxr-xr-x | js/ninja.reel/ninja.html | 2 | ||||
-rw-r--r-- | js/panels/binding-panel.reel/binding-panel.css | 11 | ||||
-rw-r--r-- | js/panels/binding-panel.reel/binding-panel.html | 30 | ||||
-rw-r--r-- | js/panels/binding-panel.reel/binding-panel.js | 14 | ||||
-rw-r--r-- | js/panels/binding/binding-item.reel/binding-item.css | 45 | ||||
-rw-r--r-- | js/panels/binding/binding-item.reel/binding-item.html | 85 | ||||
-rw-r--r-- | js/panels/binding/binding-item.reel/binding-item.js | 88 | ||||
-rw-r--r-- | js/panels/objects/object.reel/object.html | 2 | ||||
-rw-r--r-- | js/panels/objects/object.reel/object.js | 32 | ||||
-rwxr-xr-x | node_modules/montage/core/event/binding.js | 24 |
14 files changed, 437 insertions, 56 deletions
diff --git a/js/controllers/objects-controller.js b/js/controllers/objects-controller.js index 543aa96f..a02c3045 100644 --- a/js/controllers/objects-controller.js +++ b/js/controllers/objects-controller.js | |||
@@ -8,46 +8,146 @@ var Montage = require("montage/core/core").Montage, | |||
8 | Component = require("montage/ui/component").Component; | 8 | Component = require("montage/ui/component").Component; |
9 | 9 | ||
10 | var objectsController = exports.ObjectsController = Montage.create(Component, { | 10 | var objectsController = exports.ObjectsController = Montage.create(Component, { |
11 | |||
12 | _currentDocument : { | ||
13 | value : null, | ||
14 | enumerable : false | ||
15 | }, | ||
16 | currentDocument : { | ||
17 | get : function() { | ||
18 | return this._currentDocument; | ||
19 | }, | ||
20 | set : function(doc) { | ||
21 | if(!doc) { return false; } | ||
22 | |||
23 | // TODO: remove setTimeout when timing of montage initialization is done | ||
24 | setTimeout(function() { | ||
25 | this.bindToModelObjects(); | ||
26 | }.bind(this), 1000); | ||
27 | |||
28 | this._currentDocument = doc; | ||
29 | }, | ||
30 | enumerable : false | ||
31 | }, | ||
32 | |||
11 | objects : { | 33 | objects : { |
12 | value: [] | 34 | value: [] |
13 | }, | 35 | }, |
14 | 36 | ||
15 | handleAppLoaded : { | 37 | _isBoundToModelObjects : { |
38 | value: null | ||
39 | }, | ||
40 | bindToModelObjects : { | ||
16 | value: function() { | 41 | value: function() { |
17 | ///// Bind app's activeDocument property to | 42 | //// Remove any previous bindings if previously bound |
18 | ///// objects controller's _activeDocument property | 43 | if(!this._isBoundToModelObjects) { |
44 | Object.deleteBinding(this, 'objects'); | ||
45 | this._isBoundToModelObjects = true; | ||
46 | } | ||
47 | |||
48 | Object.defineBinding(this, 'objects', { | ||
49 | boundObject: this.currentDocument.model, | ||
50 | boundObjectPropertyPath: 'objects', | ||
51 | oneway: false | ||
52 | }); | ||
19 | } | 53 | } |
20 | }, | 54 | }, |
55 | |||
56 | /* -------------------------- | ||
57 | Binding Methods | ||
58 | ----------------------------- */ | ||
59 | |||
60 | addBinding : { | ||
61 | value: function(bindingArgs) { | ||
62 | if(!bindingArgs.sourceObject || !bindingArgs.sourceObjectPropertyPath || !bindingArgs) { return; } | ||
21 | 63 | ||
22 | deserializedFromTemplate : { | 64 | Object.defineBinding(bindingArgs.sourceObject, bindingArgs.sourceObjectPropertyPath, bindingArgs); |
23 | value: function() { | 65 | } |
24 | this.eventManager.addEventListener( "appLoaded", this, false); | ||
25 | }, | ||
26 | enumerable : false | ||
27 | }, | 66 | }, |
28 | 67 | ||
29 | _activeDocument : { | 68 | removeBinding : { |
30 | value : null, | 69 | value: function(bindingArgs) { |
31 | enumerable : false | 70 | if(!bindingArgs) { return; } |
71 | |||
72 | Object.deleteBinding(bindingArgs.sourceObject, bindingArgs.sourceObjectPropertyPath); | ||
73 | } | ||
32 | }, | 74 | }, |
33 | 75 | ||
34 | activeDocument : { | 76 | editBindingPropertyPath : { |
35 | get : function() { | 77 | value: function(bindingArgs, newPropertyPath) { |
36 | return this._activeDocument; | 78 | this.removeBinding(bindingArgs); |
37 | }, | ||
38 | set : function(document) { | ||
39 | ///// If the document is null set default stylesheets to null | ||
40 | if(!document) { return false; } | ||
41 | 79 | ||
42 | setTimeout(function() { | 80 | bindingArgs.boundObjectPropertyPath = 'newPropertyPath'; |
43 | this.objects = document._document.application._template._deserializer.getObjectsFromLastDeserialization(); | 81 | |
44 | }.bind(this), 1000); | 82 | this.addBinding(bindingArgs); |
83 | } | ||
84 | }, | ||
85 | |||
86 | getObjectBindings : { | ||
87 | value: function(object) { | ||
88 | var descriptors = object._bindingDescriptors, | ||
89 | bindingsArray = [], | ||
90 | property, descriptor, bindingArgsObject; | ||
91 | |||
92 | for(property in descriptors) { | ||
93 | if(descriptors.hasOwnProperty(property)) { | ||
94 | descriptor = descriptors[property]; | ||
95 | |||
96 | bindingArgsObject = { | ||
97 | sourceObject : object, | ||
98 | sourceObjectPropertyPath : property, | ||
99 | boundObject : descriptor.boundObject, | ||
100 | boundObjectPropertyPath : descriptor.boundObjectPropertyPath, | ||
101 | onweway : descriptor.oneway | ||
102 | }; | ||
103 | |||
104 | bindingsArray.push(bindingArgsObject); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | return bindingsArray; | ||
109 | } | ||
110 | }, | ||
111 | |||
112 | /* ---- Bindable Properties ---- */ | ||
45 | 113 | ||
114 | getEnumerableProperties : { | ||
115 | value: function(object, excludeUnderscoreProperties) { | ||
116 | var properties = []; | ||
46 | 117 | ||
47 | ///// setting document via binding | 118 | for(var key in object) { |
48 | this._activeDocument = document; | 119 | properties.push(key); |
120 | } | ||
121 | |||
122 | if(excludeUnderscoreProperties) { | ||
123 | properties = properties.filter(function(property) { | ||
124 | return property[0] !== '_'; | ||
125 | }, this); | ||
126 | } | ||
127 | |||
128 | return properties.sort(); | ||
129 | } | ||
130 | }, | ||
131 | |||
132 | /* ---- Bindable controller properties ---- */ | ||
133 | |||
134 | currentObjectBindings : { | ||
135 | value: null | ||
136 | }, | ||
137 | _currentObject : { | ||
138 | value: null | ||
139 | }, | ||
140 | currentObject : { | ||
141 | get: function() { | ||
142 | return this._currentObject; | ||
49 | }, | 143 | }, |
50 | enumerable : false | 144 | set: function(value) { |
145 | if(value === this._currentObject) { return; } | ||
146 | |||
147 | this.currentObjectBindings = this.getObjectBindings(value); | ||
148 | |||
149 | this._currentObject = value; | ||
150 | } | ||
51 | } | 151 | } |
52 | 152 | ||
53 | }); \ No newline at end of file | 153 | }); \ No newline at end of file |
diff --git a/js/document/models/html.js b/js/document/models/html.js index fd42d4de..a93faa9e 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js | |||
@@ -74,6 +74,7 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { | |||
74 | setComponentInstance: { | 74 | setComponentInstance: { |
75 | value: function(instance, el) { | 75 | value: function(instance, el) { |
76 | this.userComponents[el.uuid] = instance; | 76 | this.userComponents[el.uuid] = instance; |
77 | this.objects.push(instance); | ||
77 | } | 78 | } |
78 | }, | 79 | }, |
79 | //////////////////////////////////////////////////////////////////// | 80 | //////////////////////////////////////////////////////////////////// |
@@ -86,6 +87,10 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { | |||
86 | return null; | 87 | return null; |
87 | } | 88 | } |
88 | } | 89 | } |
90 | }, | ||
91 | //////////////////////////////////////////////////////////////////// | ||
92 | objects : { | ||
93 | value: null | ||
89 | } | 94 | } |
90 | //////////////////////////////////////////////////////////////////// | 95 | //////////////////////////////////////////////////////////////////// |
91 | //////////////////////////////////////////////////////////////////// | 96 | //////////////////////////////////////////////////////////////////// |
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, { | |||
29 | var componentRequire = component[data.name]; | 29 | var componentRequire = component[data.name]; |
30 | var componentInstance = componentRequire.create(); | 30 | var componentInstance = componentRequire.create(); |
31 | 31 | ||
32 | componentInstance._montage_metadata.label = data.name; | ||
32 | componentInstance.element = element; | 33 | componentInstance.element = element; |
33 |