try to fix some minor dropdown bugs
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / Feature.as
index 6e3e724781302d06bc7b16f4a1a74261e5bd9860..2a250521e725306f9fb77cd8acf249c08eb2dcaf 100644 (file)
@@ -9,10 +9,16 @@ package net.systemeD.potlatch2.mapfeatures {
         private var _xml:XML;
         private static var variablesPattern:RegExp = /[$][{]([^}]+)[}]/g;
         private var _tags:Array;
+        private var _editors:Array;
 
         public function Feature(mapFeatures:MapFeatures, _xml:XML) {
             this.mapFeatures = mapFeatures;
             this._xml = _xml;
+            parseTags();
+            parseEditors();
+        }
+        
+        private function parseTags():void {
             _tags = new Array();
             
             for each(var tag:XML in definition.tag) {
@@ -21,7 +27,28 @@ package net.systemeD.potlatch2.mapfeatures {
                 tagObj["v"] = tag.@v;
                 _tags.push(tagObj);
             }
-
+        }
+        
+        private function parseEditors():void {
+            _editors = new Array();
+            
+            for each(var inputXML:XML in definition.input) {
+                var inputType:String = inputXML.@type;
+                var presenceStr:String = inputXML.@presence;
+                var sortOrderStr:String = inputXML.@priority;
+                var editor:EditorFactory = EditorFactory.createFactory(inputType, inputXML);
+                if ( editor != null ) {
+                    editor.presence = Presence.getPresence(presenceStr);
+                    editor.sortOrder = EditorFactory.getPriority(sortOrderStr);
+                    _editors.push(editor);
+                }
+            }
+            
+            _editors.sortOn(["sortOrder", "name"], [Array.DESCENDING | Array.NUMERIC, Array.CASEINSENSITIVE]);
+        }
+        
+        public function get editors():Array {
+            return _editors;
         }
         
         public function get definition():XML {
@@ -51,12 +78,22 @@ package net.systemeD.potlatch2.mapfeatures {
             var txt:String = icon.children().toXMLString();
             var replaceTag:Function = function():String {
                 var value:String = entity.getTag(arguments[1]);
-                return value == null ? "" : value;
+                return value == null ? "" : htmlEscape(value);
             };
             txt = txt.replace(variablesPattern, replaceTag);
             return txt;
         }
         
+        public static function htmlEscape(str:String):String {
+            var newStr:String = str.replace(/&/g, "&");
+            newStr = newStr.replace(/</g, "&lt;");
+            newStr = newStr.replace(/>/g, "&gt;");
+            newStr = newStr.replace(/"/g, "&quot;");
+            newStr = newStr.replace(/'/g, "&apos;");
+            return newStr;
+        }
+      
+
         public function isInCategory(category:String):Boolean {
             var cats:XMLList = _xml.category;
             if ( cats.length() == 0 )