]> git.openstreetmap.org Git - potlatch2.git/blob - net/systemeD/halcyon/connection/actions/AddMemberToRelationAction.as
Bugfix - if index is given as -1, insert after last member rather than before. See...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / AddMemberToRelationAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class AddMemberToRelationAction extends UndoableEntityAction {
6         private var rel:Relation;
7         private var index:int;
8         private var member:RelationMember;
9         private var memberList:Array;
10         
11         public function AddMemberToRelationAction(rel:Relation, index:int, member:RelationMember, memberList:Array) {
12             super(rel, "Add " + member.entity.getType() + " " + member.entity.id + " at position " + index + " to ");
13             this.rel = rel;
14             this.index = index;
15             this.member = member;
16             this.memberList = memberList;
17         }
18         
19         public override function doAction():uint {
20             if ( index == -1 )
21                 index = memberList.length;
22             memberList.splice(index, 0, member);
23             member.entity.addParent(rel);
24             markDirty();
25             rel.dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_ADDED, member.entity, rel, index));
26             
27             return SUCCESS;
28         }
29         
30         public override function undoAction():uint {
31             memberList.splice(index, 1);
32             member.entity.removeParent(rel);
33             markClean();
34             rel.dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_REMOVED, member.entity, rel, index));
35             
36             return SUCCESS;
37         }
38     }
39 }