Introduce vc.getName()

Change-Id: I7a069b792f83d9f5d598c2bf8e44fdc7afaeb2f1
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index f874723..81e3f8a 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -1569,20 +1569,31 @@
       var vc = vcClass.create().fromJson(kq["collection"]);
       expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
     });
-  });
 
-  it('shouldn\'t be deserializable from collection with unknown type', function () {
-    var kq = {
-      "@type" : "koral:doc",
-      "match": "match:eq",
-      "type":"type:failure",
-      "value": "Goethe",
-      "key": "author"
-    };
+    it('shouldn\'t be deserializable from collection with unknown type', function () {
+      var kq = {
+        "@type" : "koral:doc",
+        "match": "match:eq",
+        "type":"type:failure",
+        "value": "Goethe",
+        "key": "author"
+      };
 
-    expect(function () {
-      vcClass.create().fromJson(kq)
-    }).toThrow(new Error("Unknown value type: string"));
+      expect(function () {
+        vcClass.create().fromJson(kq)
+      }).toThrow(new Error("Unknown value type: string"));
+    });
+
+    it('should return a name', function () {
+      var vc = vcClass.create();
+      expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
+
+      vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
+      expect(vc.getName()).toEqual("DeReKo");
+
+      vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
+      expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
+    });
   });
 
 
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 07731c7..5d2b498 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -81,6 +81,8 @@
   const loc = KorAP.Locale;
   loc.SHOW_STAT = loc.SHOW_STAT || 'Statistics';
   loc.VERB_SHOWSTAT = loc.VERB_SHOWSTAT || 'Corpus Statistics';
+  loc.VC_allCorpora    = loc.VC_allCorpora    || 'all corpora';
+  loc.VC_oneCollection = loc.VC_oneCollection || 'a virtual corpus';
 
   KorAP._vcKeyMenu = undefined;
   KorAP._vcDatePicker = dpClass.create();
@@ -167,6 +169,7 @@
       return obj;
     },
 
+
     /**
      * Create and render a new virtual collection based on a KoralQuery
      * collection document
@@ -204,7 +207,7 @@
 
       return this;
     },
-
+    
     // Check if the virtual corpus contains a rewrite
     // This is a class method
     checkRewrite : function(json) {
@@ -339,6 +342,21 @@
       this.update();
     },
 
+
+    // Get the reference name
+    getName : function () {
+      if (this._root.ldType() === 'non') {
+        return loc.VC_allCorpora;
+      }
+      else if (this._root.ldType() === 'docGroupRef') {
+        return this._root.ref();
+      }
+      else {
+        return loc.VC_oneCollection;
+      }
+    },
+
+    
     /**
      * Get the generated json string
      */