aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorEric Guzman2012-05-30 15:02:23 -0700
committerEric Guzman2012-05-30 15:02:23 -0700
commite09efe3212e86ac794de3fc8ecfc6cdef7b15181 (patch)
treeb32fb1c5bfffadbb04efe35ba87dc012b1491482 /js
parente884d2769a53dd8920b485672631b50158ed0800 (diff)
downloadninja-e09efe3212e86ac794de3fc8ecfc6cdef7b15181.tar.gz
Objects Controller - Add bindable controller properties, and bindings getter
Diffstat (limited to 'js')
-rw-r--r--js/controllers/objects-controller.js75
-rwxr-xr-xjs/ninja.reel/ninja.html2
2 files changed, 62 insertions, 15 deletions
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,
9 9
10var objectsController = exports.ObjectsController = Montage.create(Component, { 10var objectsController = exports.ObjectsController = Montage.create(Component, {
11 11
12 _activeDocument : { 12 _currentDocument : {
13 value : null, 13 value : null,
14 enumerable : false 14 enumerable : false
15 }, 15 },
16 activeDocument : { 16 currentDocument : {
17 get : function() { 17 get : function() {
18 return this._activeDocument; 18 return this._currentDocument;
19 }, 19 },
20 set : function(doc) { 20 set : function(doc) {
21 if(!doc) { return false; } 21 if(!doc) { return false; }
@@ -25,7 +25,7 @@ var objectsController = exports.ObjectsController = Montage.create(Component, {
25 this.bindToModelObjects(); 25 this.bindToModelObjects();
26 }.bind(this), 1000); 26 }.bind(this), 1000);
27 27
28 this._activeDocument = doc; 28 this._currentDocument = doc;
29 }, 29 },
30 enumerable : false 30 enumerable : false
31 }, 31 },
@@ -46,7 +46,7 @@ var objectsController = exports.ObjectsController = Montage.create(Component, {
46 } 46 }
47 47
48 Object.defineBinding(this, 'objects', { 48 Object.defineBinding(this, 'objects', {
49 boundObject: this.activeDocument.model, 49 boundObject: this.currentDocument.model,
50 boundObjectPropertyPath: 'objects', 50 boundObjectPropertyPath: 'objects',
51 oneway: false 51 oneway: false
52 }); 52 });
@@ -58,28 +58,75 @@ var objectsController = exports.ObjectsController = Montage.create(Component, {
58 ----------------------------- */ 58 ----------------------------- */
59 59
60 addBinding : { 60 addBinding : {
61 value: function(bindingDescriptor) { 61 value: function(bindingArgs) {
62 if(!bindingDescriptor.sourceObject || !bindingDescriptor.sourceObjectPropertyPath || !bindingDescriptor) { return; } 62 if(!bindingArgs.sourceObject || !bindingArgs.sourceObjectPropertyPath || !bindingArgs) { return; }
63 63
64 Object.defineBinding(bindingDescriptor.sourceObject, bindingDescriptor.sourceObjectPropertyPath, bindingDescriptor); 64 Object.defineBinding(bindingArgs.sourceObject, bindingArgs.sourceObjectPropertyPath, bindingArgs);
65 } 65 }
66 }, 66 },
67 67
68 removeBinding : { 68 removeBinding : {
69 value: function(bindingDescriptor) { 69 value: function(bindingArgs) {
70 if(!bindingDescriptor) { return; } 70 if(!bindingArgs) { return; }
71 71
72 Object.deleteBinding(bindingDescriptor.sourceObject, bindingDescriptor.sourceObjectPropertyBindingPath); 72 Object.deleteBinding(bindingArgs.sourceObject, bindingArgs.sourceObjectPropertyPath);
73 } 73 }
74 }, 74 },
75 75
76 editBindingPropertyPath : { 76 editBindingPropertyPath : {
77 value: function(bindingDescriptor, newPropertyPath) { 77 value: function(bindingArgs, newPropertyPath) {
78 this.removeBinding(bindingDescriptor); 78 this.removeBinding(bindingArgs);
79 79
80 //this.addBinding() 80 bindingArgs.boundObjectPropertyPath = 'newPropertyPath';
81 81
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 controller properties ---- */
113
114 currentObjectBindings : {
115 value: null
116 },
117 _currentObject : {
118 value: null
119 },
120 currentObject : {
121 get: function() {
122 return this._currentObject;
123 },
124 set: function(value) {
125 if(value === this._currentObject) { return; }
126
127 this.currentObjectBindings = this.getObjectBindings(value);
82 128
129 this._currentObject = value;
83 } 130 }
84 } 131 }
85 132
diff --git a/js/ninja.reel/ninja.html b/js/ninja.reel/ninja.html
index 1f0582b1..53b8676f 100755
--- a/js/ninja.reel/ninja.html
+++ b/js/ninja.reel/ninja.html
@@ -326,7 +326,7 @@
326 "objectsController" : { 326 "objectsController" : {
327 "prototype": "js/controllers/objects-controller", 327 "prototype": "js/controllers/objects-controller",
328 "bindings": { 328 "bindings": {
329 "activeDocument": {"<-": "@owner.currentDocument"} 329 "currentDocument": {"<-": "@owner.currentDocument"}
330 } 330 }
331 }, 331 },
332 332