/*
 Eloquence WEBDLG v2
 (C) Copyright Marxmeier Software AG, 2020-2025
 Version: 2.0.20
 $Id: 00-base.js,v 28.146 2025/07/09 09:18:17 mike Exp $
 $Id: 10-status.js,v 28.1 2022/06/29 15:39:01 mike Exp $
*/
var eq=eq||{};eq.c=eq.c||{};eq.p=eq.p||{};eq.p.version=20020;eq.c.Obj=function(){};(eq.c.Obj.setClassName=function(b,a){var c=Object.getOwnPropertyDescriptor(a.prototype.constructor,"name");void 0!==c?c.value=b:c={value:b,configurable:!0,enumerable:!1,writable:!1};Object.defineProperty(a.prototype.constructor,"name",c)})("Obj",eq.c.Obj);
eq.c.Obj.subClass=function(b,a){var c=this;a.prototype=Object.create(c.prototype);Object.defineProperty(a.prototype,"constructor",{value:a,configurable:!1,enumerable:!1,writable:!0});eq.c.Obj.setClassName(b,a);a.subClass=function(d,f){return c.subClass.call(this,d,f)};return eq.c[b]=a};
eq.xhr={get:function(b,a){var c=eq.xhr;if(void 0===c.base){var d=/^([^?#]+)/.exec(window.location.href)[1];c.base=d+(/\/$/.test(d)?"api/":"/api/")}d=new XMLHttpRequest;d.onload=function(){try{var f=JSON.parse(this.responseText)}catch(e){throw Error("Failed to load '"+c.base+a+"' ("+this.responseText.trim()+")");}b.update(f)};d.open("GET",c.base+a);d.responseType="text";d.send()},refresh:function(b,a){var c=eq.xhr;c.refreshTimer.forEach(c.cancelRefresh,b);c.refreshTimer.set(window.setInterval(c.onRefresh,
1E3*a,b),b)},refreshTimer:new Map,onRefresh:function(b){b.get()},cancelRefresh:function(b,a){this&&this===b&&(window.clearInterval(a),eq.xhr.refreshTimer.delete(a))}};
eq.yesno={open:function(b,a,c,d,f){var e=eq.yesno;e.close();e.self=c;e.cb=d;e.arg=f;c=document.createElement("DIV");c.className="eq-yesno";d=document.createElement("SPAN");d.textContent=a;c.appendChild(d);d=document.createElement("BUTTON");d.type="button";d.className="eq-yes";d.textContent="Yes";d.onclick=e.close;c.appendChild(d);d=document.createElement("BUTTON");d.type="button";d.className="eq-no";d.textContent="No";d.onclick=e.close;c.appendChild(d);c.appendChild(document.createElement("I"));window.addEventListener("mousedown",
e.close);b.appendChild(c)},close:function(b){var a=eq.yesno;if(b){b.preventDefault();b.stopImmediatePropagation();b=b.target;for(var c;b&&b!==document;){if(c=b.classList){if(c.contains("eq-yes")){a.cb(a.self,a.arg);break}if(c.contains("eq-no"))break;if(c.contains("eq-yesno"))return}b=b.parentNode}}a.self=void 0;a.cb=void 0;a.arg=void 0;b=document.getElementsByClassName("eq-yesno");c=0;for(var d=b.length;c<d;c++){var f=b[c];f.parentNode.removeChild(f)}window.removeEventListener("mousedown",a.close)}};
eq.c.Obj.subClass("StatusElement",function(b){eq.c.Obj.call(this);this.uri=b});eq.c.StatusElement.prototype.get=function(){eq.xhr.get(this,this.uri)};eq.c.StatusElement.subClass("StatusList",function(b,a,c){eq.c.StatusElement.call(this,a);this.id=b;a=document.createElement("TABLE");a.id=b;a.classList.add("eq-list");(c||document.body).appendChild(a);eq.c.StatusList.map.set(b,this);this.get()});delete eq.c.StatusList.subClass;eq.c.StatusList.map=new Map;
eq.c.StatusList.prototype.get=function(){eq.xhr.get(this,this.uri)};
eq.c.StatusList.prototype.update=function(b){var a=document.getElementById(this.id),c=a.firstElementChild;c||(c=document.createElement("TBODY"),a.appendChild(c));a=0;for(var d=b.length;a<d;a++){var f=b[a],e=document.getElementById(f.id);if(e){var n=e.firstElementChild;var l=n.nextSibling}else e=document.createElement("TR"),e.id=f.id,n=document.createElement("TD"),n.className="eq-label",l=document.createElement("TD"),l.className="eq-val",e.appendChild(n),e.appendChild(l),c.appendChild(e);n.textContent=
f.label+":";l.textContent="";e=document.createElement("SPAN");e.className="eq-val";e.textContent=f.value;l.appendChild(e);if(f=f.attr){n=0;for(var k=f.length;n<k;n++){var g=f[n];g.label&&(e=document.createElement("SPAN"),g.value||(e.id=g.id),e.className="eq-label",e.textContent=g.label,l.appendChild(e));g.value&&(e=document.createElement("SPAN"),e.id=g.id,e.className="eq-val",e.textContent=g.value,l.appendChild(e))}}}};
eq.c.StatusElement.subClass("StatusTable",function(b,a,c,d,f,e){eq.c.StatusElement.call(this,c);this.id=a;this.fld=d;b&&(c=document.createElement("DIV"),c.className="eq-title",c.textContent=b+":",(e||document.body).appendChild(c));b=document.createElement("TABLE");b.id=a;f&&(b.className=f);b.classList.add("eq-table");(e||document.body).appendChild(b);eq.c.StatusTable.map.set(a,this);this.get()});delete eq.c.StatusTable.subClass;eq.c.StatusTable.map=new Map;
eq.c.StatusTable.prototype.setActionHandler=function(b,a){var c=document.getElementById(this.id);b?(this.actionHandler={cb:b,icon:a},c.classList.add("eq-action")):(this.actionHandler=void 0,c.classList.remove("eq-action"))};eq.c.StatusTable.prototype.get=function(b,a){void 0===a&&(a=this.order());var c=this.uri;b&&(c+="?"+b);a&&(c+=(b?"&":"?")+"order="+a);eq.xhr.get(this,c)};
eq.c.StatusTable.prototype.update=function(b){for(var a=document.getElementById(this.id),c=a.getElementsByTagName("BUTTON"),d=0,f=c.length;d<f;d++){var e=c[d];e.disabled=!1;e.parentNode.classList.remove("eq-active")}c=eq.c.StatusTable;var n=this.fld,l=n.length,k=a.firstElementChild;if(k)var g=k.nextElementSibling;else{k=document.createElement("THEAD");k.className="eq-label";a.appendChild(k);d=document.createElement("TR");g=document.createElement("TH");e=document.createElement("BUTTON");e.type="button";
e.className="eq-icon-reload";e.onclick=c.reload;g.appendChild(e);d.appendChild(g);k.appendChild(d);for(var m=0;m<l;m++){var h=n[m];h.d||(g=document.createElement("TH"),e=document.createElement("SPAN"),e.textContent=h.l,g.onclick=c.sort,g.appendChild(e),d.appendChild(g))}g=document.createElement("TBODY");a.appendChild(g)}a=g.children;var u=a.length/2;d=0;for(f=b.length;d<f;d++){var v=b[d];if(d<u){var q=a[2*d];var w=q.childElementCount}else q=document.createElement("TR"),g.appendChild(q),w=0;var r=
0;for(m=0;m<l;m++){if(0===r){if(0===w){var p=document.createElement("TD");if(h=this.actionHandler)e=document.createElement("BUTTON"),e.type="button",e.className=h.icon,e.onclick=c.onAction,p.appendChild(e);q.appendChild(p)}r++}h=n[m];if(!h.d){r<w?p=q.children[r]:(p=document.createElement("TD"),q.appendChild(p));if(1===r){e=p.firstElementChild;var t;e||(e=document.createElement("SPAN"),p.appendChild(e));e.className="eq-line-id";e.textContent!==(t=v[h.f])&&(e.textContent=t,q.classList.remove("eq-open"));
p.className="eq-click";p.onclick=c.detailOpenClose}else if(p.textContent=v[h.f],h=h.c)p.className=h;r++}}d<u?(m=a[2*d+1],m.textContent=""):(m=document.createElement("TR"),m.className="eq-detail",g.appendChild(m));m.appendChild(document.createElement("TD"));p=document.createElement("TD");p.onclick=c.detailOpenClose;m.appendChild(p);p=document.createElement("TD");m.appendChild(p);p.colSpan=q.childElementCount-1;for(m=r=0;m<l;m++)if(h=n[m],h.d&&(t=v[h.f])){q=document.createElement("DIV");p.appendChild(q);
e=document.createElement("SPAN");e.className="eq-label";e.textContent=h.l+":";q.appendChild(e);e=document.createElement("SPAN");e.textContent=t;q.appendChild(e);if(h=h.c)e.className=h;r++}}for(f*=2;a.length>f;)g.removeChild(g.lastElementChild);if(b.length)for(a=k.firstElementChild.children,d=0,f=a.length;d<f;d++){g=a[d];if(b=g.style.width)break;b=Number(b.replace(/px$/,""));t=Math.ceil(100*g.getBoundingClientRect().width)/100;if(isNaN(b)||t>b)g.style.width=t+"px"}};
eq.c.StatusTable.prototype.order=function(){var b=this.fld,a=b.length,c=document.getElementById(this.id).firstElementChild,d="";if(c&&(c=c.firstElementChild)){var f=c.children;c=1;for(var e=0,n=f.length;c<n;c++){for(var l,k=f[c].classList;e<a&&(l=b[e]).d;)e++;if(e++===a)break;if(k.contains("eq-dn"))a=":d";else if(k.contains("eq-up"))a="";else continue;d=l.f+a;1!==c&&(d+=","+b[0].f);break}}return d};
eq.c.StatusTable.reload=function(b){for(var a=b.target;a&&a!==document&&"TABLE"!==a.tagName;)a=a.parentNode;if(a){var c=eq.c.StatusTable.map.get(a.id);if(!c)throw Error("StatusTable: unknown instance");a=a.getElementsByTagName("BUTTON");for(var d=0,f=a.length;d<f;d++){var e=a[d];e.disabled=!0;e===b.target&&e.parentNode.classList.add("eq-active")}c.get()}};
eq.c.StatusTable.sort=function(b){for(var a=b.target;a&&a!==document&&"TH"!==a.tagName;)a=a.parentNode;if(a){for(var c=eq.c.StatusTable,d=a,f;(d=d.parentNode)&&d!==document;)if("TABLE"===d.tagName){f=c.map.get(d.id);break}if(!f)throw Error("StatusTable: unknown instance");d=f.fld;for(var e=d.length,n=a.parentNode.children,l="",k,g=1,m=n.length;g<m;g++){var h=n[g];k=h.classList;if(a===h){for(var u=h=0;u<e;u++){var v=d[u];if(!v.d){if(h===g-1){l=v.f;break}h++}}k.contains("eq-up")?(k.remove("eq-up"),
k.add("eq-dn"),l+=":d"):k.contains("eq-dn")?(k.remove("eq-dn"),l=""):k.add("eq-up");l&&1!==g&&(l+=","+d[0].f)}else k.remove("eq-up"),k.remove("eq-dn")}c.detailCloseAll(b);f.get(null,l)}};
eq.c.StatusTable.onAction=function(b){for(var a=b.target;a&&a!==document&&"TD"!==a.tagName;)a=a.parentNode;if(a){for(var c=eq.c.StatusTable,d=a,f;(d=d.parentNode)&&d!==document;)if("TABLE"===d.tagName){f=c.map.get(d.id);break}if(!f)throw Error("StatusTable: unknown instance");if(!(c=f.actionHandler))throw Error("StatusTable: no action handler");a=a.parentNode.querySelector(".eq-line-id").textContent;c.cb(f,a,b)}};
eq.c.StatusTable.detailOpenClose=function(b){for(var a=b.target;a&&a!=document&&"TR"!=a.tagName;)a=a.parentNode;if(a){var c=a.classList;c.contains("eq-detail")&&(c=(a=a.previousElementSibling).classList);b.shiftKey||eq.c.StatusTable.detailCloseAll(b,a);c.contains("eq-open")?c.remove("eq-open"):c.add("eq-open")}};
eq.c.StatusTable.detailCloseAll=function(b,a){for(b=b.target;b&&b!==document&&"TABLE"!==b.tagName;)b=b.parentNode;if(b){if(!eq.c.StatusTable.map.get(b.id))throw Error("StatusTable: unknown instance");if(b=b.lastElementChild){b=b.children;for(var c=0,d=b.length;c<d;c++){var f=b[c];f!==a&&f.classList.remove("eq-open")}}}};
window.onload=function(){var b=document.getElementById("eq-page");eq.xhr.refresh(new eq.c.StatusList("eq-stats","statistics",b),10);b=new eq.c.StatusTable("Active sessions","eq-sessions","sessions",[{l:"ID",f:"id"},{l:"Application",f:"app"},{l:"Login",f:"login"},{l:"User address",f:"peer_ws",c:"eq-mono"},{l:"DLG address",f:"peer_dlg",c:"eq-mono"},{l:"Connected",f:"connected",c:"eq-mono",d:!0},{l:"Online",f:"online",c:"eq-mono"},{l:"Idle",f:"idle",c:"eq-mono"},{l:"Dialog",f:"dialog",c:"eq-mono",d:!0},
{l:"User-agent",f:"user_agent",c:"eq-mono",d:!0}],"eq-sort eq-detail",b);b.kill=function(a,c,d){void 0!==d?eq.yesno.open(d.target,"Terminate session #"+c+"?",a,a.kill,c):a.get("kill="+c)};b.setActionHandler(b.kill,"eq-icon-kill")};
//# sourceMappingURL=eq-webdlg-status.src.map
