fix minor breakage
[potlatch2.git] / potlatch2.mxml
index d1ac89a..660b8d9 100755 (executable)
@@ -29,6 +29,7 @@
             creationComplete="bgButton.popUp = new BackgroundSelector();"/>
         <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true"
             creationComplete="styleButton.popUp = new StyleSelector();"/>
+        <mx:Button label="GPS" click="trackLoader.load();"/>
         <mx:Spacer width="100%"/>
         <mx:Button label="Undo" click="MainUndoStack.getGlobalStack().undo();"
             enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
         import mx.events.DragEvent;
         import mx.managers.DragManager;
         import mx.core.DragSource;
+        import mx.controls.Alert;
 
         public var theMap:Map;
         public var theController:EditController;
                public var yahoo:Yahoo;
+               public var trackLoader:TrackLoader;
                public var toolbox:Toolbox;
 
                private var savecount:uint=0;
                        Globals.vars.map_area = map_area;
                        Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
                        var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
+                       Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
 
                        // populate sharedObject with loaderInfo parameters if supplied
                        var obj:SharedObject = SharedObject.getLocal("user_state");
                        if (objChanged) { obj.flush(); }
 
                        // load imagery and style XML
-               var request:URLRequest = new URLRequest("imagery.xml?"+Math.random());
+               var request:DebugURLRequest = new DebugURLRequest("imagery.xml");
                var loader:URLLoader = new URLLoader();
                loader.addEventListener(Event.COMPLETE, onImageryLoad);
-               loader.load(request);
+               loader.load(request.request);
 
-                       var request2:URLRequest = new URLRequest("stylesheets.xml?"+Math.random());
+                       var request2:DebugURLRequest = new DebugURLRequest("stylesheets.xml");
                        var loader2:URLLoader = new URLLoader();
                loader2.addEventListener(Event.COMPLETE, onStylesheetsLoad);
-               loader2.load(request2);
+               loader2.load(request2.request);
 
                        // map backdrop object
             var w:uint = map_area.width;
             conn.addEventListener(Connection.SAVE_COMPLETED, onDataComplete);
             conn.addEventListener(Connection.DATA_DIRTY, onDataDirty);
             conn.addEventListener(Connection.DATA_CLEAN, onDataClean);
+                       conn.addEventListener(MapEvent.ERROR, onMapError);
+
+                       // create GPS trackloader
+                       trackLoader=new TrackLoader(theMap,conn.apiBase);
+
+            // show help dialog on startup, if required
+            // show_help == always => on every startup
+            // show_help == once => show on first startup only
+            var show_help:String = loaderInfo.parameters["show_help"];
+
+            if (show_help == 'always' || (show_help == 'once' && obj.data["help_shown"] != "true")) {
+              new HelpDialog().init();
+            }
                }
                
+               public function onMapError(event:MapEvent):void {
+                       Alert.show(event.params.message, 'Error', mx.controls.Alert.OK);
+               }
+
         public function onResizeMap():void {
             if ( theMap != null )
                 theMap.updateSize(map_area.width, map_area.height);
                }
         private function onDataDirty(event:Event):void {
                        saveButton.enabled=true;
+            if (ExternalInterface.available) {
+              ExternalInterface.call("markChanged", false);
+            }
                }
                private function onDataClean(event:Event):void {
                        saveButton.enabled=false;
+            if (ExternalInterface.available) {
+              ExternalInterface.call("markChanged", true);
+            }
                }
                
         private function onImageryLoad(event:Event):void {
                        var xml:XML = new XML(URLLoader(event.target).data);
                        var saved_url:String = SharedObject.getLocal("user_state").data['stylesheet_url'];
                        var saved_name:String= SharedObject.getLocal("user_state").data['stylesheet_name'];
-                       var xml_url:String, xml_name:String, isSet:Boolean=false;
-                       if (!saved_url) { saved_url='potlatch.css'; saved_name='Potlatch'; }
-                       
-                       // create menu
+                       var xml_url:String, xml_name:String, isInMenu:Boolean=false, isSet:Boolean=false;
+
+            // first, build the menu from the stylesheet list.
+            // Also ensure the saved_url is in the menu (might be either saved from before, or supplied via loaderInfo)
             theController.stylesheets=new Array();
                        for each(var set:XML in xml.stylesheet) {
                                xml_url= set.child("url");
                                xml_name=set.child("name");
                 theController.stylesheets.push({ label:xml_name, data:xml_url });
-                               if (xml_url==saved_url || (xml_name==saved_name && xml_name!='Custom')) { isSet=true; }
+                               if (xml_url==saved_url || (xml_name==saved_name && xml_name!='Custom')) { isInMenu=true; }
                        }
-                       if (!isSet) { theController.stylesheets.push({ label:saved_name, data:saved_url }); }
-
-                       for each (var bg:Object in theController.stylesheets) {
-                               if (bg['label']==saved_nameĀ || bg['data']==saved_url) { 
-                                       setStylesheet(bg['label'], bg['data']);
+                       if (saved_url && !isInMenu) { theController.stylesheets.push({ label:saved_name, data:saved_url }); }
+
+            // pick a stylesheet to be set. It should be the saved one, if it is in the menu
+            // or alternatively the first one on the menu,
+            // or finally try 'potlatch.css'
+                       for each (var ss:Object in theController.stylesheets) {
+                               if (ss['label']==saved_nameĀ || ss['data']==saved_url) {
+                                       setStylesheet(ss['label'], ss['data']);
+                    isSet = true;
+                    break;
                                }
                        }
+            if (!isSet) {
+              if(theController.stylesheets.length > 0) {
+                var s:Object = theController.stylesheets[0];
+                setStylesheet(s['label'], s['data']);
+              } else {
+                //hit and hope. FIXME should this be an error state?
+                theController.stylesheets.push({ label:'Potlatch', data:'potlatch.css'});
+                setStylesheet('Potlatch','potlatch.css');
+              }
+            }
                }
 
                public function setStylesheet(name:String,url:String):void {