Modernize view scripts and improve specifications

Change-Id: Ie45465c8c29aef272c719942290f4ab0c9dc8550
diff --git a/dev/js/src/view.js b/dev/js/src/view.js
index 27d1ab2..77f8d60 100644
--- a/dev/js/src/view.js
+++ b/dev/js/src/view.js
@@ -3,6 +3,8 @@
  * like a tree view or the metadata view.
  */
 
+"use strict";
+
 define(['buttongroup', 'util'], function (buttonGroupClass) {
 
   const loc = KorAP.Locale;
@@ -20,7 +22,7 @@
       this._shown = false;
 
       // The buttonclass is bind to the view
-      var c = ['action', 'button-view'];
+      const c = ['action', 'button-view'];
       if (classes)
         c.push.apply(c,classes);
       
@@ -36,6 +38,7 @@
       return this;
     },
 
+
     /**
      * Element of the view
      */
@@ -46,30 +49,28 @@
       };
 
       // Create panel element
-      var e = document.createElement('div');
+      const e = document.createElement('div');
+      const cl = e.classList;
 
-      var cl = e.classList;
       cl.add('view', 'show');
       if (this._classes)
         cl.add.apply(cl, this._classes);
 
       // TODO: The show may need to be wrapped in another DIV!
       if (this.show !== undefined) {
-        let s = this.show();
+        const s = this.show();
         if (s) {
           e.appendChild(s);
         } else {
           return e
-        }
+        };
       }
 
       this._shown = true;
 
       e.appendChild(this.actions.element());
 
-      this._element = e;
-
-      return e;
+      return this._element = e;
     },
 
 
@@ -90,8 +91,10 @@
       }
     },
 
+
     // onClose : function () {},
 
+    
     /**
      * Close the view.
      */
@@ -101,7 +104,7 @@
       if (this.onClose)
         this.onClose();
 
-      var e = this.element();
+      const e = this.element();
       if (e.parentNode) {
         e.parentNode.removeChild(e);
       };
@@ -109,6 +112,7 @@
       this._shown = false;
     },
 
+
     /**
      * Upgrade this object to another object,
      * while private data stays intact.
@@ -116,7 +120,7 @@
      * @param {Object] An object with properties.
      */
     upgradeTo : function (props) {
-      for (var prop in props) {
+      for (let prop in props) {
         this[prop] = props[prop];
       };
       return this;
diff --git a/dev/js/src/view/match/meta.js b/dev/js/src/view/match/meta.js
index f54c7fb..406c10a 100644
--- a/dev/js/src/view/match/meta.js
+++ b/dev/js/src/view/match/meta.js
@@ -1,3 +1,5 @@
+"use strict";
+
 define([
   'view',
   'match/meta'
@@ -7,7 +9,10 @@
   
   return {
     create : function (match) {
-      return Object.create(viewClass)._init(['metatable']).upgradeTo(this)._init(match);
+      return Object.create(viewClass)
+        ._init(['metatable'])
+        .upgradeTo(this)
+        ._init(match);
     },
 
 
@@ -24,26 +29,24 @@
       if (this._show)
         return this._show;
 
-      var metaTable = document.createElement('div');
+      const metaTable = document.createElement('div');
       metaTable.classList.add('metatable', 'loading');
 
       this.getData(function (meta) {
-
         if (meta === null)
           return;
 
         // Load data
         metaTable.classList.remove('loading');
-
         metaTable.appendChild(meta.element());
       });
 
+
       // TODO:
       //   Loading should have a timeout on view-level
       //   matchtable.classList.remove('loading');
 
-      this._show = metaTable;
-      return metaTable;
+      return this._show = metaTable;
     },
 
 
@@ -61,7 +64,7 @@
      */
     getData : function (cb) {
 
-      var match = this._match;
+      const match = this._match;
       try {
         KorAP.API.getTextInfo(
           match, {}, function (textResponse) {
@@ -71,14 +74,13 @@
               return;
             };
 
-            var doc = textResponse["document"];
-       
+            const doc = textResponse["document"];
             if (doc === undefined) {
               cb(null);
               return;
             };
 
-            var fields = doc["fields"];
+            const fields = doc["fields"];
             if (fields === undefined) {
               cb(null);
               return;
@@ -97,6 +99,7 @@
       };
     },
 
+
     // Delete circular references
     onClose : function () {
       this._match = undefined;
diff --git a/dev/js/src/view/match/relations.js b/dev/js/src/view/match/relations.js
index c61a4ff..1c9bdad 100644
--- a/dev/js/src/view/match/relations.js
+++ b/dev/js/src/view/match/relations.js
@@ -11,7 +11,10 @@
   
   return {
     create : function (match,foundry,layer,type) {
-      return Object.create(viewClass)._init(['relations']).upgradeTo(this)._init(match, foundry, layer, type);
+      return Object.create(viewClass)
+        ._init(['relations'])
+        .upgradeTo(this)
+        ._init(match, foundry, layer, type);
     },
 
 
@@ -33,20 +36,17 @@
       if (this._show)
         return this._show;
 
-      var matchtree = d.createElement('div');
+      const matchtree = d.createElement('div');
       matchtree.classList.add('matchtree', 'loading');
 
-      // this.element().appendChild(matchtree);
-
       // Add title line
-      var h6 = matchtree.addE('h6');
+      const h6 = matchtree.addE('h6');
       h6.addE('span').addT(this._foundry);
       h6.addE('span').addT(this._layer);      
 
       this._tree = matchtree.addE('div');
 
-      this._show = matchtree;
-      return matchtree;
+      return this._show = matchtree;
     },
 
 
@@ -55,13 +55,13 @@
      */
     afterEmbed : function () {
 
-      var foundry = this._foundry,
-          layer = this._layer,
-          type = this._type;
+      const foundry = this._foundry,
+            layer = this._layer,
+            type = this._type;
 
-      var that = this;
-      var tree = this._tree;
-      var matchtree = this._show;
+      const that = this,
+            tree = this._tree,
+            matchtree = this._show;
 
       // Get tree data async
       this.getData(foundry, layer, type, function (treeObj) {
@@ -85,21 +85,20 @@
           if (type === "spans") {
 
             // Download link
-            that.actions.add(loc.DOWNLOAD, {'cls':['button-icon','download']}, function (e) {
-              var a = treeObj.downloadLink();
-              d.body.appendChild(a);
-              a.click();
-              d.body.removeChild(a)
-            });
+            that.actions.add(
+              loc.DOWNLOAD,
+              {'cls':['button-icon','download']},
+              function (e) {
+                const a = treeObj.downloadLink();
+                d.body.appendChild(a);
+                a.click();
+                d.body.removeChild(a)
+              }
+            );
           };
           
           treeObj.center();
         };
-  
-        /*
-          if (cb)
-          cb(treeObj);
-          */
       });
 
       matchtree.classList.remove('loading');
@@ -163,6 +162,7 @@
       };
     },
   
+
     // Delete circular references
     onClose : function () {
       this._match = undefined;
diff --git a/dev/js/src/view/match/tokentable.js b/dev/js/src/view/match/tokentable.js
index e954068..e06ec52 100644
--- a/dev/js/src/view/match/tokentable.js
+++ b/dev/js/src/view/match/tokentable.js
@@ -1,3 +1,5 @@
+"use strict";
+
 define([
   'view',
   'match/table',
@@ -8,7 +10,10 @@
   
   return {
     create : function (match) {
-      return Object.create(viewClass)._init(['tokentable']).upgradeTo(this)._init(match);
+      return Object.create(viewClass)
+        ._init(['tokentable'])
+        .upgradeTo(this)
+        ._init(match);
     },
 
 
@@ -17,6 +22,7 @@
       return this;
     },
     
+
     /**
      * TokenTable view element
      */
@@ -25,12 +31,13 @@
         return this._show;
 
       // Append default table
-      var matchtable = d.createElement('div');
+      const matchtable = d.createElement('div');
       matchtable.classList.add('matchtable', 'loading');
       this._show = matchtable;
       return matchtable;
     },
 
+
     /**
      * Do after embedding
      */
@@ -43,7 +50,7 @@
       //   matchtable.classList.remove('loading');
 
       // var that = this;
-      var matchtable = this._show;
+      const matchtable = this._show;
 
       // Create the table asynchronous
       this.getData(undefined, function (table) {
@@ -52,7 +59,6 @@
           matchtable.appendChild(table.element());
           table.toMark();
 	      };
-
       });
 
       // Load data
@@ -73,12 +79,12 @@
      * representation
      */
     getData : function (tokens, cb) {
-      var focus = [];
+      let focus = [];
 
       // Get all tokens
       if (tokens === undefined) {
         focus = this._match.getTokens();
-      } 
+      }
 
       // Get only some tokens
       else {
@@ -87,7 +93,7 @@
         tokens.forEach(function(term) {
           try {
             // Create info layer objects
-            var layer = infoLayerClass.create(term);
+            const layer = infoLayerClass.create(term);
             layer.type = "tokens";
             focus.push(layer);
           }
@@ -115,8 +121,9 @@
 
             // Get snippet from match info
             if (matchResponse["snippet"] !== undefined) {
-              this._table = matchTableClass.create(matchResponse["snippet"]);
-              cb(this._table);
+              cb(
+                this._table = matchTableClass.create(matchResponse["snippet"])
+              );
             };
           }.bind(this)
         );
@@ -132,6 +139,7 @@
       */
     },
 
+
     // Delete circular references
     onClose : function () {
       this._match = undefined;
diff --git a/dev/js/src/view/result/koralquery.js b/dev/js/src/view/result/koralquery.js
index c456eee..74aec5a 100644
--- a/dev/js/src/view/result/koralquery.js
+++ b/dev/js/src/view/result/koralquery.js
@@ -1,10 +1,14 @@
+"use strict";
+
 define([
   'view',
   'lib/highlight/highlight.pack',
 ], function (viewClass) {
   return {
     create : function (classes) {
-      return Object.create(viewClass)._init(classes).upgradeTo(this);
+      return Object.create(viewClass)
+        ._init(classes)
+        .upgradeTo(this);
     },
 
     /**
@@ -14,10 +18,10 @@
       if (this._show)
         return this._show;
 
-      var kq = document.createElement('div');
+      const kq = document.createElement('div');
       kq.setAttribute('id', 'koralquery');
 
-      var kqInner = kq.addE('div');
+      const kqInner = kq.addE('div');
 
       kqInner.addT(
         JSON.stringify(KorAP.koralQuery || {}, null, '  ')
diff --git a/dev/js/src/view/vc/corpstatv.js b/dev/js/src/view/vc/corpstatv.js
index 316018f..e4aacb0 100644
--- a/dev/js/src/view/vc/corpstatv.js
+++ b/dev/js/src/view/vc/corpstatv.js
@@ -4,7 +4,7 @@
  * @author Helge Stallkamp
  */
 
-define([ 'view', 'vc/statistic', 'buttongroup' ], function(viewClass, statClass, buttonGroup) {
+define([ 'view', 'vc/statistic', 'buttongroup' ], function (viewClass, statClass, buttonGroup) {
 
   // Localization values
   const loc   = KorAP.Locale;
@@ -38,7 +38,7 @@
      */
     getStatistic : function(cb) {
       // cq = corpusQuery
-      var vc = this.vc;
+      const vc = this.vc;
 
       try {
         KorAP.API.getCorpStat(vc.toQuery(), function(statResponse) {
@@ -79,15 +79,13 @@
       if (this._show)
         return this._show; 
       
-      var statTable = document.createElement('div');
+      const statTable = document.createElement('div');
       statTable.classList.add('stattable', 'loading');
   
-      var that = this;
-     
       /*
-      * Get corpus statistic, remove "loading"-image and
-      * append result to statTable
-      */
+       * Get corpus statistic, remove "loading"-image and
+       * append result to statTable
+       */
       this.getStatistic(function(statistic) {
         statTable.classList.remove('loading');
 
@@ -96,57 +94,53 @@
 
         statisticobj = statClass.create(statistic);
         statTable.appendChild(statisticobj.element());
-    
       });
 
-      this._show = statTable;
-      return statTable;
-
+      return this._show = statTable;
     },
-    
 
     
     /**
      * Checks if statistic has to be disabled
      */
-    checkStatActive : 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)
-      */
+    checkStatActive : function () {
+      let newString = KorAP.vc.toQuery();
+      const 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 || newString === ''){
-       if(newString.startsWith('(')){
-         newString = newString.slice(1, newString.length-1);
-       }
+      if (newString || newString === '') {
+        if (newString.startsWith('(')) {
+          newString = newString.slice(1, newString.length-1);
+        };
        
-       if(newString != oldString) {
-        this.disableStat();
-      }  
-     }
-     
-   },
+        if (newString != oldString) {
+          this.disableStat();
+        }
+      }
+    },
    
+
     /**
      * Disabling 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.
      */   
-
     disableStat : function(){
-      var statt = this._show;
+      const statt = this._show;
   
       if (statt.getElementsByClassName('reloadStatB').length == 0) {
-        let btg = buttonGroup.create(['reloadStatB', 'button-panel']);
-        var that = this;
+        const btg = buttonGroup.create(['reloadStatB', 'button-panel']);
+
         btg.add(loc.REFRESH, {'cls':['refresh', 'button-icon']}, function (e) {
           statt.classList.remove('stdisabled');
-          that.panel.reloadCorpStat(); 
-        });
+          this.panel.reloadCorpStat(); 
+        }.bind(this));
+
         statt.appendChild(btg.element());
         statt.classList.add('stdisabled');
       };