Merge commit '2.0' into history
[potlatch2.git] / net / systemeD / potlatch2 / RelationSelectPanel.mxml
index 5c58d66b4d96a93afb9d38b38d467d690e49fedd..37a184f7a85c97af9f2b9e2d231e1d7600de0c39 100644 (file)
         private var conn:Connection;
         private var relationList:Array;
         private var entity:Entity;
-               private var tags:Object;
+               private var defaulttags:Object;
 
+        /** Initialise panel used to add and remove relations from an entity.
+        *   @param e Entity that is being edited.
+        *   @param t Object containing tag match patterns as properties, for the kind of relation sought.
+        */
         public function init(e:Entity, t:Object):void {
           entity = e;
-          tags = {}; for (var k:String in t) { tags[k]=t[k]; } // deep copy tags
+          defaulttags = {};
+          for (var k:String in t) {  
+            //tagmatches[k]=t[k];// deep copy match pattern tags
+            defaulttags[k]=t[k][0];  // route=[hiking,foot] -> route=hiking
+          }    
           PopUpManager.addPopUp(this, Application(Application.application), true);
           PopUpManager.centerPopUp(this);
     
           var titles:Array = [];
           conn = Connection.getConnectionInstance();
-          relationList = conn.getMatchingRelationIDs(tags);
+          relationList = conn.getMatchingRelationIDs(t);
           if (relationList.length == 0) {
             warning.text = "No relations available";
           } else {
         }
         
         public function updateEntityAndClose():void {
-                       var relation:Relation = conn.getRelation(relationSelector.selectedItem.relId);
-                       if (entity is EntityCollection) {
-                               var undo:CompositeUndoableAction = new CompositeUndoableAction("Add to relation");
-                               for each (var e:Entity in EntityCollection(entity).entities) {
-                                       if (relation.findEntityMemberIndex(e)==-1) {
-                                               relation.appendMember(new RelationMember(e, ''), undo.push);
+                       var undo:CompositeUndoableAction = new CompositeUndoableAction("Add to relation");
+                       for each (var relObject:Object in relationSelector.selectedItems) {
+                               var relation:Relation = conn.getRelation(relObject.relId);
+                               if (entity is EntityCollection) {
+                                       for each (var e:Entity in EntityCollection(entity).entities) {
+                                               if (relation.findEntityMemberIndex(e)==-1) {
+                                                       relation.appendMember(new RelationMember(e, ''), undo.push);
+                                               }
                                        }
+                               } else {
+                                       relation.appendMember(new RelationMember(entity, ''), undo.push);
                                }
-                               MainUndoStack.getGlobalStack().addAction(undo);
-                       } else {
-                               relation.appendMember(new RelationMember(entity, ''), MainUndoStack.getGlobalStack().addAction);
                        }
+                       MainUndoStack.getGlobalStack().addAction(undo);
                        PopUpManager.removePopUp(this);
         }
         
@@ -62,7 +72,7 @@
                                        members.push(new RelationMember(e, ''));
                                }
                        } else members.push(new RelationMember(entity, ''));
-                       var relation:Relation = conn.createRelation(tags, members, MainUndoStack.getGlobalStack().addAction);
+                       var relation:Relation = conn.createRelation(defaulttags, members, MainUndoStack.getGlobalStack().addAction);
 
                        PopUpManager.removePopUp(this);
                        var panel:RelationEditorPanel = RelationEditorPanel(
         
     ]]></mx:Script> 
     <mx:Text id="warning" text="" />
-    <mx:List width="100%" height="100%" id="relationSelector" verticalScrollPolicy="on"> 
+    <mx:List width="100%" height="100%" id="relationSelector" verticalScrollPolicy="on" allowMultipleSelection="true" 
     </mx:List>
     <mx:ControlBar>
       <mx:Button label="New Relation..." click="closeAndNewRelation();" styleName="titleWindowButton" />
       <mx:Spacer width="100%"/>
-      <mx:Button label="Select" click="updateEntityAndClose();" enabled="{relationSelector.selectedItem != null? true : false}" styleName="titleWindowButton" />
+      <mx:Button label="Select" click="updateEntityAndClose();" enabled="{relationSelector.selectedItems.length>0}" styleName="titleWindowButton" />
     </mx:ControlBar>
 </mx:TitleWindow>