aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js94
1 files changed, 33 insertions, 61 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 6ab33eff..a5f72462 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -234,8 +234,25 @@ exports.ElementMediator = Montage.create(Component, {
234 @param eventType: Change/Changing. Will be passed to the dispatched event 234 @param eventType: Change/Changing. Will be passed to the dispatched event
235 @param source: String for the source object making the call 235 @param source: String for the source object making the call
236 */ 236 */
237 /*value: function(elements, properties, currentProperties, eventType, source) {*/
237 setProperties: { 238 setProperties: {
238 value: function(elements, properties, currentProperties, eventType, source) { 239 value: function(elements, eventType, source) {
240
241 elements.forEach(function(elementObject) {
242 elementObject.element.elementModel.controller["setProperties"](elementObject.element, elementObject.properties);
243 });
244
245 if(eventType !== "Changing") {
246 var undoLabel = "Properties change";
247 elements.forEach(function(elementObject) {
248 var swap = elementObject.properties;
249 elementObject.properties = elementObject.previousProperties;
250 elementObject.previousProperties = swap;
251 });
252 document.application.undoManager.add(undoLabel, this.setProperties, this, elements, eventType, source);
253 }
254
255 /*
239 // Assume elements is an array of elements always 256 // Assume elements is an array of elements always
240 elements.forEach(function(element) { 257 elements.forEach(function(element) {
241 element.elementModel.controller["setProperties"](element, properties); 258 element.elementModel.controller["setProperties"](element, properties);
@@ -246,79 +263,34 @@ exports.ElementMediator = Montage.create(Component, {
246 var undoLabel = "Properties change"; 263 var undoLabel = "Properties change";
247 document.application.undoManager.add(undoLabel, this.setProperties, this, elements, currentProperties, properties, eventType, source); 264 document.application.undoManager.add(undoLabel, this.setProperties, this, elements, currentProperties, properties, eventType, source);
248 } 265 }
266 */
267 // Map the elements for the event data
268 var els = elements.map(function(element) {
269 return element.element;
270 });
249 271
250 // Dispatch the element change/changing event. 272 // Dispatch the element change/changing event.
251 NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": elements, "prop": properties, "value": properties}, redraw: null}); 273 NJevent("element" + eventType, {type : "setProperties", source: source, data: {"els": els, "prop": elements[0].properties, "value": elements}, redraw: null});
252 } 274 }
253 }, 275 },
254 276
255 /**
256 Set a property change command for an element or array of elements
257 @param els: Array of elements. Can contain 1 or more elements
258 @param props: Property/ies object containing both the value and property
259 @param eventType: Change/Changing. Will be passed to the dispatched event
260 @param source: String for the source object making the call
261 @param currentProps *OPTIONAL*: current properties objects array. If not found it will be calculated
262 @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline
263 */
264 set3DProperties: { 277 set3DProperties: {
265 value: function(els, props, eventType, source, currentProps, stageRedraw) { 278 value: function(elements, eventType, source) {
266 if(eventType === "Changing") {
267 this._set3DProperties(els, props, eventType, source);
268 } else {
269 // Calculate currentProps if not found for each element
270 if(!currentProps) {
271 var that = this;
272 currentProps = els.map(function(item) {
273 return that.get3DProperties(item);
274 });
275 }
276
277 var command = Montage.create(Command, {
278 _els: { value: els },
279 _props: { value: props },
280 _previous: { value: currentProps },
281 _eventType: { value: eventType},
282 _source: { value: "undo-redo"},
283 description: { value: "Set 3D Properties"},
284 receiver: { value: this},
285
286 execute: {
287 value: function(senderObject) {
288 if(senderObject) this._source = senderObject;
289 this.receiver._set3DProperties(this._els, this._props, this._eventType, this._source);
290 this._source = "undo-redo";
291 return "";
292 }
293 },
294
295 unexecute: {
296 value: function() {
297 this.receiver._set3DProperties(this._els, this._previous, this._eventType, this._source);
298 return "";
299 }
300 }
301 });
302
303 NJevent("sendToUndo", command);
304 command.execute(source);
305 }
306 }
307 },
308
309 _set3DProperties: {
310 value: function(els, props, eventType, source) {
311 var update3DModel = false; 279 var update3DModel = false;
312 280
313 if(eventType === "Change") { 281 if(eventType === "Change") {
314 update3DModel = true; 282 update3DModel = true;
315 } 283 }
316 284
317 for(var i=0, item; item = els[i]; i++) { 285 for(var i=0, item; item = elements[i]; i++) {
318 item.elementModel.controller["set3DProperties"](item, props, i, update3DModel); 286 item.element.elementModel.controller["set3DProperties"](item.element, item.properties, update3DModel);
319 } 287 }
320 288
321 NJevent("element" + eventType, {type : "set3DProperties", source: source, data: {"els": els, "prop": "matrix", "value": props}, redraw: null}); 289 var els = elements.map(function(element) {
290 return element.element;
291 });
292
293 NJevent("element" + eventType, {type : "set3DProperties", source: source, data: {"els": els, "prop": "matrix", "value": elements}, redraw: null});
322 } 294 }
323 }, 295 },
324 296
@@ -529,7 +501,7 @@ exports.ElementMediator = Montage.create(Component, {
529 setMatrix: { 501 setMatrix: {
530 value: function(el, mat, isChanging, source) { 502 value: function(el, mat, isChanging, source) {
531 var dist = el.elementModel.controller["getPerspectiveDist"](el); 503 var dist = el.elementModel.controller["getPerspectiveDist"](el);
532 el.elementModel.controller["set3DProperties"](el, [{mat:mat, dist:dist}], 0, !isChanging); 504 el.elementModel.controller["set3DProperties"](el, {mat:mat, dist:dist}, !isChanging);
533 505
534 if(isChanging) { 506 if(isChanging) {
535 NJevent("elementChanging", {type : "setMatrix", source: source, data: {"els": [el], "prop": "matrix", "value": mat}, redraw: null}); 507 NJevent("elementChanging", {type : "setMatrix", source: source, data: {"els": [el], "prop": "matrix", "value": mat}, redraw: null});