Include relation memberships in tag summary
authorRichard Fairhurst <richard@systemeD.net>
Wed, 1 Aug 2012 16:01:06 +0000 (17:01 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Wed, 1 Aug 2012 16:01:06 +0000 (17:01 +0100)
net/systemeD/potlatch2/TagViewer.mxml

index fd59757..9ba9b14 100644 (file)
                                if (entity==null) {
                                        iconText.htmlText = "<i>Nothing selected</i>";
                                        setSummary('');
-                               } else if (entity.hasTags()) {
+                               } else if (entity.hasTags() || entity.parentRelations.length>0) {
                                        iconText.htmlText = "<b>Not recognised</b><br/><font size='10pt'>Try looking at the tags under the advanced properties</font>";
                                        setSummary(tagSummary(entity));
                                } else {
                        }
          }
 
-       /** Construct an HTML string that summarises the tags of an object. */
+       /** Construct an HTML string that summarises the tags and relation memberships of an object. */
        private function tagSummary(entity:Entity):String {
+               // Process tags
                var tags:Object=entity.getTagsCopy();
                var len:uint=entity.getTagList().length;
                var expl:Array=[];
-               var t:String;
+               var t:String="none";
                if (tags['name']) {
                        expl.push("<b>"+tags['name']+"</b>"); delete tags['name']; len--;
                }
                                default:        expl.push("and "+len+" other tags"); break;
                        }
                        t=expl.join('; ');
-               } else {
+               } else if (len>0) {
                        t=entity.getTagList().toString();
                }
-               return "<p>Tags: "+t+" <b>(<a href='event:openAdvanced'>edit tags</a>)</b></p>";
+
+               // Process relations
+               expl=[];
+               for each (var rel:Relation in entity.parentRelations) {
+                       tags=rel.getTagsHash();
+                       if (tags['type'] && tags['name']) { expl.push("<b>"+tags['type']+"</b> ("+tags['name']+")"); }
+                       else if (tags['type']) { expl.push("<b>"+tags['type']+"</b>"); }
+                       else if (tags['name']) { expl.push(tags['name']); }
+                       else if (tags['ref' ]) { expl.push(tags['ref']); }
+                       else { expl.push('unknown'); }
+               }
+
+               // Assemble complete string
+               return "<p>Tags: "+t+(expl.length ? "<br>Relations: "+expl.join('; ') : '')+" <b>(<a href='event:openAdvanced'>edit</a>)</b></p>";
        }
        
        /** List of 'noun' keys (i.e. those that define the type of the object, rather than its properties). FIXME: should be defined in a config file. */
 
       private function addedToRelation(event:RelationMemberEvent):void {
          resetRelationsGrid(selectedEntity);
+         refreshFeatureIcon();
       }
 
       private function removedFromRelation(event:RelationMemberEvent):void {
          resetRelationsGrid(selectedEntity);
+         refreshFeatureIcon();
       }
 
       private function removeRelationListeners():void {
 
       private function relationTagChanged(event:TagEvent):void {
           resetRelationsGrid(selectedEntity);
+          refreshFeatureIcon();
       }
 
       private function entityRelationMemberChanged(event:RelationMemberEvent):void {