Make VC replaceable via KorAP.vc.fromJson(...)

Change-Id: Ic7de60fd4b67036e52467b8c0c99b59d504a240b
diff --git a/Changes b/Changes
index 656df7a..ee8858a 100755
--- a/Changes
+++ b/Changes
@@ -1,8 +1,9 @@
-0.36 2019-07-23
+0.36 2019-07-25
         - Rename all cookies to be independent
           for different instance (#94).
         - Enable https only via
           configuration option 'https_only'.
+        - Make VC replaceable via KorAP.vc.fromJson().
 
         WARNING: This requires relogin for all users!
 
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index 388a26d..5c1fdfd 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -1869,6 +1869,42 @@
       vc.addRequired(doc5);
       expect(vc.toQuery()).toEqual('referTo "@max/myCorpus" & author = "Goethe"');
     });
+
+    it('should be replaceble via JSON', function () {
+      let vc = KorAP.vc = vcClass.create().fromJson({
+        "@type" : 'koral:docGroup',
+        'operation' : 'operation:or',
+        'operands' : [
+          {
+            '@type' : 'koral:doc',
+            'key' : 'title',
+            'value' : 'Hello World!'
+          },
+          {
+            '@type' : 'koral:doc',
+            'key' : 'foo',
+            'value' : 'bar'
+          }
+        ]
+      });
+
+      expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"')
+
+      let e = vc.element();
+      expect(e.firstChild.firstChild.firstChild.children[0].textContent).toEqual("title");
+      expect(e.firstChild.firstChild.firstChild.children[2].textContent).toEqual("Hello World!");
+
+      vc.fromJson({
+        '@type' : 'koral:doc',
+        'key' : 'foo',
+        'value' : 'bar'
+      });
+
+      expect(vc.toQuery()).toEqual('foo = "bar"');
+      e = vc.element();
+      expect(e.firstChild.firstChild.children[0].textContent).toEqual("foo");
+      expect(e.firstChild.firstChild.children[2].textContent).toEqual("bar");
+    })
   });
 
 
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 5d1ccf0..fd22a97 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -178,19 +178,22 @@
      * corpus document
      */
     fromJson : function(json) {
+
+      let obj;
+      
       if (json !== undefined) {
         // Parse root document
         if (json['@type'] == 'koral:doc') {
-          this._root = docClass.create(this, json);
+          obj = docClass.create(this, json);
         }
         // parse root group
         else if (json['@type'] == 'koral:docGroup') {
-          this._root = docGroupClass.create(this, json);
+          obj = docGroupClass.create(this, json);
         }
 
         // parse root reference
         else if (json['@type'] == 'koral:docGroupRef') {
-          this._root = docGroupRefClass.create(this, json);
+          obj = docGroupRefClass.create(this, json);
         }
         
         // Unknown collection type
@@ -202,12 +205,12 @@
 
       else {
         // Add unspecified object
-        this._root = unspecDocClass.create(this);
+        obj = unspecDocClass.create(this);
       };
 
       // Init element and update
-      this.update();
-
+      this.root(obj);   
+ 
       return this;
     },
 
diff --git a/dev/js/src/vc/docgroup.js b/dev/js/src/vc/docgroup.js
index c73a325..3a22034 100644
--- a/dev/js/src/vc/docgroup.js
+++ b/dev/js/src/vc/docgroup.js
@@ -210,8 +210,10 @@
 
       group.appendChild(op.element());
 
-      var vcchevent = new CustomEvent('vcChange', {'detail':this});
-      KorAP.vc.element().dispatchEvent(vcchevent);
+      if (KorAP.vc) {
+        var vcchevent = new CustomEvent('vcChange', {'detail':this});
+        KorAP.vc.element().dispatchEvent(vcchevent);
+      };
       
       return this;
     },
diff --git a/package.json b/package.json
index 9e58c1d..a85bfbe 100755
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "Kalamar",
   "description": "Mojolicious-based Frontend for KorAP",
   "license": "BSD-2-Clause",
-  "version": "0.36.1",
+  "version": "0.36.2",
   "pluginVersion": "0.1",
   "repository": {
     "type": "git",