refactoring and some bugfixes
[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">
9     <mx:columns>
10         <mx:DataGridColumn editable="true" dataField="label" headerText="Name"/>
11         <mx:DataGridColumn editable="true" dataField="data" headerText="URL"/>
12     </mx:columns>
13   </mx:DataGrid>        
14
15   <mx:HBox horizontalAlign="right" width="100%">
16     <mx:LinkButton label="Delete" click="removeSource()" enabled="{dataGrid.selectedItem != null? true : false}"/>
17     <mx:LinkButton label="Add" click="addNewSource()"/>
18   </mx:HBox>
19
20   <mx:Script><![CDATA[
21
22         /*
23                 Still to do:
24                 - editable hotkeys for each layer
25                 - editable source tag for each layer
26                 - editable bbox for each layer
27                 - ability to use this dialogue to select as well as edit
28                 - automatically select imagery once you've edited it (i.e. itemEditEnd)
29                 - edits should stick around, either in SharedObjects or OSM preferences
30         */
31
32     import mx.managers.PopUpManager;
33     import mx.events.CloseEvent;
34     import mx.core.Application;
35         import mx.collections.ArrayCollection;
36         import mx.controls.List;
37
38         public var dataCollection:ArrayCollection;
39         private var menu:List;
40
41     public function init(title:String, menu:List, source:Array):void {
42                 this.title=title;
43                 this.menu=menu;
44                 dataCollection=new ArrayCollection(source);
45         PopUpManager.addPopUp(this, Application(Application.application), true);
46         PopUpManager.centerPopUp(this);
47         this.addEventListener(CloseEvent.CLOSE, backgroundDialog_close);
48                 dataGrid.dataProvider=dataCollection;
49     }
50     
51     private function backgroundDialog_close(evt:CloseEvent):void {
52         PopUpManager.removePopUp(this);
53                 if (menu) { menu.invalidateList(); }
54     }
55
56         private function addNewSource():void {
57                 dataCollection.addItemAt( {label:'(new name)',data:'(new URL)'} , dataCollection.length);
58                 dataGrid.validateNow();
59                 dataGrid.verticalScrollPosition=dataGrid.maxVerticalScrollPosition;
60                 dataGrid.editedItemPosition = {rowIndex: dataCollection.length-1, columnIndex: 0};
61         }
62         private function removeSource():void {
63                 dataCollection.removeItemAt(dataGrid.selectedIndex);
64         }
65
66   ]]>
67   </mx:Script>
68
69 </mx:TitleWindow>