1 /**
  2  * Object that is used to undo actions when figures are grouped or ungrouped
  3  * @this {GroupCommand} 
  4  * @constructor
  5  * @param objectId {Numeric} - the id of the object we will operate on
  6  * @param typeOfObject {Numeric} - the type of the object we will operate on (ex. History.OBJECT_FIGURE)
  7  * @param property {String} - the property of the object we are observing
  8  * @param previousValue {Object} - the pervious value of the object
  9  * @param currentValue {Object} - the current value of the object
 10  */
 11 function GroupCommand(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 = "Group Action";
 18 }
 19 
 20 GroupCommand.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 group = stack.groupGetById(this.objectId);
 34         if(value == false){//we are ungrouping
 35             stack.groupDestroy(this.objectId);
 36             selectedGroupId = -1; //inherited from main.js
 37             state = STATE_NONE; //inherited from main.js
 38         }
 39         else {//we are regrouping
 40             //destroy/discard any temp group
 41             for (var i = 0; i < stack.groups.length; i++){
 42                 if(stack.groups[i].permanent == false){
 43                     stack.groupDestroy(stack.groups[i].id);
 44                     break;//there should only be 1
 45                 }
 46             }
 47 
 48             //create a new group based on the figureIds we already have
 49             var gId = stack.groupCreate(value);
 50             group = stack.groupGetById(gId);
 51             group.id = this.objectId;
 52             group.permanent = this.property;
 53 
 54             //set the figures with the old groupId, as we will now have a new one.
 55             var figures = stack.figureGetByGroupId(gId);
 56             for (var i = 0; i < figures.length; i++){
 57                 figures[i].groupId = this.objectId;
 58             }
 59             selectedGroupId = this.objectId;
 60             state = STATE_GROUP_SELECTED;
 61         }
 62     }
 63 }
 64 
 65