Merge commit '2.0' into history
[potlatch2.git] / net / systemeD / potlatch2 / BackgroundDialog.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:TitleWindow
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         layout="vertical" showCloseButton="true"
5         horizontalAlign="center" 
6         width="500" height="300" verticalGap="0">
7
8   <mx:DataGrid editable="true" width="100%" height="100%" id="dataGrid" itemEditEnd="updateSource()">
9     <mx:columns>
10         <mx:DataGridColumn editable="true"  dataField="name" headerText="Name"/>
11         <mx:DataGridColumn editable="true"  dataField="url" headerText="URL"/>
12         <mx:DataGridColumn editable="false" headerText="Key" width="70">
13                         <mx:itemRenderer>
14                                 <mx:Component>
15                                 <mx:ComboBox
16                                         selectedItem="{FunctionKeyManager.instance().getKeyFor(outerDocument.title,data.name)}"
17                                     dataProvider="{FunctionKeyManager.fkeysCollection}"
18                                         change="FunctionKeyManager.instance().setKeyFromFString(selectedItem as String,outerDocument.title,data.name)" />
19                                 </mx:Component>
20                         </mx:itemRenderer>
21                 </mx:DataGridColumn>
22     </mx:columns>
23   </mx:DataGrid>
24
25   <mx:HBox horizontalAlign="right" width="100%">
26     <mx:LinkButton label="Delete" click="removeSource()" enabled="{dataGrid.selectedItem != null? true : false}"/>
27     <mx:LinkButton label="Add" click="addNewSource()"/>
28   </mx:HBox>
29
30   <mx:Script><![CDATA[
31
32         /*
33                 Still to do:
34                 - editable source tag for each layer
35                 - editable bbox for each layer
36                 - ability to use this dialogue to select as well as edit
37                 - automatically select imagery once you've edited it (i.e. itemEditEnd)
38                 - edits should stick around, either in SharedObjects or OSM preferences
39         */
40
41     import mx.managers.PopUpManager;
42     import mx.events.CloseEvent;
43     import mx.core.Application;
44         import mx.collections.ArrayCollection;
45         import mx.controls.List;
46         import net.systemeD.potlatch2.FunctionKeyManager;
47
48         public var dataCollection:ArrayCollection;
49         private var menu:List;
50         private var collection:Object;
51
52     public function init(title:String, menu:List, source:Object):void {
53                 this.title=title;
54                 this.menu=menu;
55                 collection=source;
56                 dataCollection=new ArrayCollection(source.collection);
57         PopUpManager.addPopUp(this, Application(Application.application), true);
58         PopUpManager.centerPopUp(this);
59         this.addEventListener(CloseEvent.CLOSE, backgroundDialog_close);
60                 dataGrid.dataProvider=dataCollection;
61     }
62     
63     private function backgroundDialog_close(evt:CloseEvent):void {
64         PopUpManager.removePopUp(this);
65                 if (menu) { menu.invalidateList(); }
66     }
67
68         private function addNewSource():void {
69                 dataCollection.addItemAt( {name:'(new name)',url:'(new URL)'} , dataCollection.length);
70                 dataGrid.validateNow();
71                 dataGrid.verticalScrollPosition=dataGrid.maxVerticalScrollPosition;
72                 dataGrid.editedItemPosition = {rowIndex: dataCollection.length-1, columnIndex: 0};
73         }
74         private function removeSource():void {
75                 dataCollection.removeItemAt(dataGrid.selectedIndex);
76         }
77         public function updateSource():void {
78                 collection.dispatchEvent(new Event("collection_changed"));
79         }
80
81   ]]>
82   </mx:Script>
83
84 </mx:TitleWindow>