aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/element-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/element-mediator.js')
-rwxr-xr-xjs/mediators/element-mediator.js129
1 files changed, 47 insertions, 82 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 67f2a562..e711e632 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -29,16 +29,13 @@ exports.ElementMediator = Montage.create(Component, {
29 if(Array.isArray(elements)) { 29 if(Array.isArray(elements)) {
30 elements.forEach(function(element) { 30 elements.forEach(function(element) {
31 ElementController.addElement(element, rules); 31 ElementController.addElement(element, rules);
32 if(element.elementModel && element.elementModel.props3D) {
33 element.elementModel.props3D.init(element, false); 32 element.elementModel.props3D.init(element, false);
34 }
35 }); 33 });
36 } else { 34 } else {
37 ElementController.addElement(elements, rules); 35 ElementController.addElement(elements, rules);
38 if(elements.elementModel && elements.elementModel.props3D) {
39 elements.elementModel.props3D.init(elements, false); 36 elements.elementModel.props3D.init(elements, false);
37
40 } 38 }
41 }
42 39
43 if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") { 40 if(this.addDelegate && typeof (this.addDelegate['onAddElements']) === "function") {
44 this.addDelegate['onAddElements'].call(this.addDelegate, elements); 41 this.addDelegate['onAddElements'].call(this.addDelegate, elements);
@@ -48,7 +45,7 @@ exports.ElementMediator = Montage.create(Component, {
48 45
49 document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); 46 document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify);
50 47
51 this.application.ninja.documentController.activeDocument.model.needsSave = true; 48 this.application.ninja.currentDocument.model.needsSave = true;
52 49
53 if(notify || notify === undefined) { 50 if(notify || notify === undefined) {
54 NJevent("elementAdded", elements); 51 NJevent("elementAdded", elements);
@@ -77,7 +74,7 @@ exports.ElementMediator = Montage.create(Component, {
77 74
78 document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); 75 document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify);
79 76
80 this.application.ninja.documentController.activeDocument.model.needsSave = true; 77 this.application.ninja.currentDocument.model.needsSave = true;
81 78
82 NJevent("elementsRemoved", elements); 79 NJevent("elementsRemoved", elements);
83 } 80 }
@@ -92,7 +89,7 @@ exports.ElementMediator = Montage.create(Component, {
92 89
93 document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); 90 document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild);
94 91
95 this.application.ninja.documentController.activeDocument.model.needsSave = true; 92 this.application.ninja.currentDocument.model.needsSave = true;
96 93
97 if(notify || notify === undefined) { 94 if(notify || notify === undefined) {
98 NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); 95 NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}});
@@ -102,11 +99,6 @@ exports.ElementMediator = Montage.create(Component, {
102 99
103 getProperty: { 100 getProperty: {
104 value: function(el, prop, valueMutator) { 101 value: function(el, prop, valueMutator) {
105 if(!el.elementModel) {
106 console.log("Element has no Model -> One should have been created");
107 NJUtils.makeElementModel(el, "Div", "block");
108 }
109
110 if(valueMutator && typeof valueMutator === "function") { 102 if(valueMutator && typeof valueMutator === "function") {
111 return valueMutator(el.elementModel.controller["getProperty"](el, prop)); 103 return valueMutator(el.elementModel.controller["getProperty"](el, prop));
112 } else { 104 } else {
@@ -117,22 +109,12 @@ exports.ElementMediator = Montage.create(Component, {
117 109
118 getShapeProperty: { 110 getShapeProperty: {
119 value: function(el, prop) { 111 value: function(el, prop) {
120 if(!el.elementModel) {
121 console.log("Element has no Model -> One should have been created");
122 NJUtils.makeElementModel(el, "Canvas", "block", true);
123 }
124
125 return el.elementModel.controller["getShapeProperty"](el, prop); 112 return el.elementModel.controller["getShapeProperty"](el, prop);
126 } 113 }
127 }, 114 },
128 115
129 setShapeProperty: { 116 setShapeProperty: {
130 value: function(el, prop, value) { 117 value: function(el, prop, value) {
131 if(!el.elementModel) {
132 console.log("Element has no Model -> One should have been created");
133 NJUtils.makeElementModel(el, "Canvas", "block", true);
134 }
135
136 return el.elementModel.controller["setShapeProperty"](el, prop, value); 118 return el.elementModel.controller["setShapeProperty"](el, prop, value);
137 } 119 }
138 }, 120 },
@@ -297,9 +279,6 @@ exports.ElementMediator = Montage.create(Component, {
297 // Routines to get/set color 279 // Routines to get/set color
298 getColor: { 280 getColor: {
299 value: function(el, isFill, borderSide) { 281 value: function(el, isFill, borderSide) {
300 if(!el.elementModel) {
301 NJUtils.makeModelFromElement(el);
302 }
303 return el.elementModel.controller["getColor"](el, isFill, borderSide); 282 return el.elementModel.controller["getColor"](el, isFill, borderSide);
304 } 283 }
305 }, 284 },
@@ -374,78 +353,76 @@ exports.ElementMediator = Montage.create(Component, {
374 }, 353 },
375 354
376 getStroke: { 355 getStroke: {
377 value: function(el) { 356 value: function(el, strokeProperties) {
378 if(!el.elementModel) { 357 return el.elementModel.controller["getStroke"](el, strokeProperties);
379 NJUtils.makeElementModel(el, "Div", "block");
380 }
381 return el.elementModel.controller["getStroke"](el);
382 } 358 }
383 }, 359 },
384 360
385
386 /** 361 /**
387 Set a property change command for an element or array of elements 362 Set stroke/border properties on an element or array of elements
388 @param els: Array of elements. Can contain 1 or more elements 363 @param els: Array of elements. Can contain 1 or more elements
389 @param value: Value to be set. This is the stroke info 364 @param value: Value to be set. This is the stroke info
390 @param eventType: Change/Changing. Will be passed to the dispatched event 365 @param eventType: Change/Changing. Will be passed to the dispatched event
391 @param source: String for the source object making the call 366 @param source: String for the source object making the call
392 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated 367 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated
393 @param stageRedraw: *OPTIONAL*: True. If set to false the stage will not redraw the selection/outline
394 */ 368 */
395 setStroke: { 369 setStroke: {
396 value: function(els, value, eventType, source, currentValue) { 370 value: function(els, value, eventType, source, currentValue) {
397 371
398 if(eventType === "Changing") { 372 if(eventType !== "Changing") {
399 this._setStroke(els, value, isFill, eventType, source);
400 } else {
401 // Calculate currentValue if not found for each element 373 // Calculate currentValue if not found for each element
402 if(!currentValue) { 374 if(!currentValue) {
403 var that = this; 375 var that = this,
376 val = value;
404 currentValue = els.map(function(item) { 377 currentValue = els.map(function(item) {
405 return that.getStroke(item); 378 return that.getStroke(item, val);
406 }); 379 });
407 } 380 }
381 document.application.undoManager.add("Set stroke", this.setStroke, this, els, currentValue, eventType, source, value);
382 }
408 383
409 var command = Montage.create(Command, { 384 for(var i=0, item; item = els[i]; i++) {
410 _els: { value: els }, 385 item.elementModel.controller["setStroke"](item, (value[i] || value), eventType, source);
411 _value: { value: value },
412 _previous: { value: currentValue },
413 _eventType: { value: eventType},
414 _source: { value: "undo-redo"},
415 description: { value: "Set Color"},
416 receiver: { value: this},
417
418 execute: {
419 value: function(senderObject) {
420 if(senderObject) this._source = senderObject;
421 this.receiver._setStroke(this._els, this._value, this._eventType, this._source);
422 this._source = "undo-redo";
423 return "";
424 }
425 },
426
427 unexecute: {
428 value: function() {
429 this.receiver._setStroke(this._els, this._previous, this._eventType, this._source);
430 return "";
431 }
432 }
433 });
434
435 NJevent("sendToUndo", command);
436 command.execute(source);
437 } 386 }
438 387
388 NJevent("element" + eventType, {type : "setStroke", source: source, data: {"els": els, "prop": "stroke", "value": value}, redraw: null});
439 } 389 }
440 }, 390 },
441 391
442 _setStroke: { 392 getFill: {
443 value: function(els, value, eventType, source) { 393 value: function(el, fillProperties) {
394 return el.elementModel.controller["getFill"](el, fillProperties);
395 }
396 },
397
398 /**
399 Set fill/background properties for an element or array of elements
400 @param els: Array of elements. Can contain 1 or more elements
401 @param value: Value to be set. This is the fill info
402 @param eventType: Change/Changing. Will be passed to the dispatched event
403 @param source: String for the source object making the call
404 @param currentValue *OPTIONAL*: current value array. If not found the current value is calculated
405 */
406 setFill: {
407 value: function(els, value, eventType, source, currentValue) {
408
409 if(eventType !== "Changing") {
410 // Calculate currentValue if not found for each element
411 if(!currentValue) {
412 var that = this,