New Bookmarks menu
[potlatch2.git] / net / systemeD / potlatch2 / BookmarkSelector.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <s:BorderContainer
3     xmlns:controls="net.systemeD.controls.*"
4         xmlns:fx="http://ns.adobe.com/mxml/2009"
5     xmlns:s="library://ns.adobe.com/flex/spark" >
6
7     <s:layout>
8       <s:VerticalLayout
9           paddingLeft="5" paddingRight="5"
10           paddingTop="5" paddingBottom="5"/>
11     </s:layout>
12
13         <s:List width="100%" height="100%" id="bookmarkMenu"
14                 labelField="name"
15             itemRenderer="net.systemeD.controls.DeletableListItemRenderer"
16                 change="FlexGlobals.topLevelApplication.bookmarkButton.close(); goToBookmark(event);"
17             dataProvider="{bookmarks}">
18       <s:layout>
19         <s:VerticalLayout requestedRowCount="{bookmarks.length}" gap="0" rowHeight="20" variableRowHeight="false" horizontalAlign="contentJustify"/> 
20       </s:layout>
21     </s:List>
22
23         <s:Button id="addButton" label="Add..." click="FlexGlobals.topLevelApplication.bookmarkButton.close(); addBookmark();" />
24
25         <fx:Script><![CDATA[
26                 import net.systemeD.halcyon.*;
27                 import net.systemeD.halcyon.connection.*;
28                 import net.systemeD.potlatch2.*;
29                 import net.systemeD.potlatch2.collections.Stylesheets;
30                 import net.systemeD.potlatch2.dialogs.*;
31                 import net.systemeD.controls.DeletableListItemRenderer;
32                 import mx.core.*;
33         import spark.events.IndexChangeEvent;
34                 import mx.collections.ArrayCollection;
35         import mx.managers.PopUpManager;
36
37                 [Bindable]
38         public var bookmarks:ArrayCollection = new ArrayCollection([]);
39                 // of format { name: "Bookmark 1", lat: 53, lon: 0 }, { name: "Bookmark 2", lat: 54, lon: -1 }
40
41                 private var userState:SharedObject=SharedObject.getLocal("user_state","/");
42
43                 public function init():BookmarkSelector {
44                         if (userState.data['bookmarks']) {
45                                 bookmarks = new ArrayCollection(userState.data['bookmarks']);
46                         }
47                         return this;
48                 }
49
50                 private function goToBookmark(event:IndexChangeEvent):void {
51                         FlexGlobals.topLevelApplication.theController.map.moveMapFromLatLon(event.currentTarget.selectedItem.lat, event.currentTarget.selectedItem.lon);
52                 }
53                 
54                 private function addBookmark():void {
55                         var dialog:BookmarkNameDialog = BookmarkNameDialog(
56                             PopUpManager.createPopUp(Application(FlexGlobals.topLevelApplication), BookmarkNameDialog, true));
57                         PopUpManager.centerPopUp(dialog);
58                         // save to SharedObject
59                 userState.setProperty("bookmarks",bookmarks.source);
60                 try { userState.flush(); } catch (e:Error) {}
61                 }
62     ]]></fx:Script>
63 </s:BorderContainer>
64