aboutsummaryrefslogtreecommitdiff
path: root/js/panels/binding/edit-binding-view.reel/edit-binding-view.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/binding/edit-binding-view.reel/edit-binding-view.js')
-rw-r--r--js/panels/binding/edit-binding-view.reel/edit-binding-view.js196
1 files changed, 193 insertions, 3 deletions
diff --git a/js/panels/binding/edit-binding-view.reel/edit-binding-view.js b/js/panels/binding/edit-binding-view.reel/edit-binding-view.js
index 700f3024..c9f946f5 100644
--- a/js/panels/binding/edit-binding-view.reel/edit-binding-view.js
+++ b/js/panels/binding/edit-binding-view.reel/edit-binding-view.js
@@ -9,13 +9,203 @@ var Montage = require("montage/core/core").Montage,
9 9
10 10
11exports.EditBindingView = Montage.create(Component, { 11exports.EditBindingView = Montage.create(Component, {
12 objectsList : { 12
13 value: ["Object1", "Object2", "Object3"] 13 objectIdentifiers : {
14 value: null
15 },
16 getObjectIdentifiers : {
17 value: function() {
18 return this.application.ninja.objectsController.objects.map(function(object) {
19 return object.identifier;
20 });
21 }
22 },
23
24 /* -------------------
25 Binding Properties
26 ------------------- */
27
28 sourceObjectIdentifier : {
29 value: "",
30 distinct: true
31 },
32 sourceObjectPropertyPath : {
33 value: "",
34 distinct: true
35 },
36 boundObjectIdentifier : {
37 value: "",
38 distinct: true
39 },
40 boundObjectPropertyPath : {
41 value: "",
42 distinct: true
43 },
44 _oneway: {
45 value: null
46 },
47 oneway: {
48 get: function() {
49 return this._oneway;
50 },
51 set: function(value) {
52 if(value === this._oneway) { return; }
53
54 this._oneway = !!value;
55
56 this.needsDraw = true;
57 }
58 },
59
60 /* -------------------
61 Binding Args Object
62 ------------------- */
63
64 _bindingArgs : {
65 value: null
66 },
67 bindingArgs :{
68 get: function() {
69 return this._bindingArgs;
70 },
71 set: function(value) {
72 if(value === this._bindingArgs) { return; }
73
74 this._bindingArgs = value;
75
76 // clear form values
77 this.clearForm();
78
79 // set up hints for hintable components
80 this.objectIdentifiers = this.getObjectIdentifiers();
81 console.log("setting hints to ", this.objectIdentifiers);
82 this.boundObjectField.hints = this.objectIdentifiers;
83 this.sourceObjectField.hints = this.objectIdentifiers;
84
85 if(value.sourceObject) {
86 this.sourceObjectIdentifier = value.sourceObject.identifier || value.sourceObject._montage_metadata.label;
87 this.sourceObjectPropertyPath = value.sourceObjectPropertyPath || '';
88 }
89
90 if(value.boundObject) {
91 this.boundObjectIdentifier = value.boundObject.identifier || '';
92 this.boundObjectPropertyPath = value.boundObjectPropertyPath || '';
93 this.isNewBinding = false;
94 } else {
95 this.isNewBinding = true;
96 }
97
98 this.oneway = value.oneway;
99
100 this.needsDraw = true;
101 }
102 },
103
104 /* -------------------
105 Form properties
106 ------------------- */
107
108 dirty: { value: null },
109 isNewBinding : { value: null },
110
111 "sourceObjectField" : {value: null, enumerable: true },
112 "boundObjectField" : {value: null, enumerable: true },
113 "sourceObjectPropertyPathField" : {value: null, enumerable: true },
114 "boundObjectPropertyPathField" : {value: null, enumerable: true },
115 "directionCheckbox" : {value: null, enumerable: true },
116 "deleteButton" : {value: null },
117 "saveButton" : {value: null },
118 "cancelButton" : {value: null },
119
120 clearForm : {
121 value: function() {
122 for(var field in this) {
123 if(this.hasOwnProperty(field)) {
124 field.value = '';
125 }
126 }
127 this.dirty = false;
128 }
129 },
130
131 saveForm : {
132 value: function() {
133 var controller = this.application.ninja.objectsController,
134 newBindingArgs = {
135 sourceObject : this.getObjectFromIdentifierValue(this.sourceObjectField.value),
136 sourceObjectPropertyPath : this.sourceObjectPropertyPathField.value,
137 boundObject : this.getObjectFromIdentifierValue(this.boundObjectField.value),
138 boundObjectPropertyPath : this.boundObjectPropertyPathField.value,
139 oneway: this.oneway
140 };
141
142 if(this.isNewBinding) {
143 controller.addBinding(newBindingArgs);
144 } else {
145 controller.editBinding(this.bindingArgs, newBindingArgs);
146 }
147
148 controller.currentObject = controller.currentObject;
149 }
150 },
151
152 getObjectFromIdentifierValue : {
153 value: function(id) {
154 var identifiers = this.getObjectIdentifiers(),
155 objects = this.application.ninja.objectsController.objects;
156
157 return objects[identifiers.indexOf(id)];
158 }
14 }, 159 },
15 160
161 /* -------------------
162 Save/Cancel/Delete button handlers
163 ------------------- */
164
165 handleCancelButtonAction : {
166 value: function(e) {
167 this.clearForm();
168 this.parentComponent.editing = false;
169 }
170 },
171
172 handleDeleteButtonAction : {
173 value: function(e) {
174 var controller = this.application.ninja.objectsController;
175
176 controller.removeBinding(this.bindingArgs);
177 controller.currentObject = controller.currentObject;
178
179 this.parentComponent.editing = false;
180 }
181 },
182 handleSaveButtonAction : {
183 value: function(e) {
184 this.saveForm();
185 this.parentComponent.editing = false;
186 }
187 },
188
189
190 /* -------------------
191 Dirty handler
192 ------------------- */
193
194 handleEvent : {
195 value: function(e) {
196 if(e._event.type === 'change') {
197 this.dirty = true;
198 }
199 }
200 },
201
202 /* -------------------
203 Draw Cycle
204 ------------------- */
205
16 prepareForDraw : { 206 prepareForDraw : {
17 value: function() { 207 value: function() {
18 console.log("Preparing to draw edit view"); 208
19 } 209 }
20 } 210 }
21}); \ No newline at end of