Relation selection dialog
[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
19         public function init(e:Entity):void {
20           entity = e;
21           PopUpManager.addPopUp(this, Application(Application.application), true);
22           PopUpManager.centerPopUp(this);
23     
24           var titles:Array = [];
25           conn = Connection.getConnectionInstance();
26           relationList = conn.getAllRelationIDs();
27           if (relationList.length == 0) {
28             warning.text = "No relations loaded";
29           } else {
30             warning.text = "These relations are available:";
31           }
32           //relationSelector.dataProvider = relationList;
33           for each (var id:Number in relationList) {
34             var relation:Relation = conn.getRelation(id);
35             titles.push({label:id + ": " + relation.getDescription(), relId:id});
36           }
37           relationSelector.dataProvider = titles;
38         }
39         
40         public function updateEntityAndClose():void {
41           var relation:Relation = conn.getRelation(relationSelector.selectedItem.relId);
42           relation.appendMember(new RelationMember(entity, ''));
43           PopUpManager.removePopUp(this);
44         }
45     ]]></mx:Script> 
46     <mx:Text id="warning" text="" />
47     <mx:List width="100%" height="100%" id="relationSelector" verticalScrollPolicy="on"> 
48     </mx:List>
49     <mx:ControlBar>
50       <mx:Button label="New Relation..." enabled="false"/>
51       <mx:Spacer width="100%"/>
52       <mx:Button label="Select" click="updateEntityAndClose();" enabled="{relationSelector.selectedItem != null? true : false}"/>
53     </mx:ControlBar>
54 </mx:TitleWindow>