Support VC references in VC builder to fix #62

Change-Id: Iec84c12ade2f64e8bbbd3d42b9e52788a0fba3fe
diff --git a/dev/js/src/vc/unspecified.js b/dev/js/src/vc/unspecified.js
index 56d0869..6ffa0e3 100644
--- a/dev/js/src/vc/unspecified.js
+++ b/dev/js/src/vc/unspecified.js
@@ -5,8 +5,9 @@
 define([
   'vc/jsonld',
   'vc/doc',
+  'vc/docgroupref',
   'util'
-], function (jsonldClass, docClass) {
+], function (jsonldClass, docClass, docGroupRefClass) {
 
   // Localize empty string
   var loc = KorAP.Locale;
@@ -40,9 +41,18 @@
       if (this._parent === undefined)
 	      return null;
 
+      var newDoc;
+      var keyType = KorAP._vcKeyMenu.typeOf(v);
+
       // Set JSON-LD type
-      var newDoc = docClass.create(this._parent);
-      newDoc.key(v);
+      if (keyType && keyType === 'ref') {
+        newDoc = docGroupRefClass.create(this._parent);
+      }
+      else {
+        newDoc = docClass.create(this._parent);
+        newDoc.key(v);
+        newDoc.type(keyType);
+      };
   
       // Unspecified document on root
       if (this._parent.ldType() === null) {
@@ -82,7 +92,8 @@
       this._element.refTo = this;
 
       // Set operators
-      if (this._parent !== undefined && this.parent().ldType() !== null) {
+      if (this._parent !== undefined &&
+          this.parent().ldType() !== null) {
 	      var op = this.operators(
 	        false,
 	        false,
@@ -127,9 +138,9 @@
       var that = this;
 
       // Set released method
-      menu.released(function (key, type) {
+      menu.released(function (key) {
 	      // Set chosen key and type - will return a doc
-	      that.key(key).type(type).update();
+	      that.key(key).update();
 	      this.hide();
       });