Load VC by default and solely rely on VC.getName() for VC name

Change-Id: I14a7894f44dc390af1718053b681d09fcfb2e481
diff --git a/Changes b/Changes
index f703223..4ee4684 100755
--- a/Changes
+++ b/Changes
@@ -1,10 +1,11 @@
-0.28 2018-08-17
+0.28 2018-08-28
         - Introduced Widget based plugin system.
         - Added corpus statistics to VC (hebasta, #25).
         - Introduce center alignment (#63).
         - Change KWIC lines from table style
           to flexbox style (#31).
         - Added doc group reference to VC builder (#62).
+        - Show VC name, when a reference is defined.
 
 0.27 2018-07-23
         - Introduced content blocks to create
diff --git a/dev/demo/all.html b/dev/demo/all.html
index e19b474..d959a6b 100644
--- a/dev/demo/all.html
+++ b/dev/demo/all.html
@@ -40,7 +40,7 @@
         <div id="vc-view"></div>
         in
         <input id="show" name="show" type="hidden" />
-        <input id="collection-name" name="collection-name" type="hidden">
+        <!--<input id="collection-name" name="collection-name" type="hidden"> -->
         <input id="collection" name="collection" type="text" value="">
 	with <span class="menu select">
 	  <select name="ql" id="ql-field">
diff --git a/dev/demo/alldemo.js b/dev/demo/alldemo.js
index 5a3d3c8..02a6190 100644
--- a/dev/demo/alldemo.js
+++ b/dev/demo/alldemo.js
@@ -765,11 +765,18 @@
 
 KorAP.currentQuery = queryExample;
 
+/*
+KorAP.koralQuery["collection"] = {
+  "@type" : "koral:docGroupRef",
+  "ref" : "This is my name"
+};
+*/
+
 require(['app/en', 'init', 'hint/foundries/cnx'], function (lang) {
   KorAP.hintArray = hintArray;
 
   // Set current virtual collection
-  KorAP.currentVC = vcExample;
+  // KorAP.currentVC = vcExample;
 
   // Parse and show the table
   // Override getMatchInfo API call
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 21887f3..d992c3f 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -40,11 +40,6 @@
              selectMenuClass,
              resultPanelClass) {
 
-  // Localization values
-  const loc = KorAP.Locale;
-  loc.VC_allCorpora    = loc.VC_allCorpora    || 'all corpora';
-  loc.VC_oneCollection = loc.VC_oneCollection || 'a virtual corpus';
-
   const d = document;
 
   KorAP.session = sessionClass.create('KalamarJS');
@@ -87,23 +82,35 @@
      */
     var vcname, vcchoose;
     var input = d.getElementById('collection');
+
+    var vc = vcClass.create(vcArray);
+
+    // Add vc name object
     if (input) {
       input.style.display = 'none';
       vcname = d.createElement('span');
       vcname.setAttribute('id', 'vc-choose');
       vcname.classList.add('select');
 
-      var currentVC = loc.VC_allCorpora;
+      // Load virtual corpus object
       if (KorAP.koralQuery !== undefined && KorAP.koralQuery["collection"]) {
-        currentVC = loc.VC_oneCollection;
+        try {
+          vc.fromJson(KorAP.koralQuery["collection"]);
+        }
+        catch (e) {
+          KorAP.log(0,e);
+        }
       };
 
       vcchoose = vcname.addE('span');
-
       vcchoose.addT(
-        d.getElementById('collection-name').value || currentVC
+        vc.getName()
       );
 
+      if (vc.wasRewritten()) {
+        vcchoose.classList.add('rewritten');
+      };
+
       input.parentNode.insertBefore(vcname, input);
     };
 
@@ -245,7 +252,6 @@
      * Toggle the Virtual Collection builder
      */
     if (vcname) {
-      var vc;
       var vcclick = function () {
         var view = d.getElementById('vc-view');
 
@@ -258,8 +264,6 @@
 
         // The vc is not visible
         else {
-          if (vc === undefined)
-            vc = _getCurrentVC(vcClass, vcArray);
           view.appendChild(vc.element());
           vcname.classList.add('active');
           show['collection'] = true;
@@ -271,11 +275,6 @@
       // Click, if the VC should be shown
       if (show['collection']) {
         vcclick.apply();
-      }
-
-      // else
-      else if (_checkVCrewrite(vcClass)) {
-        vcchoose.classList.add('rewritten');
       };
     };
 
@@ -324,11 +323,6 @@
         // Store session information
         KorAP.session.set("show", show);
 
-        // Set Virtual collection 
-        if (vc === undefined) {
-          vc = _getCurrentVC(vcClass, vcArray);
-        };
-
         if (vc !== undefined) {
           input.value = vc.toQuery();
         }
@@ -354,27 +348,3 @@
     return obj;
   });
 });
-
-
-// Render Virtual collection
-function _getCurrentVC (vcClass, vcArray) {
-  var vc = vcClass.create(vcArray);
-  try {
-    if (KorAP.koralQuery !== undefined && KorAP.koralQuery["collection"]) {
-      vc.fromJson(KorAP.koralQuery["collection"]);
-    };
-  }
-  catch (e) {
-    KorAP.log(0, e);
-    return;
-  }
-  return vc;
-};
-
-
-function _checkVCrewrite (vcClass) {
-  if (KorAP.koralQuery !== undefined && KorAP.koralQuery["collection"]) {
-    return vcClass.checkRewrite(KorAP.koralQuery["collection"]);
-  };
-  return false;
-}
diff --git a/kalamar.dict b/kalamar.dict
index 6ec2e52..bbe4ed4 100644
--- a/kalamar.dict
+++ b/kalamar.dict
@@ -25,7 +25,8 @@
     logout => 'Abmelden',
     register => 'Registrieren',
     pwdforgotten => 'Password vergessen?',
-    searchjob => '»<%== $q %>« <% if (param("collection-name")) { %>in »<%== param("collection-name") %>« <% } elsif (param("collection")) { %>im definierten Korpus <% } %>mit <%== loc("QL_" . $ql, "unbekannter Anfragesprache") %>',
+    # TODO: use document.write() refering to vc.getName()!
+    searchjob => '»<%== $q %>« <% if (param("collection")) { %>im definierten Korpus <% } %>mit <%== loc("QL_" . $ql, "unbekannter Anfragesprache") %>',
     searchtitle => 'KorAP: Finde <%== loc("searchjob") %>',
     searchplaceholder => 'Finde ...',
     go => 'Los!',
@@ -115,7 +116,8 @@
     register => 'Register',
     pwdforgotten => 'Password forgotten?',
     go => 'Go!',
-    searchjob => '»<%== $q %>« <% if (param("collection-name")) { %>in »<%== param("collection-name") %>« <% } elsif (param("collection")) { %>in the defined corpus <% } %>with <%== loc("QL_". $ql, "unknown query language") %>',
+    # TODO: use document.write() refering to vc.getName()!
+    searchjob => '»<%== $q %>« <% if (param("collection")) { %>in the defined corpus <% } %>with <%== loc("QL_". $ql, "unknown query language") %>',
     searchtitle => 'KorAP: Find <%== loc("searchjob") %>',
     searchplaceholder => 'Find ...',
     in => 'in',
diff --git a/templates/partial/header.html.ep b/templates/partial/header.html.ep
index 8213e0a..349104e 100644
--- a/templates/partial/header.html.ep
+++ b/templates/partial/header.html.ep
@@ -20,7 +20,6 @@
     <div id="vc-view"></div>
     <%= loc 'in' %>
     %# TODO: Create 'align' parameter
-    %= hidden_field 'collection-name' => param('collection-name'), id => 'collection-name' 
     %= text_field 'collection', id => 'collection'
 
     <%= loc 'with' %>