graying corpus statistic(plus tests+vc test fixed) and fix vc serialization

Change-Id: I3f934c2cc0ebbb0a91b5fa8f529bf3f5c3ebd391
(cherry picked from commit 172d6a4bbc7d29a0fe7c23b114fbbf485e2f4aeb)
diff --git a/dev/demo/vcdemo.js b/dev/demo/vcdemo.js
index 0c66dd3..4e0eaed 100644
--- a/dev/demo/vcdemo.js
+++ b/dev/demo/vcdemo.js
@@ -122,32 +122,32 @@
 
     // Create a new virtual collection by passing a based json object and
     // field menu information
-    var vc = vcClass.create([
+    KorAP.vc = vcClass.create([
       ['title', 'string'],
       ['subTitle', 'string'],
       ['pubDate', 'date'],
       ['author', 'text']
     ]).fromJson(json);
 
-    document.getElementById('vc-view').appendChild(vc.element());
+    document.getElementById('vc-view').appendChild(KorAP.vc.element());
 
-    vc.open();
+    KorAP.vc.open();
 
     // show the current JSON serialization
     KorAP.showJSON = function () {
       var json = document.getElementById("json");
-      json.innerHTML = JSON.stringify(vc.root().toJson(), null, '  ');
+      json.innerHTML = JSON.stringify(KorAP.vc.root().toJson(), null, '  ');
       hljs.highlightBlock(json);
     };
 
     // show the current query serialization
     KorAP.showQuery = function () {
-      document.getElementById("query").innerHTML = vc.root().toQuery();
+      document.getElementById("query").innerHTML = KorAP.vc.root().toQuery();
     };
 
     // make the current vc persistant
     KorAP.makeVCPersistant = function () {
-      vc.makePersistant();
+      KorAP.vc.makePersistant();
     };
     
     //get the corpus statistic (demo function)
diff --git a/dev/js/spec/statSpec.js b/dev/js/spec/statSpec.js
index cb9d713..ec114eb 100644
--- a/dev/js/spec/statSpec.js
+++ b/dev/js/spec/statSpec.js
@@ -7,7 +7,7 @@
 
 
 define(['vc', 'vc/statistic', 'view/corpstatv'], function(vcClass, statClass, corpStatVClass){
-	 
+  
 	var json = {
    	"@type":"koral:docGroup",
    	"operation":"operation:or",
@@ -77,8 +77,81 @@
   	return cb(preDefinedStat);
   }; 
   
- 	
-	describe('KorAP.CorpusStat', function(){
+
+  generateCorpusDocGr = function(){     
+   let vc = vcClass.create().fromJson({
+      "@type" : 'koral:docGroup',
+      'operation' : 'operation:or',
+      'operands' : [
+        {
+          '@type' : 'koral:doc',
+          'key' : 'title', 
+          'match': 'match:eq',
+          'value' : 'Hello World!'
+        },
+        {
+          '@type' : 'koral:doc',   
+          'match': 'match:eq',
+          'key' : 'foo',
+          'value' : 'bar'
+        }
+      ]
+    });  
+   return vc;
+  }
+  
+  generateCorpusDoc = function(){
+    let vc= vcClass.create().fromJson({
+        '@type' : 'koral:doc',
+        'key' : 'title', 
+        'match': 'match:eq',
+        'value' : 'Hello World!',
+        'type'  : 'type:string'      
+    });
+    return vc;
+  };
+  
+  
+  /**
+   * Generate vc with docgroupref
+   */
+  generateCorpusRef = function(){  
+    let vc = vcClass.create().fromJson({
+      "@type" : "koral:docGroupRef",
+      "ref" : "@max/myCorpus"
+    });
+    return vc;
+  };
+  
+  
+  /**
+   * Checks is corpus statistic is active
+   */
+  checkStatActive = function(view, div){   
+    // corpus statistic exists, it is active and reloadStatButton is shown
+    if ((view.firstChild.classList.contains("stattable") === true) 
+      && (view.firstChild.classList.contains("greyOut") === false)
+      && (div.getElementsByClassName("reloadStatB").length == 0) ) { 
+      return true;
+    } 
+    return false;
+  };
+ 
+  
+  /**
+   * Checks if corpus statistic is disabled
+   */
+  checkStatDisabled = function(view, div){
+    if ((view.firstChild.classList.contains("stattable") === true) 
+        && (view.firstChild.classList.contains("greyOut") === true)
+        && (div.getElementsByClassName("reloadStatB").length === 1) ) {
+      return true;
+    }   
+    return false;
+    };
+    
+    
+  describe('KorAP.CorpusStat', function(){
 
 		it('should be initiable', function(){
 		  var stat = statClass.create(preDefinedStat);		
@@ -88,7 +161,7 @@
 		
 		it('should be parsed in a statistic view and displayed as HTML Description List', function(){
 		  var stat = statClass.create(preDefinedStat);		
-      var descL = stat.element();
+          var descL = stat.element();
 			expect(descL.tagName).toEqual('DL');		
 			expect(descL.children[0].tagName).toEqual('DIV');
 			expect(descL.children[0].children[0].tagName).toEqual('DT');
@@ -113,12 +186,14 @@
 	      ['author', 'text']
 	    ]).fromJson(json);
 
+		  KorAP.vc = vc;
+		  
 		  statView = corpStatVClass.create(vc);
-		  //corpStatVClass.show(vc);
+		  // corpStatVClass.show(vc);
 		  
 			var testDiv = document.createElement('div');
 			testDiv.appendChild(statView.show());
-			//statClass.showCorpStat(testDiv, vc);
+			// statClass.showCorpStat(testDiv, vc);
 			
 			expect(testDiv.children[0].tagName).toEqual('DIV');
 			expect(testDiv.children[0].getAttribute("class")).toEqual('stattable');   
@@ -232,5 +307,197 @@
       panel.lastChild.children[0].click();
       expect(panel.firstChild.children.length).toEqual(1);
     });
-  });		
+    
+   
+  });	
+	
+  
+  
+    /**
+     * Test disabling and reload of corpus statistic if vc is changed 
+     * in vc builder through user-interaction
+     */
+	describe ('KorAP.CorpusStat.Disable', function(){
+	
+	  /**
+	   * If the user defines a new vc, the statistic should be disabled,
+	   * because it is out-of-date.
+	   * 
+	   * The user can choose to display an up-to-date corpus statistic. Here it is tested
+	   * if corpus statistic is disabled after a valid change of corpus statistic and if the corpus statistic is updatable.
+	   */ 	  	 
+      it ('should disable the corpus statistic if corpus definition is changed and display a functional reload  button', function(){
+        
+        KorAP.vc = generateCorpusDocGr();  
+        
+        //Show corpus statistic
+        let show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());
+        let panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        let view = panel.firstChild.firstChild;
+        
+        //corpus statistic is active
+        expect(checkStatActive(view, show)).toBe(true);
+        
+        //change vc, a line in vc builder is deleted
+        KorAP._delete.apply(KorAP.vc.root().getOperand(0));
+        expect(checkStatDisabled(view,show)).toBe(true);
+        
+        //click at reload button
+        let rlbutton = show.getElementsByClassName("refresh").item(0);
+        rlbutton.click();
+        
+        expect(checkStatActive(view,show)).toBe(true);
+      });
+      
+      
+      it('should disable corpus statistic if entries in vc builder are deleted', function(){
+        KorAP.vc = generateCorpusDocGr();
+        
+        // create corpus builder and corpus statistic;
+        let show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());   
+        let panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        let view = panel.firstChild.firstChild;
+
+        expect(checkStatActive(view, show)).toBe(true);
+        
+        //delete foo=bar
+        KorAP._delete.apply(KorAP.vc.root().getOperand(1));
+        expect(checkStatDisabled(view, show)).toBe(true);
+       
+        //refresh corpus statistic
+        let rlbutton = show.getElementsByClassName("refresh").item(0);
+        rlbutton.click();
+        expect(checkStatActive(view,show)).toBe(true);   
+            
+        KorAP._delete.apply(KorAP.vc.root());
+        // fails momentarily, does not fail after next commit with Change-Id: Id44736f134c00e1a1be002bf14e00e6efa26ad02
+        //expect(checkStatDisabled(view, show)).toBe(true);        
+      });
+      
+      
+      it('should disable corpus statistic if key, matchoperator or value is changed', function(){  
+        /*         
+         * Doc change of key, match operator and value 
+         */
+        KorAP.vc= generateCorpusDoc();
+        // show vc builder and open corpus statistic
+        let show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());
+        let panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        let view = panel.firstChild.firstChild;
+        expect(checkStatActive(view, show)).toBe(true);
+        
+        KorAP.vc.root().matchop("ne").update();
+        expect(checkStatDisabled(view, show)).toBe(true);
+        
+        let rlbutton = show.getElementsByClassName("refresh").item(0);
+        rlbutton.click();
+        
+        view = panel.firstChild.firstChild;
+        expect(checkStatActive(view, show)).toBe(true);
+        KorAP.vc.root().value("Hello tester").update();
+        expect(checkStatDisabled(view, show)).toBe(true);
+          
+        //refresh corpus statistic
+        rlbutton = show.getElementsByClassName("refresh").item(0);
+        rlbutton.click();
+        view = panel.firstChild.firstChild;
+        expect(checkStatActive(view, show)).toBe(true);
+        
+        KorAP.vc.root().key("author").update();
+        expect(checkStatDisabled(view, show)).toBe(true);
+        
+        
+        /*
+         * DocGroupRef change of value...
+         */  
+        KorAP.vc = generateCorpusRef();
+        show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());
+        panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        view = panel.firstChild.firstChild;
+        expect(checkStatActive(view, show)).toBe(true);
+        
+        KorAP.vc.root().ref("@anton/secondCorpus").update();
+        expect(checkStatDisabled(view, show)).toBe(true);
+        });
+      
+      
+      it('should not disable corpus statistic if docgroup definition is incomplete', function(){
+        
+        KorAP.vc = generateCorpusDocGr();
+        
+        //Show corpus statistic
+        let show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());
+        let panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        let view = panel.firstChild.firstChild;
+        
+        expect(checkStatActive(view, show)).toBe(true);
+
+        KorAP._and.apply(KorAP.vc.root());
+
+        let andbuild = show.getElementsByClassName("builder");
+        expect(andbuild[0].firstChild.classList.contains('docGroup')).toBeTruthy();
+        expect(andbuild[0].firstChild.getAttribute("data-operation")).toEqual("and");  
+        expect(checkStatActive(view, show)).toBe(true);
+      });
+
+      
+      it('should not disable corpus statistic if doc/docref definition is incomplete', function(){
+        
+        /*
+         * DOC incomplete
+         */
+        KorAP.vc = vcClass.create().fromJson();
+        expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
+        
+        // show vc builder and open corpus statistic
+        let show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());
+        let panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        let view = panel.firstChild.firstChild;
+       
+        // corpus statistic should be shown and be up-to-date, reload button is not shown
+        expect(checkStatActive(view, show)).toBe(true);
+        
+        // open the menu
+        KorAP.vc.builder().firstChild.firstChild.click();
+        KorAP._vcKeyMenu._prefix.add("author");
+        let prefElement = KorAP.vc.builder().querySelector('span.pref');
+        // add key 'author' to VC
+        prefElement.click();
+        
+        expect(checkStatActive(view, show)).toBe(true); 
+       
+        
+        /*
+         * DOCREF incomplete
+         */
+        KorAP.vc = vcClass.create().fromJson();
+        expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
+        
+        // show vc builder and open corpus statistic
+        show = document.createElement('div');
+        show.appendChild(KorAP.vc.element());
+        panel = show.firstChild.lastChild.firstChild;
+        panel.lastChild.children[0].click();
+        view = panel.firstChild.firstChild;
+        expect(checkStatActive(view, show)).toBe(true);
+
+        KorAP.vc.builder().firstChild.firstChild.click();
+        KorAP._vcKeyMenu._prefix.add("referTo");
+        prefElement = KorAP.vc.builder().querySelector('span.pref');
+        prefElement.click();
+        expect(checkStatActive(view, show)).toBe(true);
+        });     
+      });
 });
diff --git a/dev/js/spec/vcSpec.js b/dev/js/spec/vcSpec.js
index f657ee9..e7cc4fb 100644
--- a/dev/js/spec/vcSpec.js
+++ b/dev/js/spec/vcSpec.js
@@ -27,7 +27,7 @@
 
   KorAP._vcKeyMenu = undefined;
 
-
+   
   // Helper method for building factories
   buildFactory = function (objClass, defaults) {
     return {
@@ -146,6 +146,7 @@
       expect(doc.key()).toBeUndefined();
       expect(doc.value()).toBeUndefined();
       expect(doc.type()).toEqual("string");
+      expect(doc.incomplete()).toBeTruthy();
     });
 
     it('should be definable', function () {
@@ -161,6 +162,7 @@
       expect(doc.key()).toEqual("title");
       expect(doc.type()).toEqual("string");
       expect(doc.value()).toEqual("Der alte Mann");
+      expect(doc.incomplete()).toBeFalsy();
     });
 
 
@@ -173,6 +175,7 @@
       expect(doc.key()).toEqual("author");
       expect(doc.type()).toEqual("string");
       expect(doc.value()).toEqual("Max Birkendale");
+      expect(doc.incomplete()).toBeFalsy();
 
       // No valid string
       doc = stringFactory.create({
@@ -195,6 +198,7 @@
       expect(doc.key()).toEqual("author");
       expect(doc.type()).toEqual("string");
       expect(doc.value()).toEqual("Max Birkendale");
+      expect(doc.incomplete()).toBeFalsy();
 
       // Invalid match type
       doc = stringFactory.create({
@@ -216,6 +220,7 @@
       });
       expect(doc.matchop()).toEqual('ne');
       expect(doc.rewrites()).toBeUndefined();
+      expect(doc.incomplete()).toBeFalsy();
 
       // Invalid matcher
       doc = regexFactory.create({
@@ -345,6 +350,12 @@
       doc = stringFactory.create();
       expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
 
+      // Check for incompletion
+      expect(doc.incomplete()).toBeFalsy();
+      doc.value("");
+      expect(doc.incomplete()).toBeTruthy();
+      expect(doc.toQuery()).toEqual('');
+
       // Serialize string with quotes
       doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
       expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
@@ -570,6 +581,17 @@
           '(pubDate since 2014-05-12 & ' +
           'pubDate until 2014-12-05 & foo != /[a]?bar/)'
       );
+
+
+      // Check for incompletion and only serialize complete operands
+      expect(docGroup.incomplete()).toBeFalsy();
+      var op1 = docGroup.getOperand(0);
+      op1.value("");
+      expect(docGroup.incomplete()).toBeFalsy();
+      expect(docGroup.toQuery()).toEqual(
+        '(pubDate since 2014-05-12 & ' +
+          'pubDate until 2014-12-05 & foo != /[a]?bar/)'
+      );
     });
   });
 
@@ -625,6 +647,12 @@
       expect(vcRef.toQuery()).toEqual(
         "referTo \"@peter/myCorpus2\""
       );
+
+      // Check for incompletion and only serialize complete operands
+      expect(vcRef.incomplete()).toBeFalsy();
+      vcRef.ref("");
+      expect(vcRef.incomplete()).toBeTruthy();
+      expect(vcRef.toQuery()).toEqual("");
     });
   });
 
@@ -637,6 +665,7 @@
       expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
       expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
       expect(doc.toQuery()).toEqual('');
+      expect(doc.incomplete()).toBeTruthy();
 
       // Only removable
       expect(docElement.lastChild.children.length).toEqual(0);
@@ -731,7 +760,9 @@
     });
     
     it('should be replaceable on root', function () {
+      
       var vc = vcClass.create();
+      KorAP.vc = vc;
       expect(vc.toQuery()).toEqual("");
 
       expect(vc.root().ldType()).toEqual("non");
@@ -756,6 +787,8 @@
       var vc = vcClass.create([
         ["pubDate", "date"]
       ]);
+      KorAP.vc = vc;
+
       expect(vc.toQuery()).toEqual("");
       expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
       expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
@@ -805,6 +838,7 @@
         "value":"Baum",
         "match":"match:eq"
       });
+      KorAP.vc = vc;
       expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
 
       var vcE = vc.builder();
@@ -837,6 +871,7 @@
         "match":"match:eq"
       });
 
+      KorAP.vc = vc;
       expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
 
       var vcE = vc.builder();
@@ -870,6 +905,7 @@
         "match":"match:eq"
       });
 
+      KorAP.vc = vc;
       expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
 
       var vcE = vc.builder();
@@ -911,6 +947,7 @@
         ]
       });
 
+    KorAP.vc = vc;
       expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
 
       var vcE = vc.builder();
@@ -2936,29 +2973,32 @@
 
 
     it('should be clickable', function () {
-      var vc = vcClass.create([
+      KorAP.vc = vcClass.create([
         ['a', null],
         ['b', null],
         ['c', null]
       ]).fromJson();
-      expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
+      
+      //vc = KorAP.vc;
+      
+      expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
 
       // This should open up the menu
-      vc.builder().firstChild.firstChild.click();
-      expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
+      KorAP.vc.builder().firstChild.firstChild.click();
+      expect(KorAP.vc.builder().firstChild.firstChild.tagName).toEqual('UL');
 
       KorAP._vcKeyMenu._prefix.clear();
       KorAP._vcKeyMenu._prefix.add('x');
 
-      var prefElement = vc.builder().querySelector('span.pref');
+      var prefElement = KorAP.vc.builder().querySelector('span.pref');
       expect(prefElement.innerText).toEqual('x');
 
       // This should add key 'x' to VC
       prefElement.click();
 
-      expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
-      expect(vc.builder().firstChild.firstChild.className).toEqual('key');
-      expect(vc.builder().firstChild.firstChild.innerText).toEqual('x');
+      expect(KorAP.vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
+      expect(KorAP.vc.builder().firstChild.firstChild.className).toEqual('key');
+      expect(KorAP.vc.builder().firstChild.firstChild.innerText).toEqual('x');
     });
   });
 
diff --git a/dev/js/src/panel/vcpanel.js b/dev/js/src/panel/vcpanel.js
index 98a9b4b..e12c20c 100644
--- a/dev/js/src/panel/vcpanel.js
+++ b/dev/js/src/panel/vcpanel.js
@@ -43,10 +43,19 @@
       if (this.statView === undefined || !this.statView.shown()) {
         this.statView = corpStatVClass.create(this.vc, this);
         this.add(this.statView);
+        this.vc.oldvcQuery = KorAP.vc.toQuery();
       }
 
     },
     
+    /**
+     * Reload corpus statistic 
+     *
+     */
+    reloadCorpStat: function(){
+      this.statView.close();
+      this.addCorpStat();
+    }
     
   }
 });
diff --git a/dev/js/src/vc.js b/dev/js/src/vc.js
index 711008f..0431f92 100644
--- a/dev/js/src/vc.js
+++ b/dev/js/src/vc.js
@@ -81,6 +81,8 @@
   // KorAP._validDateMatchRE is defined in datepicker.js!
 
   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';
   loc.MINIMIZE         = loc.MINIMIZE         || 'Minimize';
@@ -360,13 +362,12 @@
     
     /**
      * Update the whole object based on the underlying data structure
-     */ 
+     */    
     update : function() {
       this._root.update();
+      this.checkGrayingStat();
       return this;
     },
-    
- 
     /**
      * Make the vc persistant by injecting the current timestamp as a
      * creation date limit criterion.
@@ -478,8 +479,17 @@
       //Create panel  
       this.panel = vcPanelClass.create(this); 
       dv.appendChild(this.panel.element());
+      
     },
     
-    
+    /**
+     * Checks if corpus statistic has to be greyOut,
+     * and to be updated after clicking at the "reload-button"
+     */
+    checkGrayingStat : function(){
+      if(this.panel !== undefined && this.panel.statView !==undefined){
+        this.panel.statView.checkGrayingStatistic();
+      }
+    }
   };
 });
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 996c347..2a0e872 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -149,6 +149,10 @@
         e.appendChild(op.element());
       };
       
+      if(KorAP.vc){
+        KorAP.vc.checkGrayingStat();
+      }
+      
       return e;
     },
 
@@ -616,9 +620,12 @@
       };
     },
 
+    incomplete : function () {
+      return !(this.matchop() && this.key() && this.value());
+    },
 
     toQuery : function () {
-      if (!this.matchop() || !this.key())
+      if (this.incomplete())
         return "";
 
       // Build doc string based on key
diff --git a/dev/js/src/vc/docgroup.js b/dev/js/src/vc/docgroup.js
index 7ce2fed..10a6495 100644
--- a/dev/js/src/vc/docgroup.js
+++ b/dev/js/src/vc/docgroup.js
@@ -356,7 +356,7 @@
     toQuery : function (brackets) {
       var list = this._operands
 	        .filter(function (op) {
-	          return op.ldType() !== 'non';
+            return !op.incomplete();
 	        })
 	        .map(function (op) {
 	          return (op.ldType() === 'docGroup') ?
diff --git a/dev/js/src/vc/docgroupref.js b/dev/js/src/vc/docgroupref.js
index 7d3ecea..fa82a4b 100644
--- a/dev/js/src/vc/docgroupref.js
+++ b/dev/js/src/vc/docgroupref.js
@@ -109,7 +109,7 @@
         // Append new operators
         e.appendChild(op.element());
       };  
-
+      KorAP.vc.checkGrayingStat();
       return this.element();
     },
 
@@ -207,7 +207,6 @@
       return this;
     },
 
-
     /**
      * Click on the unspecified object
      */
@@ -261,9 +260,13 @@
       };
     },
 
+
+    incomplete : function () {
+      return this.ref() ? false : true
+    },
     
     toQuery : function () {
-      if (!this.ref())
+      if (this.incomplete())
         return "";
 
       // Build doc string based on key
diff --git a/dev/js/src/vc/jsonld.js b/dev/js/src/vc/jsonld.js
index 600a5bb..21260d4 100644
--- a/dev/js/src/vc/jsonld.js
+++ b/dev/js/src/vc/jsonld.js
@@ -99,6 +99,10 @@
       return null;
     },
 
+    incomplete : function () {
+      return false;
+    },
+
     toQuery : function () {
       return '';
     }
diff --git a/dev/js/src/vc/unspecified.js b/dev/js/src/vc/unspecified.js
index 6ffa0e3..416ad85 100644
--- a/dev/js/src/vc/unspecified.js
+++ b/dev/js/src/vc/unspecified.js
@@ -121,6 +121,11 @@
       return this._element;
     },
 
+
+    incomplete : function () {
+      return true;
+    },
+    
     /**
      * Click on the unspecified object
      */
diff --git a/dev/js/src/view/corpstatv.js b/dev/js/src/view/corpstatv.js
index 1cc6f0c..44a9ae2 100644
--- a/dev/js/src/view/corpstatv.js
+++ b/dev/js/src/view/corpstatv.js
@@ -3,18 +3,20 @@
  * 
  * @author Helge Stallkamp
  */
+
 define([ 'view', 'vc/statistic' ], function(viewClass, statClass) {
 
   const d = document;
 
   return {
-    create : function(vc) {
+    create : function(vc, panel) {
       return Object.create(viewClass)._init([ 'vcstatistic' ]).upgradeTo(this)
-          ._init(vc);
+          ._init(vc, panel);
     },
 
-    _init : function(vc) {
+    _init : function(vc, panel) {
       this.vc = vc;
+      this.panel = panel;
       return this;
     },
 
@@ -71,9 +73,10 @@
      * Show corpus statistic view 
      */
     show : function() {
+      
       if (this._show)
-        return this._show;
-
+        return this._show; 
+      
       var statTable = document.createElement('div');
       statTable.classList.add('stattable', 'loading');
   
@@ -91,13 +94,70 @@
 
         statisticobj = statClass.create(statistic);
         statTable.appendChild(statisticobj.element());
+    
       });
 
       this._show = statTable;
       return statTable;
 
     },
+    
 
+    
+    /**
+     * Checks if graying necessary
+     */
+    checkGrayingStatistic : function (){   
+     var newString = KorAP.vc.toQuery();
+     var oldString = this.vc.oldvcQuery;
+     
+     /*
+      * Do ignore surrounding round brackets
+      * Definining an incomplete docGroup in the vc builder: 
+      * (foo = bar and author = Goethe) and ... 
+      * leads to 
+      * vc.toQuery() -> (foo = bar and author=Goethe)
+      */
+     if(newString.startsWith('(')){
+       newString = newString.slice(1, newString.length-1);
+     }
+     
+      if(newString && newString != oldString) {
+        this.grayingStat();
+      }   
+   },
+   
+    /**
+     * Graying corpus statistic if in vc builder a different vc is choosen.
+     * After clicking at the reload-button the up-to-date corpus statistic is displayed.
+     */   
+    grayingStat : function(){
+      var statt = this._show;
+      
+      if(statt.getElementsByClassName('reloadStatB').length == 0){
+          var reloadspan = document.createElement('span');
+          reloadspan.classList.add('reloadStatB');
+          reloadb = reloadspan.addE('span');
+          reloadb.classList.add('refresh');
+          
+          var that = this;
+          
+          reloadb.addEventListener("click", function (e){    
+          statt.classList.remove('greyOut');
+          that.panel.actions.element().querySelector(".statistic").classList.remove('greyOut');
+          that.panel.reloadCorpStat(); 
+             });
+          
+ 
+        statt.appendChild(reloadspan);
+        statt.classList.add('greyOut');        
+        this.panel.actions.element().querySelector(".statistic").classList.add('greyOut');
+        
+        console.log("Corpus statistic DISABLED");
+        }
+    },
+
+    
     /**
      * Close the view.
      */