Don't let editor panels fuck up _factory.relationTags
[potlatch2.git] / net / systemeD / potlatch2 / RelationSelectPanel.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:TitleWindow
3     xmlns:mx="http://www.adobe.com/2006/mxml"
4     xmlns:potlatch2="net.systemeD.potlatch2.*"
5     title="Select Relation" width="350" height="400"
6     showCloseButton="true" close="PopUpManager.removePopUp(this);">
7
8     <mx:Script><![CDATA[
9         import net.systemeD.halcyon.*;
10         import net.systemeD.halcyon.connection.*;
11         import net.systemeD.potlatch2.*;
12         import mx.managers.PopUpManager;
13         import mx.core.Application;
14
15         private var conn:Connection;
16         private var relationList:Array;
17         private var entity:Entity;
18                 private var tags:Object;
19
20         public function init(e:Entity, t:Object):void {
21           entity = e;
22           tags = {}; for (var k:String in t) { tags[k]=t[k]; }  // deep copy tags
23           PopUpManager.addPopUp(this, Application(Application.application), true);
24           PopUpManager.centerPopUp(this);
25     
26           var titles:Array = [];
27           conn = Connection.getConnectionInstance();
28           relationList = conn.getMatchingRelationIDs(tags);
29           if (relationList.length == 0) {
30             warning.text = "No relations available";
31           } else {
32             warning.text = "These relations are available:";
33           }
34           //relationSelector.dataProvider = relationList;
35           for each (var id:Number in relationList) {
36             var relation:Relation = conn.getRelation(id);
37             titles.push({label:id + ": " + relation.getDescription(), relId:id});
38           }
39           relationSelector.dataProvider = titles;
40         }
41         
42         public function updateEntityAndClose():void {
43           var relation:Relation = conn.getRelation(relationSelector.selectedItem.relId);
44           relation.appendMember(new RelationMember(entity, ''));
45           PopUpManager.removePopUp(this);
46         }
47         
48         public function closeAndNewRelation():void {
49           var relation:Relation = conn.createRelation(tags, [new RelationMember(entity, '')],
50               MainUndoStack.getGlobalStack().addAction)
51           PopUpManager.removePopUp(this);
52           var panel:RelationEditorPanel = RelationEditorPanel(
53               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
54           panel.setRelation(relation);
55           PopUpManager.centerPopUp(panel);
56         }
57         
58     ]]></mx:Script> 
59     <mx:Text id="warning" text="" />
60     <mx:List width="100%" height="100%" id="relationSelector" verticalScrollPolicy="on"> 
61     </mx:List>
62     <mx:ControlBar>
63       <mx:Button label="New Relation..." click="closeAndNewRelation();"/>
64       <mx:Spacer width="100%"/>
65       <mx:Button label="Select" click="updateEntityAndClose();" enabled="{relationSelector.selectedItem != null? true : false}"/>
66     </mx:ControlBar>
67 </mx:TitleWindow>