From c31ca3b1293c321d74a5bb2bc349243c1248911f Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Tue, 25 Jul 2023 16:58:35 +0200
Subject: [PATCH] changes to use winbox

---
 .../classes/plugins_renderer.class.php        | 11 ++++++
 public_html/deployment/index.php              | 11 +++---
 public_html/deployment/js/functions.js        | 35 +++++++++++++++++--
 public_html/deployment/main.css               | 15 ++++++++
 4 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/public_html/deployment/classes/plugins_renderer.class.php b/public_html/deployment/classes/plugins_renderer.class.php
index 288452c9..403e48ba 100644
--- a/public_html/deployment/classes/plugins_renderer.class.php
+++ b/public_html/deployment/classes/plugins_renderer.class.php
@@ -100,6 +100,7 @@ class plugin_renderer extends ciplugins {
     }
     public function getHtmlOutwindow(){
         $aConfig=$this->getPluginConfig();
+        /*
         return '<div id="'.$this->getHtmlOutIdWrapper().'" class="cmdoutbox draggable draggable-onpage">'
         // .'<button class="btn-close float-right">X</button>'
         .'<div class="header"><i class="'.$aConfig['icon'].'"></i> '.$this->_sPluginname.'</div>'
@@ -109,6 +110,16 @@ class plugin_renderer extends ciplugins {
             .(isset($aConfig['window-lines']) && $aConfig['window-lines'] ? ' cmd-lines-'.$aConfig['window-lines'] : '' )
             .'"></div>'
         .'</div>';
+        */
+        return '<div id="'.$this->getHtmlOutIdWrapper().'" class="cmdoutbox">'
+        // .'<button class="btn-close float-right">X</button>'
+        .'<div class="header"><i class="'.$aConfig['icon'].'"></i> '.$this->_sPluginname.'</div>'
+        .'<div id="'.$this->getHtmlOutId().'" '
+        .'class="out'
+            .(isset($aConfig['window-cols'])  && $aConfig['window-cols']  ? ' cmd-cols-'.$aConfig['window-cols'] : ''   )
+            .(isset($aConfig['window-lines']) && $aConfig['window-lines'] ? ' cmd-lines-'.$aConfig['window-lines'] : '' )
+            .'"></div>'
+        .'</div>';
     }
 
     // ---------------------------------------------------------------
diff --git a/public_html/deployment/index.php b/public_html/deployment/index.php
index 1ebe3cd4..bc10f128 100644
--- a/public_html/deployment/index.php
+++ b/public_html/deployment/index.php
@@ -85,9 +85,12 @@ $CI_plugins->setType('shellcmd');
 $aEnabledShellPlugins=$CI_plugins->getEnabledPlugins('shellcmd');
 $sHeader.= count($aEnabledShellPlugins) 
     ? '' 
-        ."\n<!-- shellcmd plugins :: js files -->\n"
+        ."\n<!-- for shellcmd plugins -->\n"
         .'<script src="/vendor/axelhahn/js/ubd.class.js"></script>'."\n"
-        .'<script src="/vendor/axelhahn/js/addi.js"></script>'."\n"
+        // .'<script src="/vendor/axelhahn/js/addi.js"></script>'."\n"
+        .'<script src="/vendor/winbox/0.2.82/winbox.min.js"></script>'."\n"
+        .'<link rel="stylesheet" type="text/css" href="/vendor/winbox/0.2.82/winbox.min.css"/>'."\n"
+        ."<!-- shellcmd scripts -->\n"
     : ''
     ;
 foreach ($aEnabledShellPlugins as $sPlugin){
@@ -99,8 +102,8 @@ foreach ($aEnabledShellPlugins as $sPlugin){
             .'<li >'
             .$oHtml->getLink(array(
                 'href'=>'#',
-                // 'onclick'=>'$(\'#'.$CI_plugins->getHtmlOutIdWrapper().'\').slideToggle(100);',
-                'onclick'=>'toggleShellWindow(\''.$CI_plugins->getHtmlOutIdWrapper().'\', this);',
+                // 'onclick'=>'toggleShellWindow(\''.$CI_plugins->getHtmlOutIdWrapper().'\', this);',
+                'onclick'=>'toggleShellWindow(\''.$CI_plugins->getHtmlOutId().'\', this);',
                 'role'=>'button',
                 'aria-expanded'=>'false',
                 'icon'=> (isset($aPluginConfig['icon']) ? $aPluginConfig['icon'] : ''),
diff --git a/public_html/deployment/js/functions.js b/public_html/deployment/js/functions.js
index a653e7bb..5d0ff311 100644
--- a/public_html/deployment/js/functions.js
+++ b/public_html/deployment/js/functions.js
@@ -42,14 +42,43 @@ function hideModalMessage(){
    return false;
 }
 
+
+var aWinBoxes={};
 /**
  * shellcmd plugin ... toggle output window
  * @param {string} idWrapperDiv  id of the wrapper
  * @param {object} oLink         a tag in the navbar with link for toggling window 
  */
 function toggleShellWindow(idWrapperDiv, oLink){
-    $('#'+idWrapperDiv).slideToggle(100);
-    $(oLink).parent().toggleClass('active');
+    if(aWinBoxes[idWrapperDiv]){
+        aWinBoxes[idWrapperDiv].close();
+    } else {
+        var oWrapper=document.getElementById(idWrapperDiv);
+        aWinBoxes[idWrapperDiv] = WinBox({
+            title: oLink.innerText,
+            id: 'winbox-'+idWrapperDiv,
+            border: 5,
+            background: "#628",
+            class: [ "no-min", "no-max", /* "no-full", "no-resize", "no-move"*/ "ciwinbox" ],
+
+            // position:
+            x: "center",
+            y: "center",
+
+            // width: oWrapper.clientWidth+'px',
+
+            mount: oWrapper,
+            
+            onclose: function(){
+                delete aWinBoxes[idWrapperDiv];
+                $(oLink).parent().removeClass('active');
+            }
+        });
+        $(oLink).parent().addClass('active');
+        window.setTimeout("aWinBoxes['"+idWrapperDiv+"'].resize("+(oWrapper.clientWidth+25)+", "+(oWrapper.clientHeight+150)+").move('center', 'center')", 200);
+    }
+    // $('#'+idWrapperDiv).slideToggle(100);
+    // $(oLink).parent().toggleClass('active');
 }
 
 // ----------------------------------------------------------------------
@@ -58,7 +87,7 @@ function toggleShellWindow(idWrapperDiv, oLink){
 
 $(document).ready(function() {
     initSoftscroll();
-    addi.init();
+    // addi.init();
     // $(".optionName").popover({trigger: "hover"});
     // $("#content").hide().fadeIn(300);
 });
diff --git a/public_html/deployment/main.css b/public_html/deployment/main.css
index 3a2fb3dc..3026f0b1 100644
--- a/public_html/deployment/main.css
+++ b/public_html/deployment/main.css
@@ -283,17 +283,32 @@ input[type="radio"]:checked+label, input[type="checkbox"]:checked+label{
 .tab-pane p {margin: 1em 10px;}
 
 /* ----- plugins ----- */
+
+/*
 .draggable-onpage{position: absolute;}
 .draggable-onscreen{position: fixed;}
 .isdragging{opacity: 0.9;}
 
 .cmdoutbox{background: rgba(0,0,0,0.9); color: #f0f0f0; box-shadow: 0.2em 0.2em 0.5em rgba(0,0,0,0.4); display: none;}
 .cmdoutbox .header{background:#628;padding: 0.1em 0.5em;}
+
 .cmdoutbox .out{color:#ccf; ;padding: 0.5em; font-family: monospace; overflow: scroll; white-space: nowrap; }
 .cmdoutbox button.btn-close{background:#e55; color: #fff; border: none;}
 
 .cmdoutbox .bar{background: rgba(255,255,255,0.1);}
 .cmdoutbox .progress{background: #85a;}
+*/
+.ciwinbox .wb-body{
+    background: rgba(0,0,0,0.9) !important; 
+    color: #ccf; 
+    font-family: monospace; 
+    padding: 0.5em;
+    overflow: scroll; 
+    white-space: nowrap; 
+}
+.cmdoutbox{display: none;}
+.ciwinbox .bar{background: rgba(255,255,255,0.1);}
+.ciwinbox .progress{background: #85a;}
 
 .float-right{float: right;}
 
-- 
GitLab