Added pipe demo and make sendMsg() puplic in plugin client library

Change-Id: I38ee2d8cec2804d0c13abf97455ccc78411df5ed
diff --git a/dev/demo/plugin-client.html b/dev/demo/plugin-client.html
index b0b477d..0250c6c 100644
--- a/dev/demo/plugin-client.html
+++ b/dev/demo/plugin-client.html
@@ -35,13 +35,27 @@
 
       function pluginit (p) {
         p.onMessage = function(msg) {
-          console.log("State changed to", msg.key, msg.value);
+          switch (msg.key) {
+            // console.log("State changed to", msg.key, msg.value);
+            case 'glemm':
+              let data = {
+                'action' : 'pipe',
+                'service' : 'http://glemm/'
+              };
+                   
+              if (!msg.value) {
+                data['job'] = 'del';
+              };
+              KorAPlugin.sendMsg(data);
+              break;
+          }
         };
       };
       </script>
     <ul>
       <li><a onclick="KorAPlugin.log(333, 'Huhu!')">Send log!</a></li>
       <li><a onclick="KorAPlugin.resize()">Resize</a></li>
+      <li><a onclick="KorAPlugin.sendMsg({'action':'pipe','service':'Glemm'})">Add Glemm</a></li>
       <li><a onclick="flood()">Flood!</a></li>
     </ul>
     <p style="width: 2000px">------------------------------------------------------------------------------------------------------------------------</p>
diff --git a/dev/demo/plugin-server.html b/dev/demo/plugin-server.html
index 146d2eb..98cbac0 100644
--- a/dev/demo/plugin-server.html
+++ b/dev/demo/plugin-server.html
@@ -14,8 +14,13 @@
     //]]></script>  
     <script data-main="plugin-serverdemo.js" src="../js/lib/require.js" async="async"></script>
   </head>
-  <body>
+  <body>    
     <p>Start the demo server with <code>morbo -l 'http://*:3003' t/server/plugin.pl</code> and open <a href="http://localhost:3003/demo/plugin-server.html"><code>this website</code></a>.</p>
+
+    <header>
+      <form id="searchform" autocomplete="off" action="/kalamar"></form>
+    </header>
+    
     <main> 
         <script>
         KorAP.koralQuery = {
diff --git a/dev/demo/plugin-serverdemo.js b/dev/demo/plugin-serverdemo.js
index eb91f14..096050f 100644
--- a/dev/demo/plugin-serverdemo.js
+++ b/dev/demo/plugin-serverdemo.js
@@ -8,14 +8,18 @@
 
 
 
-define(['app/en','match', 'panel/match', 'panel/result', 'plugin/server','lib/domReady','init'], function (lang, matchClass, matchPanelClass, resultPanelClass, pluginClass, domReady) {
+define(['app/en','match', 'panel/match', 'panel/result', 'plugin/server','pipe','lib/domReady','init'], function (lang, matchClass, matchPanelClass, resultPanelClass, pluginClass, pipeClass, domReady) {
   domReady(function () {
  
-    //Load Plugin Server first 
+    // Load Plugin Server first 
     KorAP.Plugin = pluginClass.create();
 
     // Add services container to head
     document.head.appendChild(KorAP.Plugin.element());
+
+    // Add pipe form
+    KorAP.Pipe = pipeClass.create();
+    document.getElementById("searchform").appendChild(KorAP.Pipe.element());
     
     //Register result plugin
     KorAP.Plugin.register({
diff --git a/dev/js/src/plugin/client.js b/dev/js/src/plugin/client.js
index 8c73625..389d093 100644
--- a/dev/js/src/plugin/client.js
+++ b/dev/js/src/plugin/client.js
@@ -52,7 +52,7 @@
     },
 
     // Send a message
-    _sendMsg : function (data) {
+    sendMsg : function (data) {
       data["originID"] = this.widgetID;
       window.parent.postMessage(data, this.server);
     },
@@ -79,7 +79,7 @@
      * Send a log message to the embedding KorAP
      */
     log : function (code, msg) {
-      this._sendMsg({
+      this.sendMsg({
         action : 'log',
         code : code,
         msg : msg
@@ -98,7 +98,7 @@
       if (de.scrollWidth > de.clientWidth) {
         height += 14;
       };
-      this._sendMsg({
+      this.sendMsg({
         'action' : 'resize',
         'height' : height
       });
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index 1c46dbe..d5c9cfb 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -393,6 +393,17 @@
       case 'log':
         KorAP.log(d.code, d.msg,  service.src);
         break;
+
+      // Modify pipes
+      case 'pipe':
+        if (KorAP.Pipe != undefined) {
+          if (d.job == 'del') {
+            KorAP.Pipe.remove(d.service);
+          } else {
+            KorAP.Pipe.append(d.service);
+          };
+        };
+        break;
       };
 
       // TODO: