1function lwsgt_get_appropriate_ws_url() 2{ 3 var pcol; 4 var u = document.URL; 5 6 if (u.substring(0, 5) === "https") { 7 pcol = "wss://"; 8 u = u.substr(8); 9 } else { 10 pcol = "ws://"; 11 if (u.substring(0, 4) === "http") 12 u = u.substr(7); 13 } 14 15 return pcol + u; 16} 17 18function lwsgt_app_hdr(j, bc, ws) 19{ 20 var s = "", n, m = 0; 21 22 ws.bcq = 0; 23 24 for (n = 0; n < j.cols.length; n++) 25 if (!j.cols[n].hide) 26 m++; 27 28 s = "<tr><td colspan=\"" + m + "\" class=\"lwsgt_title\">" + 29 ws.lwsgt_title + "</td></tr>"; 30 31 if (!!bc) { 32 s += "<tr><td colspan=\"" + m + "\" class=\"lwsgt_breadcrumbs\">"; 33 for (n = 0; n < bc.length; n++) { 34 s += " / "; 35 if (!bc[n].url && bc[n].url !== "") 36 s += " " + lws_san(bc[n].name) + " "; 37 else { 38 s += "<a href=# id=\"bc_"+ ws.divname + ws.bcq + "\" h=\"" + 39 ws.lwsgt_cb + "\" p=\""+ws.lwsgt_parent+"\" aa=\"="+ 40 lws_san(encodeURI(bc[n].url))+"\" m=\"-1\" n=\"-1\">" + 41 lws_san(bc[n].name) + "</a> "; 42 ws.bcq++; 43 } 44 } 45 s += "</td></tr>"; 46 } 47 s += "<tr>"; 48 for (n = 0; n < j.cols.length; n++) 49 if (!j.cols[n].hide) 50 s = s + "<td class=\"lwsgt_hdr\">" + lws_san(j.cols[n].name) + 51 "</td>"; 52 53 s += "</tr>"; 54 55 return s; 56} 57 58function lwsgt_click_callthru() 59{ 60 window[this.getAttribute("h")](this.getAttribute("p"), this.getAttribute("aa"), this.getAttribute("m"), this.getAttribute("n")); 61 event.preventDefault(); 62} 63 64function lwsgt_initial(title, pcol, divname, cb, gname) 65{ 66 this.divname = divname; 67 68 lws_gray_out(true,{"zindex":"499"}); 69 70 this.lwsgt_ws = new WebSocket(lwsgt_get_appropriate_ws_url(), pcol); 71 this.lwsgt_ws.divname = divname; 72 this.lwsgt_ws.lwsgt_cb = cb; 73 this.lwsgt_ws.lwsgt_parent = gname; 74 this.lwsgt_ws.lwsgt_title = title; 75 try { 76 this.lwsgt_ws.onopen = function() { 77 lws_gray_out(false); 78 // document.getElementById("debug").textContent = 79 // "ws opened " + lwsgt_get_appropriate_ws_url(); 80 }; 81 this.lwsgt_ws.onmessage = function got_packet(msg) { 82 var s, m, n, j = JSON.parse(msg.data); 83 document.getElementById("debug").textContent = msg.data; 84 if (j.cols) { 85 this.hdr = j; 86 } 87 if (j.breadcrumbs) 88 this.breadcrumbs = j.breadcrumbs; 89 90 if (j.data) { 91 var q = 0; 92 s = "<table class=\"lwsgt_table\">" + 93 lwsgt_app_hdr(this.hdr, this.breadcrumbs, this); 94 for (m = 0; m < j.data.length; m++) { 95 s = s + "<tr class=\"lwsgt_tr\">"; 96 for (n = 0; n < this.hdr.cols.length; n++) { 97 if (!this.hdr.cols[n].hide) { 98 if (!this.hdr.cols[n].align) 99 s = s + "<td class=\"lwsgt_td\">"; 100 else 101 s = s + "<td class=\"lwsgt_td\" style=\"text-align: right\">"; 102 103 if (this.hdr.cols[n].href && 104 !!j.data[m][this.hdr.cols[n].href]) { 105 s = s + "<a href=# id=\""+ this.divname + q + "\" h=\"" + this.lwsgt_cb + "\" p=\""+this.lwsgt_parent+"\" aa=\""+ 106 lws_san(encodeURI(j.data[m][this.hdr.cols[n].href]))+"\" m=\""+m+"\" n=\""+n+"\">" + 107 lws_san(j.data[m][this.hdr.cols[n].name]) + 108 "</a>"; 109 q++; 110 } 111 else 112 s = s + lws_san(j.data[m][this.hdr.cols[n].name]); 113 114 s = s + "</td>"; 115 } 116 } 117 118 s = s + "</tr>"; 119 } 120 s = s + "</table>"; 121 document.getElementById(this.divname).innerHTML = s; 122 for (n = 0; n < q; n++) 123 document.getElementById(this.divname + n).onclick = 124 lwsgt_click_callthru; 125 126 for (n = 0; n < this.bcq; n++) 127 document.getElementById("bc_" + this.divname + n).onclick = 128 lwsgt_click_callthru; 129 130 } 131 }; 132 this.lwsgt_ws.onclose = function(){ 133 lws_gray_out(true,{"zindex":"499"}); 134 }; 135 } catch(exception) { 136 alert("<p>Error" + exception); 137 } 138} 139 140