start of turn restriction editor
[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.managers.PopUpManager;
19         import mx.core.*;
20
21         /* ** FIXME: some of this is common with RouteEditor.mxml. We can probably refactor */
22
23         public function addTurnRestrictions(event:Event=null):void {
24                 turnRestrictionIcons.removeAllChildren();
25                 addEventListener("relations_changed", addTurnRestrictions);
26                 for each(var relation:Object in matchedRelations) {
27                         var icon:TurnRestrictionIcon = new TurnRestrictionIcon();
28                         icon.setTurnRestriction(relation);
29                         
30                         icon.addEventListener(MouseEvent.CLICK, turnRestrictionClicked);
31                         turnRestrictionIcons.addChild(icon);
32                 }
33         }
34         
35         public function turnRestrictionClicked(event:Event):void {
36                 var relation:Object = TurnRestrictionIcon(event.currentTarget).turnRestriction;
37                 var panel:RelationEditorPanel = RelationEditorPanel(
38                         PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
39                 panel.setRelation(relation["relation"]);
40                 PopUpManager.centerPopUp(panel);
41         }
42
43         public function addNewTurnRestriction():void {
44                 var conn:Connection = Connection.getConnectionInstance();
45                 var relation:Relation = conn.createRelation(
46                         { type: 'restriction' }, 
47                         [ new RelationMember(_entity, 'via') ],
48             MainUndoStack.getGlobalStack().addAction);
49                 addTurnRestrictions();
50         }
51         
52   ]]></mx:Script>
53 </edit:RelationMemberEditor>
54