more turn restriction stuff, and checkboxes, and a bunch of little fixes
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / TurnRestrictionEditor.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <edit:RelationMemberEditor
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:edit="net.systemeD.potlatch2.mapfeatures.editors.*"
5         xmlns:flexlib="flexlib.controls.*"
6         verticalGap="0"
7         width="100%"
8         toolTip="{fieldDescription}"
9         initialize="addTurnRestrictions()">
10
11   <mx:Label text="{fieldName}:"/>
12   <mx:VBox verticalGap="0" width="100%" id="turnRestrictionIcons"/>
13   <mx:LinkButton label="Add new turn restriction" click="addNewTurnRestriction()" />
14
15   <mx:Script><![CDATA[
16         import net.systemeD.halcyon.connection.*;
17         import net.systemeD.potlatch2.*;
18         import mx.core.*;
19
20         /* ** FIXME: some of this is common with RouteEditor.mxml. We can probably refactor */
21
22         public function addTurnRestrictions(event:Event=null):void {
23                 turnRestrictionIcons.removeAllChildren();
24                 addEventListener("relations_changed", addTurnRestrictions);
25                 for each(var relation:Object in matchedRelations) {
26                         var icon:TurnRestrictionIcon = new TurnRestrictionIcon();
27                         icon.setTurnRestriction(relation);
28                         turnRestrictionIcons.addChild(icon);
29                 }
30         }
31
32         public function addNewTurnRestriction():void {
33                 var conn:Connection = Connection.getConnectionInstance();
34                 var relation:Relation = conn.createRelation(
35                         { type: 'restriction' }, 
36                         [ new RelationMember(_entity, 'via') ],
37             MainUndoStack.getGlobalStack().addAction);
38                 addTurnRestrictions();
39         }
40         
41   ]]></mx:Script>
42 </edit:RelationMemberEditor>
43