1 /** 2 * Object that is used to undo actions when the property editor is used 3 * @this {PropertyCommand} 4 * @constructor 5 * @param objectId {Numeric} - the id of the object 6 * @param typeOfObject {Numberic} - the type of the object as number (ex: History.OBJECT_FIGURE) 7 * @param property {String} - property name that is being edited on the figure 8 * @param previousValue {Object} - the value to set the property to 9 * @param currentValue {Object} - the value to set the property to 10 */ 11 function PropertyCommand(objectId, typeOfObject, property, previousValue, currentValue){ 12 this.objectId = objectId; 13 this.typeOfObject = typeOfObject; 14 this.property = property; 15 this.previousValue = previousValue; 16 this.currentValue = currentValue; 17 this.oType = "Property Action"; 18 } 19 20 PropertyCommand.prototype = { 21 /**This method got called every time the Command must execute*/ 22 redo : function(){ 23 this._doAction(this.currentValue); 24 }, 25 26 27 /**This method should be called every time the Command should be undone*/ 28 undo : function(){ 29 this._doAction(this.previousValue); 30 }, 31 32 _doAction:function(value){ 33 var shape = null; 34 switch(this.typeOfObject){ 35 case History.OBJECT_FIGURE: 36 shape = stack.figureGetById(this.objectId); 37 break; 38 case History.OBJECT_CONNECTOR: 39 shape = CONNECTOR_MANAGER.connectorGetById(this.objectId); 40 break; 41 case History.OBJECT_GROUP: 42 shape = stack.groupGetById(this.objectId); 43 break; 44 } 45 46 47 var propertyObject = shape; 48 var propertyAccessors = this.property.split("."); 49 for(var i = 0; i<propertyAccessors.length-1; i++){ 50 propertyObject = propertyObject[propertyAccessors[i]]; 51 } 52 53 if(propertyObject[propertyAccessors[propertyAccessors.length -1]] === undefined){ 54 //if something is complicated enough to need a function, likelyhood is it will need access to its parent figure 55 propertyObject["set"+propertyAccessors[propertyAccessors.length -1]](shape,value); 56 } 57 else{ 58 propertyObject[propertyAccessors[propertyAccessors.length -1]] = value; 59 } 60 61 setUpEditPanel(shape); 62 } 63 } 64 65 66