Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / TagViewer.mxml
index 816242e..dd1fefb 100644 (file)
@@ -1,4 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
+<!---
+  The TagViewer is the container for the entire sidebar. It has a number of components, and subpanels, in a ViewStack that change
+  depending on what is selected, i.e. the ControllerState.
+
+  @see net.systemeD.potlatch2.controller.ControllerState
+    -->
 <mx:VBox
     xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library://ns.adobe.com/flex/mx"
@@ -32,6 +38,8 @@
                                                        import mx.core.DragSource;
 
                                                        private function dragPOI(event:MouseEvent, tags:Array):void {
+                                                               if (outerDocument.controller.map.dragstate==outerDocument.controller.map.DRAGGING) return;
+
                                                                // Get the drag initiator component from the event object.
                                                                var dragInitiator:Image = event.currentTarget as Image;
                                                                var dragSource:DragSource = new DragSource();
@@ -55,8 +63,8 @@
 
   <!-- Standard tagging panel -->
 
-  <mx:VBox id="tagsPanel" width="100%" height="100%" creationPolicy="auto">
-    <mx:ViewStack id="stack" width="100%" height="100%">
+  <mx:VBox id="tagsPanel" width="100%" height="100%" creationPolicy="auto" tabChildren="true">
+    <mx:ViewStack id="stack" width="100%" height="100%" change="tagsPanel.tabChildren=(event.newIndex==0)">
       <mx:VBox width="100%" height="100%" label="Simple" id="editorContainer" creationComplete="initEditorStackUIs()" styleName="dndPanelVbox">
         <mx:VBox width="100%" verticalGap="1" styleName="dndTagHeader">
           <mx:HBox width="100%" id="iconContainer" styleName="featureSelector">
@@ -70,7 +78,7 @@
         </mx:VBox>
       </mx:VBox>
       <mx:VBox width="100%" height="100%" label="Advanced" id="advancedContainer" initialize="checkAdvanced()" verticalGap="1">
-        <mx:Label id="advancedID" click="openEntityPage()">
+        <mx:Label id="advancedID" click="new HistoryDialog().init(selectedEntity);">
           <mx:htmlText><![CDATA[<i>No Selection</i>]]></mx:htmlText>
         </mx:Label>
 
       import net.systemeD.halcyon.MapPaint;
       import net.systemeD.potlatch2.EditController;
       import net.systemeD.potlatch2.mapfeatures.*;
+      import net.systemeD.potlatch2.history.HistoryDialog;
       import net.systemeD.potlatch2.mapfeatures.editors.*;
       import net.systemeD.potlatch2.utils.*;
       import net.systemeD.controls.CollapsiblePanel;
                        selectedEntity.removeEventListener(Connection.TAG_CHANGED, tagChanged);
                        selectedEntity.removeEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
                        selectedEntity.removeEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
+                       if (selectedEntity is EntityCollection) EntityCollection(selectedEntity).releaseListeners();
                }
 
                if (entities.length==0) {
               markerPanelContents.init(selectedEntity, layer);
               sidebar.selectedChild = markerPanel;
             } else if (connection is SnapshotConnection) {
-              backgroundPanelContents.init(selectedEntity, layer);
+              backgroundPanelContents.init(selectedEntity);
               sidebar.selectedChild = backgroundPanel;
             } else {
               refreshFeatureIcon();
                                        subpanel.styleName="subcategoryPanel";
                                        subpanel.title=subcategory;
                                        subpanels[category][subcategory]=subpanel;
+                                       addConstrainedForm(subpanel);
                                        tabComponents[tab].push(subpanel);
                                }
-                               subpanel.addChild(catEditor);
+                               Form(subpanel.getChildByName("form")).addElement(UIComponent(catEditor));
                        } else {
                                tabComponents[tab].push(catEditor);
                        }
                return 0;
        }
        
-      private function createEditorBox():VBox {
-          var box:VBox = new VBox();
-          box.percentWidth = 100;
-          box.percentHeight = 100;
-          box.styleName = "dndEditorContainer";
-          var form:Form = new Form();
-          form.name = "form";
-          var layout:FormLayout = new FormLayout();
-          form.layout = layout;
-          box.addChild(form);
-          return box;
-      }
+       private function createEditorBox():VBox {
+               var box:VBox = new VBox();
+               box.percentWidth = 100;
+               box.percentHeight = 100;
+               box.styleName = "dndEditorContainer";
+               addConstrainedForm(box);
+               return box;
+       }
+       
+       private function addConstrainedForm(parentObject:DisplayObjectContainer):void {
+               var form:Form = new Form();
+               form.name = "form";
+               form.percentWidth=100;
+               form.addEventListener(mx.events.ResizeEvent.RESIZE, formResizeHandler, false, 0, true);
+               parentObject.addChild(form);
+               if (parentObject.width>0) form.maxWidth=parentObject.width;
+       }
+       
+       private function formResizeHandler(e:Event):void {
+               var form:Form=Form(e.target);
+               if (form.parent.width>0) form.maxWidth=form.parent.width;
+       }
 
-      private function ensureEditorsPopulated(tab:VBox):void {
-          var components:Array = tabComponents[tab];
-          if ( components == null || tab == null || tab.numChildren >= components.length )
-              return;
-          for each (var component:DisplayObject in components ) {
-              tab.addChild(component);
-          }
-      }
+       private function ensureEditorsPopulated(tab:VBox):void {
+               var components:Array = tabComponents[tab];
+               var form:Form=Form(tab.getChildByName("form"));
+               if ( components == null || tab == null || form.numElements >= components.length ) return;
+               for each (var component:DisplayObject in components ) {
+                       form.addElement(UIComponent(component));
+               }
+       }
 
        private function initEditorStackUIs():void {
                editorStackTabNavigator = new TabNavigator();
                        if      ( entity is Node     ) entityText = "Node";
                        else if ( entity is Way      ) entityText = "Way";
                        else if ( entity is Relation ) entityText = "Relation";
-                       advancedID.htmlText = entityText+": <b>"+entity.id+"</b>";
+                       advancedID.htmlText = entityText+": <b>"+entity.id+"</b> "+(entity.status ? entity.status : '');
                }
 
                removeRelationListeners();
       }
 
          public function addNewTag():void {
-               if (stack.selectedChild!=advancedContainer) { return; }
-               advancedTagGrid.addNewTag();
+               if (sidebar.selectedChild==multiplePanel) { multiAdvancedTagGrid.addNewTag(); }
+               else if (stack.selectedChild==advancedContainer) { advancedTagGrid.addNewTag(); }
          }
 
       private function addedToRelation(event:RelationMemberEvent):void {
                                break;
                        
                        case 3: // Delete relation
-                               Alert.show("Do you really want to delete the relation?","Are you sure?",Alert.YES | Alert.CANCEL,null,
+                               var warning:String="This relation has # members. Deleting it will affect all of them and erase this $. Are you really sure?";
+                               warning=warning.replace("#",rel.length).replace("$",rel.getRelationType());
+                               Alert.show(warning,"Are you sure?",Alert.YES | Alert.CANCEL,null,
                                        function(event:CloseEvent):void { 
                                                if (event.detail==Alert.CANCEL) return;
                                                rel.remove(MainUndoStack.getGlobalStack().addAction);
-                                       } );
+                                       } , null, Alert.CANCEL);
                                break;
                }
        }
               navigateToURL(new URLRequest(feature.helpURL), "potlatch_help");
       }
 
-      /** Open up a new browser page showing OSM's view of the current entity. */
-      public function openEntityPage():void {
-          if (selectedEntity != null && selectedEntity.id >= 0) {
-              // This is slightly hard-coded, but not drastically. The ../s could be changed for string manipulation of the apiBase
-              var urlBase:String = connection.apiBase + '../../browse/'
-              navigateToURL(new URLRequest(urlBase+selectedEntity.getType()+'/'+selectedEntity.id), "potlatch_browse");
-          }
-      }
-
       public function addToRelation():void {
           new RelationSelectPanel().init(selectedEntity,new Object());
       }
                if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }
                event.target.height=rows*(event.target.rowHeight+1);
        }
+
   ]]></fx:Script>
 </mx:VBox>