New Relation button
[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         
46         public function closeAndNewRelation():void {
47           var relation:Relation = conn.createRelation({}, [new RelationMember(entity, '')])
48           PopUpManager.removePopUp(this);
49           trace("edit relation "+id);
50           var panel:RelationEditorPanel = RelationEditorPanel(
51               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
52           panel.setRelation(relation);
53           PopUpManager.centerPopUp(panel);
54         }
55         
56     ]]></mx:Script> 
57     <mx:Text id="warning" text="" />
58     <mx:List width="100%" height="100%" id="relationSelector" verticalScrollPolicy="on"> 
59     </mx:List>
60     <mx:ControlBar>
61       <mx:Button label="New Relation..." click="closeAndNewRelation();"/>
62       <mx:Spacer width="100%"/>
63       <mx:Button label="Select" click="updateEntityAndClose();" enabled="{relationSelector.selectedItem != null? true : false}"/>
64     </mx:ControlBar>
65 </mx:TitleWindow>