source: trunk/FACT++/www/index.js@ 13672

Last change on this file since 13672 was 13665, checked in by tbretz, 13 years ago
Added sendCommand; fixed a problem with the debug line.
File size: 36.6 KB
Line 
1var debug = false;
2
3var map = [ 393, 390, 391, 394, 1098, 395, 392, 389, 387, 388, 386,
41001, 1004, 1099, 1101, 1100, 1111, 1108, 286, 283, 377, 375, 376, 383,
5384, 999, 1002, 1005, 1007, 1102, 1104, 1103, 1114, 1113, 1110, 1107,
6285, 282, 280, 374, 372, 373, 380, 381, 382, 385, 1000, 1003, 1006,
7990, 992, 1105, 1089, 1106, 1126, 1125, 1115, 1112, 1109, 287, 284,
8281, 279, 277, 371, 369, 370, 413, 378, 379, 422, 425, 428, 431, 983,
9986, 991, 993, 995, 1090, 1092, 1091, 1129, 1128, 1127, 1138, 1135,
101150, 1147, 1144, 259, 256, 278, 276, 274, 368, 366, 367, 410, 411,
11412, 419, 420, 423, 426, 429, 981, 984, 987, 989, 994, 996, 998, 1093,
121095, 1094, 1132, 1131, 1130, 1141, 1140, 1137, 1134, 1149, 1146, 1143,
13258, 255, 253, 275, 273, 271, 365, 363, 364, 407, 408, 409, 416, 417,
14418, 421, 424, 427, 430, 982, 985, 988, 972, 974, 997, 1035, 1037,
151096, 1080, 1097, 1117, 1116, 1133, 1234, 1233, 1142, 1139, 1136, 1151,
161148, 1145, 260, 257, 254, 252, 268, 272, 270, 322, 362, 360, 361, 404,
17405, 406, 521, 414, 415, 512, 533, 536, 539, 920, 923, 926, 911, 914,
18973, 975, 977, 1036, 1038, 1040, 1081, 1083, 1082, 1120, 1119, 1118,
191237, 1236, 1235, 1228, 1225, 1258, 1255, 1252, 205, 202, 199, 196,
20193, 269, 267, 265, 323, 321, 319, 359, 357, 358, 401, 402, 403, 518,
21519, 520, 509, 510, 531, 534, 537, 918, 921, 924, 909, 912, 915, 917,
22976, 978, 980, 1039, 1041, 1043, 1084, 1086, 1085, 1123, 1122, 1121,
231240, 1239, 1238, 1231, 1230, 1227, 1224, 1257, 1254, 1251, 204, 201,
24198, 195, 192, 190, 266, 264, 262, 320, 318, 316, 356, 354, 355, 398,
25399, 400, 515, 516, 517, 506, 507, 508, 511, 532, 535, 538, 919, 922,
26925, 910, 913, 916, 900, 902, 979, 963, 965, 1042, 1026, 1028, 1087,
271071, 1088, 1180, 1179, 1124, 1216, 1215, 1241, 1288, 1287, 1232, 1229,
281226, 1259, 1256, 1253, 206, 203, 200, 197, 194, 191, 189, 187, 263,
29261, 250, 317, 315, 313, 353, 351, 352, 467, 396, 397, 503, 513, 514,
30575, 504, 505, 611, 524, 527, 530, 929, 932, 935, 848, 851, 854, 821,
31824, 901, 903, 905, 964, 966, 968, 1027, 1029, 1031, 1072, 1074, 1073,
321183, 1182, 1181, 1219, 1218, 1217, 1291, 1290, 1289, 1327, 1324, 1249,
331246, 1243, 214, 211, 208, 142, 139, 136, 106, 103, 188, 186, 184, 251,
34249, 247, 314, 312, 310, 350, 348, 349, 464, 465, 466, 500, 501, 502,
35572, 573, 574, 608, 609, 522, 525, 528, 927, 930, 933, 846, 849, 852,
36819, 822, 825, 827, 904, 906, 908, 967, 969, 971, 1030, 1032, 1034,
371075, 1077, 1076, 1186, 1185, 1184, 1222, 1221, 1220, 1294, 1293, 1292,
381330, 1329, 1326, 1323, 1248, 1245, 1242, 213, 210, 207, 141, 138, 135,
39105, 102, 100, 185, 183, 181, 248, 246, 244, 311, 309, 307, 347, 345,
40346, 461, 462, 463, 497, 498, 499, 569, 570, 571, 605, 606, 607, 610,
41523, 526, 529, 928, 931, 934, 847, 850, 853, 820, 823, 826, 810, 812,
42907, 891, 893, 970, 954, 956, 1033, 1017, 1019, 1078, 1062, 1079, 1171,
431170, 1187, 1207, 1206, 1223, 1279, 1278, 1295, 1315, 1314, 1331, 1328,
441325, 1250, 1247, 1244, 215, 212, 209, 143, 140, 137, 107, 104, 101,
4599, 97, 182, 180, 178, 245, 243, 241, 308, 306, 304, 344, 342, 343,
46458, 459, 460, 494, 495, 496, 566, 567, 568, 602, 603, 604, 647, 650,
47653, 656, 659, 662, 665, 857, 860, 863, 839, 842, 845, 830, 833, 811,
48813, 815, 892, 894, 896, 955, 957, 959, 1018, 1020, 1022, 1063, 1065,
491064, 1174, 1173, 1172, 1210, 1209, 1208, 1282, 1281, 1280, 1318, 1317,
501316, 1363, 1360, 1375, 1372, 1369, 1384, 1381, 1378, 133, 130, 127,
51124, 121, 118, 115, 112, 98, 96, 94, 179, 177, 175, 242, 240, 238, 305,
52303, 301, 332, 330, 331, 455, 456, 457, 491, 492, 493, 563, 564, 565,
53599, 600, 601, 644, 645, 648, 651, 654, 657, 660, 663, 855, 858, 861,
54837, 840, 843, 828, 831, 834, 836, 814, 816, 818, 895, 897, 899, 958,
55960, 962, 1021, 1023, 1025, 1066, 1068, 1067, 1177, 1176, 1175, 1213,
561212, 1211, 1285, 1284, 1283, 1321, 1320, 1319, 1366, 1365, 1362, 1359,
571374, 1371, 1368, 1383, 1380, 1377, 132, 129, 126, 123, 120, 117, 114,
58111, 109, 95, 93, 91, 176, 174, 172, 239, 237, 235, 302, 300, 298, 329,
59327, 328, 452, 453, 454, 488, 489, 490, 560, 561, 562, 596, 597, 598,
60641, 642, 643, 646, 649, 652, 655, 658, 661, 664, 856, 859, 862, 838,
61841, 844, 829, 832, 835, 756, 758, 817, 792, 794, 898, 882, 884, 961,
62945, 947, 1024, 1008, 1010, 1069, 1044, 1070, 1162, 1161, 1178, 1198,
631197, 1214, 1270, 1269, 1286, 1306, 1305, 1322, 1342, 1341, 1367, 1364,
641361, 1376, 1373, 1370, 1385, 1382, 1379, 134, 131, 128, 125, 122, 119,
65116, 113, 110, 108, 43, 92, 90, 79, 173, 171, 169, 236, 234, 232, 299,
66297, 295, 326, 324, 325, 449, 450, 451, 485, 486, 487, 557, 558, 559,
67593, 594, 595, 629, 639, 640, 638, 695, 698, 701, 668, 671, 674, 677,
68680, 683, 749, 752, 755, 740, 743, 746, 775, 777, 757, 759, 761, 793,
69795, 797, 883, 885, 887, 946, 948, 950, 1009, 1011, 1013, 1045, 1047,
701046, 1165, 1164, 1163, 1201, 1200, 1199, 1273, 1272, 1271, 1309, 1308,
711307, 1345, 1344, 1343, 1353, 1351, 1420, 1417, 1414, 1393, 1390, 1387,
721402, 1399, 1396, 34, 31, 28, 25, 22, 19, 62, 60, 44, 42, 40, 80, 78,
7376, 170, 168, 166, 233, 231, 229, 296, 294, 292, 341, 339, 340, 446,
74447, 448, 482, 483, 484, 554, 555, 556, 590, 591, 592, 626, 627, 628,
75636, 637, 693, 696, 699, 666, 669, 672, 675, 678, 681, 747, 750, 753,
76738, 741, 744, 774, 776, 778, 779, 760, 762, 764, 796, 798, 800, 886,
77888, 890, 949, 951, 953, 1012, 1014, 1016, 1054, 1057, 1048, 1168,
781167, 1166, 1204, 1203, 1202, 1276, 1275, 1274, 1312, 1311, 1310, 1348,
791347, 1346, 1355, 1354, 1352, 1350, 1419, 1416, 1413, 1392, 1389, 1386,
801401, 1398, 1395, 33, 30, 27, 24, 21, 18, 61, 59, 58, 41, 39, 37, 77,
8175, 73, 167, 165, 163, 230, 228, 226, 293, 291, 289, 338, 336, 337,
82443, 444, 445, 479, 480, 481, 551, 552, 553, 587, 588, 589, 623, 624,
83625, 634, 635, 684, 687, 694, 697, 700, 667, 670, 673, 676, 679, 682,
84748, 751, 754, 739, 742, 745, 787, 789, 791, 780, 765, 763, 769, 770,
85799, 801, 803, 889, 875, 864, 952, 936, 938, 1015, 1053, 1055, 1058,
861061, 1059, 1050, 1049, 1169, 1153, 1152, 1205, 1188, 1260, 1277, 1297,
871296, 1313, 1337, 1336, 1349, 1332, 1356, 1412, 1410, 1408, 1421, 1418,
881415, 1394, 1391, 1388, 1403, 1400, 1397, 35, 32, 29, 26, 23, 20, 65,
8963, 56, 55, 53, 38, 36, 48, 74, 72, 161, 164, 162, 152, 227, 225, 224,
90290, 288, 219, 335, 333, 334, 435, 441, 442, 440, 477, 478, 476, 549,
91550, 548, 585, 586, 615, 621, 622, 620, 631, 632, 633, 685, 688, 691,
92709, 706, 703, 718, 715, 712, 736, 733, 730, 727, 724, 721, 783, 785,
93788, 790, 781, 782, 766, 767, 771, 773, 802, 804, 873, 874, 865, 866,
94937, 939, 940, 942, 1056, 1060, 1052, 1051, 1157, 1156, 1155, 1154,
951190, 1189, 1262, 1261, 1299, 1298, 1339, 1338, 1334, 1333, 1358, 1357,
961411, 1409, 1406, 1404, 1424, 1427, 1430, 1433, 1436, 1439, 11, 14, 17,
972, 5, 8, 69, 67, 64, 57, 54, 52, 51, 50, 47, 89, 88, 84, 160, 159, 151,
98150, 148, 223, 222, 221, 218, 216, 433, 434, 437, 438, 439, 473, 474,
99475, 546, 547, 579, 583, 584, 614, 617, 618, 619, 630, 686, 689, 692,
100708, 705, 702, 717, 714, 711, 735, 732, 729, 726, 723, 720, 784, 786,
101768, 772, 805, 806, 808, 880, 877, 876, 867, 869, 871, 941, 943, 944,
1021160, 1159, 1158, 1194, 1192, 1191, 1263, 1265, 1264, 1302, 1301, 1300,
1031340, 1335, 1407, 1405, 1422, 1425, 1428, 1431, 1434, 1437, 9, 12, 15,
1040, 3, 6, 71, 68, 66, 49, 46, 45, 87, 83, 82, 158, 156, 149, 147, 146,
105144, 220, 217, 432, 436, 469, 470, 471, 472, 543, 545, 577, 578, 582,
106612, 613, 616, 710, 707, 704, 719, 716, 713, 737, 734, 731, 728, 725,
107722, 807, 809, 878, 879, 881, 868, 870, 872, 1196, 1195, 1193, 1268,
1081267, 1266, 1304, 1303, 1423, 1426, 1429, 1432, 1435, 1438, 10, 13, 16,
1091, 4, 7, 86, 85, 81, 157, 155, 154, 153, 145, 468, 540, 541, 542, 544,
110576, 580, 581, 70, 690 ];
111
112/*
113
114<a href="#" onMouseover="playsound(soundfile)">Example 1</a>
115<a href="#" onMouseover="playsound('different.wav')">Example 2</a>
116
117<div id="coolmenu" onMouseover="bindsound('A', soundfile, this)">
118
119<script type="text/javascript">
120
121//
122// JavaScript Sound effect- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
123// Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
124// This notice must stay intact for legal use
125//
126
127var soundfile="sidebar.wav" //path to sound file, or pass in filename directly into playsound()
128
129function playsound(soundfile){
130if (document.all && document.getElementById){
131document.getElementById("soundeffect").src="" //reset first in case of problems
132document.getElementById("soundeffect").src=soundfile
133}
134}
135
136function bindsound(tag, soundfile, masterElement){
137if (!window.event) return
138var source=event.srcElement
139while (source!=masterElement && source.tagName!="HTML"){
140if (source.tagName==tag.toUpperCase()){
141playsound(soundfile)
142break
143}
144source=source.parentElement
145}
146}
147
148</script>
149
150Function "bindsound()" accepts 3 parameters- 1) The tag name of the element to bind the sound to ("A" for <a>, "SPAN" for <span> etc), 2) the sound file to play, whether a variable or path to sound file, and finally, 3), the keyword "this", which should never be modified.
151
152// -----------------------
153<audio controls="controls" height="50px" width="100px">
154 <source src="song.mp3" type="audio/mpeg" />
155 <source src="song.ogg" type="audio/ogg" />
156<embed height="50px" width="100px" src="song.mp3" />
157</audio>
158// ------------------------
159
160*/
161function $(id) { return document.getElementById(id); }
162function trim(str) { return str.replace("/^\s\s*/", '').replace("/\s\s*$/", ''); }
163function valid(str) { if (str==undefined) return false; if (str.length==0) return false; return true;}
164function isSliding() { var z = $("body").getAttribute("data-visible"); return $("table"+z).offsetLeft!=0; }
165
166function cycleCol(el)
167{
168 var col = el.getAttribute("data-color");
169 col++;
170 col %= 31;
171 el.setAttribute("data-color", col);
172 if (col>16)
173 col = 31-col;
174 var hex = col.toString(16);
175 el.style.color = "#"+hex+"0"+hex+"0"+hex+"f";
176}
177
178/*
179function newWindow(newContent)
180{
181 if (document.referrer != "http://www.referringPageName.html")
182 return;
183
184 winContent = window.open(newContent,
185 'nextWin',
186 'right=0,top=20,width=350,height=350,toolbar=no,scrollbars=no,resizable=no');
187 }*/
188
189function onload()
190{
191 try { new XMLHttpRequest(); }
192 catch(e)
193 {
194 alert("Your browser doesn't support dynamic reload.");
195 return;
196 }
197
198 var name = location.hash.length==0 ? "fact" : location.hash.substr(1);
199
200 /*
201 alert("0 -- "+navigator.appCodeName+"\n"+
202 "1 -- "+navigator.appName+"\n"+
203 "2 -- "+navigator.appVersion+"\n"+
204 "3 -- "+navigator.platform+"\n"+
205 "4 -- "+navigator.userAgent);
206 */
207 loadPage(name, 0, 0);
208}
209
210function onresize()
211{
212 var z = $("body").getAttribute("data-visible");
213 doresize(z);
214}
215
216function loadPage(name, z, dz)
217{
218 var xmlPage = new XMLHttpRequest();
219 xmlPage.open('POST', name+'.table', true);
220 xmlPage.onload = function ()
221 {
222 if (xmlPage.status!=200)
223 {
224 alert("ERROR[0] - HTTP request '"+name+".table': "+xmlPage.statusText+" ["+xmlPage.status+"]");
225 //setTimeout("loadPage('+name+')", 5000);
226 /****** invalidate ******/
227 return;
228 }
229
230 buildPage(name, xmlPage.responseText, z, dz);
231 changePage(z, z+dz);
232
233 //changePage(name, xmlHttp.resposeText);
234 //slideOut(name, xmlHttp.responseText);
235 //displayPage(name, xmlHttp.responseText);
236 //onresize(true);
237 };
238
239 xmlPage.send(null);
240
241 location.hash = name;
242}
243
244function sendCommand(command, debug)
245{
246 var uri = "index.php?";
247 if (debug==true)
248 uri += "debug&";
249 uri += command;
250
251 var xmlCmd = new XMLHttpRequest();
252 xmlCmd.open('POST', uri, true);
253 xmlCmd.onload = function()
254 {
255 if (xmlCmd.status!=200)
256 {
257 alert("ERROR[1] - HTTP request: "+xmlCmd.statusText+" ["+xmlCmd.status+"]");
258 return;
259 }
260
261 if (xmlCmd.responseText.length==0)
262 {
263 alert("No proper acknowledgment of command execution received.");
264 return;
265 }
266
267 var txt = xmlCmd.responseText.split('\n');
268 switch (txt[0])
269 {
270 case "1": alert("dimctrl unreachable."); break;
271 case "2": /*success*/ break;
272 default: alert("Return code '"+txt[0]+"' unknown."); break;
273 }
274 if (txt.length>1)
275 alert(xmlCmd.responseText);
276 };
277 xmlCmd.send(null);
278}
279
280
281function buildPage(name, text, oldz, dz)
282{
283 var fname = dz==0 ? "fact" : $("table"+oldz).getAttribute("data-file");
284
285 var z = oldz + dz;
286
287 var lines = text.split('\n');
288
289 if (lines.length==0)
290 {
291 alert("buildPage - received data empty.");
292 return;
293 }
294
295 var table = $("table"+z);
296 if (table != undefined)
297 $("body").removeChild(table);
298
299 table = document.createElement("table");
300 table.setAttribute("class", "tborder");
301 table.id = "table"+z;
302 table.border = 0;
303 table.cellspacing = 0;
304 table.cellpadding = "6px";
305 table.width = "100%";
306 table.setAttribute("style", "overflow:hidden;position:fixed;top:0px;left:"+window.innerWidth+"px;");
307
308 // -----------------------------------------------------
309
310 var th = document.createElement("thead");
311 th.colSpan = 3;
312 th.width = "100%";
313 table.appendChild(th);
314
315 var htr = document.createElement("tr");
316 th.appendChild(htr);
317
318 var htd = document.createElement("td");
319 htd.setAttribute("class", "thead");
320 htd.colSpan = 3;
321 htd.width = "100%";
322 htr.appendChild(htd);
323
324 // -------------
325
326 var htab = document.createElement("table");
327 htab.width = "100%";
328 htd.appendChild(htab);
329
330 var hhtr = document.createElement("tr");
331 htab.appendChild(hhtr);
332
333 var htd0 = document.createElement("td");
334 var htd1 = document.createElement("td");
335 var htd2 = document.createElement("td");
336 var htd3 = document.createElement("td");
337 htd0.setAttribute("class", "tcell1");
338 htd1.setAttribute("class", "tcell2");
339 htd2.setAttribute("class", "tcell1");
340 htd2.setAttribute("width", "1px");
341 htd3.setAttribute("class", "tcell1");
342 htd3.setAttribute("width", "1px");
343 hhtr.appendChild(htd3);
344 hhtr.appendChild(htd0);
345 hhtr.appendChild(htd1);
346 hhtr.appendChild(htd2);
347
348 var div0 = document.createElement("div");
349 var div1 = document.createElement("div");
350 var div2 = document.createElement("div");
351 var div3 = document.createElement("div");
352 div0.setAttribute("style", "font-size:x-large;");
353 div2.setAttribute("class", "icon_white");
354 div2.setAttribute("onclick","this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('"+fname+"',"+z+","+(-dz)+");");
355 div2.setAttribute("style", "background-position:-396px 50%;");
356 div3.setAttribute("class", "icon_white");
357 div3.setAttribute("onclick","this.style.backgroundColor='rgba(0,0,0,0.77)'; loadPage('fact',"+z+","+(-z)+");");
358 div3.setAttribute("style", "background-position:-575px 50%;");
359
360 var sp0 = document.createElement("span");
361 var sp1 = document.createElement("span");
362 var sp2 = document.createElement("span");
363 sp0.id = "ldot" +z;
364 sp1.id = "title"+z;
365 sp2.id = "rdot" +z;
366 sp0.setAttribute("data-color", "3");
367 sp2.setAttribute("data-color", "3");
368 sp0.appendChild(document.createTextNode(" \u2022 "));
369 sp1.appendChild(document.createTextNode(lines[0]));
370 sp2.appendChild(document.createTextNode(" \u2022 "));
371
372 div0.appendChild(sp0);
373 div0.appendChild(sp1);
374 div0.appendChild(sp2);
375
376 div1.setAttribute("style", "font-size:small;");
377 div1.id = "reporttime"+z;
378 div1.appendChild(document.createTextNode("---"));
379
380 htd0.appendChild(div0);
381 htd1.appendChild(div1);
382 if (dz!=0/* && z+dz!=0*/)
383 htd2.appendChild(div2); // back
384 if (lines[0]!="FACT")
385 htd3.appendChild(div3); // home
386
387 // -----------------------------------------------------
388
389 var tbody = document.createElement("tbody");
390 table.appendChild(tbody);
391
392 // -----------------------------------------------------
393
394 var tf = document.createElement("tfoot");
395 table.appendChild(tf);
396
397 var ftr = document.createElement("tr");
398 tf.appendChild(ftr);
399
400 var ftd = document.createElement("td");
401 ftd.setAttribute("class", "tfoot");
402 ftd.width = "100%";
403 ftd.colSpan = 3;
404 ftr.appendChild(ftd);
405
406 var ftab = document.createElement("table");
407 ftab.width = "100%";
408 ftd.appendChild(ftab);
409
410 var ftd0 = document.createElement("td");
411 var ftd1 = document.createElement("td");
412
413 ftd0.setAttribute("class", "tcell1");
414 ftd1.setAttribute("class", "tcell2");
415
416 ftab.appendChild(ftd0);
417 ftab.appendChild(ftd1);
418
419 var fdiv0 = document.createElement("div");
420 var fdiv1 = document.createElement("div");
421
422 fdiv0.setAttribute("style", "font-size:x-large;");
423 fdiv1.setAttribute("style", "font-size:small;");
424 fdiv1.id = "localtime"+z;
425
426 fdiv0.appendChild(document.createTextNode("logbook"));
427 fdiv1.appendChild(document.createTextNode("loading..."));
428
429 ftd0.appendChild(fdiv0);
430 ftd1.appendChild(fdiv1);
431
432 $("body").appendChild(table);
433
434 var counter = 1;
435 for (var i=1; i<lines.length; i++)
436 {
437 lines[i] = trim(lines[i]);
438
439 if (lines[i].length==0 || lines[i][0] == '#')
440 continue;
441
442 var cols = lines[i].split(':');
443 if (cols.length != 3 && cols.length !=4)
444 {
445 alert("Wrong number of columns in line #"+i+" in '"+name+"': '"+lines[i]+"' N(cols)="+cols.length);
446 continue;
447 }
448
449 var check = cols[1].split("=");
450
451 if (check.length>1 && (check[0]=="camera" || check[0]=="hist"))
452 {
453 var data = cols[1].substring(check[0].length+1).split("/");
454
455 var tr = document.createElement("tr");
456 tr.setAttribute("class", "row");
457 //tr.setAttribute("style", "margin:0;padding:0;");
458
459 var td = document.createElement("td");
460 td.setAttribute("class", "container");
461 td.id = "container";
462 td.colSpan = 3;
463 tr.appendChild(td);
464
465 var canv = document.createElement("canvas");
466 canv.id = "canvas"+z;
467 canv.width = "1";
468 canv.height = "1";
469 //canv.onclick = function() { save(); }
470 canv.setAttribute("data-type", check[0]);
471 canv.setAttribute("data-file", data[0]);
472 canv.setAttribute("data-data", cols[1].substring(check[0].length+data[0].length+2));
473// canv.setAttribute("style", "display:none;");
474 td.appendChild(canv);
475
476 var img = document.createElement("img");
477 img.src = "dummy.png";//needed in firefox
478 img.id = "image"+z;
479 img.setAttribute("style", "width:1px;height:1px;display:none;");
480 td.appendChild(img);
481
482 tbody.appendChild(tr);
483 continue;
484 }
485
486 var tr = document.createElement("tr");
487 tr.setAttribute("class", "row");
488 if (valid(cols[0]))
489 tr.setAttribute("onclick", "this.style.background='#ccb'; loadPage('"+cols[0]+"',"+z+",-1);");
490 if (valid(cols[3]))
491 tr.setAttribute("onclick", "this.style.background='#ccb'; loadPage('"+cols[3]+"',"+z+",+1);");
492 //tr.setAttribute("id", cols[0]+"_row");
493
494 var td0 = document.createElement("td");
495 td0.setAttribute("class", "tcol0");
496 if (valid(cols[0]))
497 {
498 var sp = document.createElement("div");
499 sp.setAttribute("class", "icon_black");
500 sp.setAttribute("style", "background-position: -144px 50%;");
501 td0.appendChild(sp);
502 }
503 tr.appendChild(td0);
504
505 var td1 = document.createElement("td");
506 td1.setAttribute("class", "tcol1");
507 td1.width = "100%";
508 tr.appendChild(td1);
509
510 var td2 = document.createElement("td");
511 td2.setAttribute("class", "tcol2");
512 td2.width = "18px";
513 if (valid(cols[3]))
514 {
515 var sp = document.createElement("div");
516 sp.setAttribute("class", "icon_black");
517 sp.setAttribute("style", "background-position: -108px 50%;");
518 td2.appendChild(sp);
519 }
520 tr.appendChild(td2);
521
522 var tab = document.createElement("table");
523 tab.width = "100%";
524 td1.appendChild(tab);
525
526 var innertr = document.createElement("tr");
527 tab.appendChild(innertr);
528
529 var cell1 = document.createElement("td");
530 cell1.setAttribute("class", "tcell1");
531 //cell1.setAttribute("id", cols[0]+"_title");
532 cell1.appendChild(document.createTextNode(cols[1]));
533
534 var cell2 = document.createElement("td");
535 cell2.id = "data"+counter;
536 cell2.setAttribute("class", "tcell2");
537 cell2.setAttribute("data-form", cols[2]);
538 cell2.appendChild(document.createTextNode("---"));
539
540 innertr.appendChild(cell1);
541 innertr.appendChild(cell2);
542
543 tbody.appendChild(tr);
544
545 counter++;
546 }
547
548 // ---------------------------------------
549 if (debug == true)
550 {
551 tr = document.createElement("tr");
552 tr.setAttribute("class", "row");
553
554 td = document.createElement("td");
555 td.id = "debug"+z;
556 td.colSpan = 3;
557 tr.appendChild(td);
558
559 tbody.appendChild(tr);
560 }
561
562 // ---------------------------------------
563
564 table.setAttribute("data-file", name);
565 doresize(z);
566}
567
568function resizeimpl(z, cnt)
569{
570 // 393 / 482 488/482 / 200 200+482-488
571 var img = $("image"+z);
572 var canv = $("canvas"+z);
573 if (img == undefined || canv == undefined)
574 return;
575
576 var h = $("table"+z).offsetHeight;
577 if (h == 0)
578 return;
579
580 var W = window.innerWidth;
581 var H = window.innerHeight;
582
583/*
584 if (W==0 || H==0)
585 {
586 var w = $("table"+z).offsetWidth;
587 img.style.width = w+"px";
588 img.style.height= w+"px";
589
590 canv.width = w;
591 canv.height = w;
592 return;
593 }
594*/
595
596 var ih = H - h + parseInt(img.style.height, 10);
597
598 img.style.width = W +"px";
599 img.style.height= ih+"px";
600
601 canv.width = W;
602 canv.height = ih;
603
604 // ------ debug -----
605 if (debug == true)
606 {
607 $('debug'+z).innerHTML = "";
608 $('debug'+z).innerHTML += "|W="+W +"/"+H;
609 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;
610 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;
611 }
612
613 if ($("table"+z).offsetHeight == H || cnt==2)
614 {
615 // ------ debug -----
616 if (debug == true)
617 {
618 $('debug'+z).innerHTML = "";
619 $('debug'+z).innerHTML += "|W="+W +"/"+H;
620 $('debug'+z).innerHTML += "|H="+h+"/"+$("table"+z).offsetHeight+"/"+img.offsetHeight;
621 $('debug'+z).innerHTML += "|I="+img.style.height+"+"+H+"-"+h;
622 }
623 return;
624 }
625
626 resizeimpl(z, ++cnt);
627}
628
629function doresize(z)
630{
631 resizeimpl(z, 0);
632}
633
634var intervalSlide = null;
635
636function changePage(oldz, newz)
637{
638 // No page displayed yet
639 if (oldz==newz)
640 {
641 $("table"+newz).style.left="0px";
642 $("body").setAttribute("data-visible", newz);
643
644 doresize(0);
645
646 //setInterval(refresh_text, 1000);
647 //setInterval(refresh_graphics, 5000);
648
649 refresh_text();
650 refresh_graphics();
651 return;
652 }
653
654 var W = window.innerWidth;
655 if (W==0)
656 {
657 $("table"+newz).style.left="0px";
658 $("body").setAttribute("data-visible", newz);
659 $("body").removeChild($("table"+oldz));
660 return;
661 }
662
663 if (newz>oldz)
664 $("table"+newz).style.left = W+"px";
665 else
666 $("table"+newz).style.left = (-W-1)+"px";
667
668 //window.clearTimeout(timeoutText);
669 //window.clearTimeout(timeoutGraphics);
670
671 $("body").setAttribute("data-visible", newz);
672 intervalSlide = setInterval(function(){doShift(oldz,newz)}, 75);
673}
674
675function doShift(oldz, newz)
676{
677 var t0 = $("table"+oldz);
678 var t1 = $("table"+newz);
679
680 if (t0.style.display=="none")
681 {
682 clearInterval(intervalSlide);
683 $("body").removeChild(t0);
684 return;
685 }
686
687 var x0 = t0.offsetLeft;
688 var x1 = t1.offsetLeft;
689
690 var W = window.innerWidth;
691
692 if (newz<oldz)
693 {
694 x0 += W/5;
695 x1 += W/5;
696 }
697
698 if (newz>oldz)
699 {
700 x0 -= W/5;
701 x1 -= W/5;
702 }
703
704 if ((newz<oldz && x1>=0) || (newz>oldz && x1<=0))
705 {
706 t0.style.display="none";
707 x1 = 0;
708 }
709
710 t0.style.left = x0+"px";
711 t1.style.left = x1+"px";
712}
713
714var timeoutText = null;
715var timeoutGraphics = null;
716
717function refresh_text()
718{
719 var z=$("body").getAttribute("data-visible");
720 var table = $("table"+z);
721
722 // Is sliding or no file defined?
723 var fname = table.getAttribute("data-file");
724 if (isSliding() || !valid(fname))
725 {
726 // invalidate?
727 timeoutText = setTimeout(refresh_text, 1000);
728 return;
729 }
730
731 var xmlText = new XMLHttpRequest();
732 xmlText.open('POST', fname+'.txt', true);
733 xmlText.onload = function ()
734 {
735 if (xmlText.status!=200)
736 {
737 alert("ERROR[1] - HTTP request '"+fname+".txt': "+xmlText.statusText+" ["+xmlText.status+"]");
738 timeoutText = setTimeout(refresh_text, 10000);
739 return;
740 }
741
742 if (!isSliding())
743 {
744 cycleCol($("ldot"+z));
745 update_text(fname, xmlText.responseText);
746 }
747 timeoutText = setTimeout(refresh_text, 3000);
748 };
749 xmlText.send(null);
750}
751
752function strike(e, status)
753{
754 if (!e)
755 return;
756
757 if (!status)
758 e.style.textDecoration="line-through";
759 else
760 e.style.textDecoration="";
761}
762
763/*
764function gray(id, str)
765{
766 var e = $(id);
767 if (!e)
768 return;
769
770 if (valid(str))
771 {
772 e.style.color="#000";
773 e.style.textDecoration="";
774 }
775 else
776 {
777 e.style.color="#daa";
778 e.style.textDecoration="line-through";
779 }
780}
781*/
782var date0 = null;
783
784function update_text(fname, result)
785{
786 var z=$("body").getAttribute("data-visible");
787 var table = $("table"+z);
788
789 if (table.getAttribute("data-file") != fname)
790 return;
791
792 var tokens = result.split('\n');
793
794 // ----------------------------------------------------
795
796 var time = $("reporttime"+z);
797 var ltime = $("localtime"+z);
798
799 var date1 = new Date();
800
801 if (tokens[0].length!=13)
802 {
803 if (date0 != null)
804 strike(time, date0.getTime()+60000>date1.getTime());
805 // FIXME: Reset display to "---" values -- no connection
806 return;
807 }
808
809 var date2 = new Date();
810 date2.setTime(tokens[0]);
811
812 strike(time, date2.getTime()+60000>date1.getTime());
813
814 date0 = date2;
815
816 var utc = date0.toUTCString();
817
818 time.innerHTML =
819 "&#8226;&nbsp;"+utc.substr(utc.length-12, 8)+"&nbsp;UTC&nbsp;&#8226;"
820 ltime.innerHTML =
821 "&#8226;&nbsp;"+date1.toLocaleString()+"&nbsp;&#8226;";
822
823 // ----------------------------------------------------
824
825 var p = table.tBodies.length==3 ? 1 : 0;
826 var tbody = table.tBodies[p];
827
828 for (var line=1; line<tokens.length; line++)
829 {
830 if (tokens[line].length==0)
831 continue;
832
833 var c = tbody.rows[line-1].cells[1];
834 if (c == undefined)
835 continue;
836
837 var e = c.childNodes[0].rows[0].cells[1];
838 if (e == undefined)
839 continue;
840
841 var form = e.getAttribute("data-form");
842 if (form==undefined)
843 continue;
844
845 var cols = tokens[line].split('\t');
846 for (var col=1; col<cols.length; col++)
847 form = form.replace("\$"+(col-1), cols[col].length==0 ? "--" : cols[col]);
848
849 if (cols.length<=1)
850 form = "---";
851
852 var newe = document.createElement("div");
853 newe.innerHTML = form;
854 e.replaceChild(newe, e.lastChild);
855
856 e.parentNode.parentNode.parentNode.parentNode.style.background=cols[0];
857 }
858}
859
860// http://billmill.org/static/canvastutorial/index.html
861// http://www.netmagazine.com/tutorials/learning-basics-html5-canvas
862// http://www.alistapart.com/articles/responsive-web-design/
863
864function refresh_graphics()
865{
866 var z = $("body").getAttribute("data-visible");
867
868 var canvas = $("canvas"+z);
869
870 // Is sliding or no data file defined?
871 var fname = canvas==null ? "" : canvas.getAttribute("data-file");
872 if (isSliding() || !valid(fname))
873 {
874 // invalidate?
875 timeoutGraphics = setTimeout(refresh_graphics, 1000);
876 return;
877 }
878
879 var xmlGfx = new XMLHttpRequest();
880 xmlGfx.open('POST', fname, true);
881 xmlGfx.onload = function()
882 {
883 if (xmlGfx.status!=200)
884 {
885 alert("ERROR[2] - Request '"+fname+"': "+xmlGfx.statusText+" ["+xmlGfx.status+"]");
886 timeoutGraphics = setTimeout(refresh_graphics, 10000);
887 //****** invalidate ******
888 return;
889 }
890
891 if (!isSliding())
892 {
893 cycleCol($("rdot"+z));
894 process_eventdata(xmlGfx.responseText);
895 }
896 timeoutGraphics = setTimeout(refresh_graphics, 5000)
897 };
898 xmlGfx.send(null);
899}
900
901
902function hueToRGB(hue)
903{
904 hue /= 3;
905 hue %= 6;
906
907 if (hue<1) return parseInt(255*hue, 10);
908 if (hue<3) return parseInt(255, 10);
909 if (hue<4) return parseInt(255*(4-hue), 10);
910
911/*
912 if (hue<1*5/4) return parseInt(255*hue*4/5);
913 if (hue<2*5/4) return parseInt(255);
914 if (hue<3*5/4) return parseInt(255*(3*5/4-hue)*4/5);
915*/
916/*
917 if (hue<1.5) return parseInt(255*hue/1.5);
918 if (hue<3.0) return parseInt(255);
919 if (hue<4.5) return parseInt(255*(4.5-hue)/1.5);
920*/
921 return 0.
922}
923
924function hueToHex(flt)
925{
926 var s = hueToRGB(flt).toString(16);
927 return s.length==2 ? s : "0"+s;
928}
929
930function HLStoRGB(hue)
931{
932 hue *= 14;
933
934 var sr = hueToHex(20-hue);
935 var sg = hueToHex(14-hue);
936 var sb = hueToHex(26-hue);
937
938 return sr+sg+sb;
939}
940
941
942function color(col)
943{
944 if (col==65533)
945 col = 0;
946
947 var hue = col/128;
948 return HLStoRGB(hue);
949}
950
951function toHex(str, idx)
952{
953 var ch = str[idx].toString(16);
954 return ch.length==2 ? ch : "0"+ch;
955}
956
957function drawHex(ctx, x, y, col)
958{
959 ctx.fillStyle = "#"+color(col);
960
961 ctx.save();
962
963 ctx.translate(x, y);
964 ctx.scale(1/2, 1/3);
965
966 ctx.beginPath();
967 ctx.moveTo( 1, 1);
968 ctx.lineTo( 0, 2);
969 ctx.lineTo(-1, 1);
970 ctx.lineTo(-1, -1);
971 ctx.lineTo( 0, -2);
972 ctx.lineTo( 1, -1);
973 ctx.fill();
974
975 ctx.restore();
976}
977
978function drawDisc(ctx, x, y, r, col)
979{
980 ctx.fillStyle = "#"+color(col);
981
982 ctx.save();
983
984 ctx.translate(x, y);
985
986 ctx.beginPath();
987 ctx.arc(0, 0, r, 0, Math.PI*2, true);
988 ctx.fill();
989
990 ctx.restore();
991}
992
993function beginDrawCam(scale)
994{
995 var z = $("body").getAttribute("data-visible");
996 var canv = $("canvas"+z);
997
998 var w = Math.min(canv.width/scale, canv.height/scale);
999
1000 var ctx = canv.getContext("2d");
1001
1002 ctx.save();
1003 ctx.translate(canv.width/2, canv.height/2);
1004 ctx.scale(w*2, w*2);
1005
1006 return ctx;
1007}
1008
1009/**
1010 * @constructor
1011 */
1012function position(s, ring, i)
1013{
1014 switch (s)
1015 {
1016 case 1: this.x = ring - i*0.5; this.y = + i; break;
1017 case 2: this.x = ring*0.5 - i; this.y = ring ; break;
1018 case 3: this.x = -ring*0.5 - i*0.5; this.y = ring - i; break;
1019 case 4: this.x = -ring + i*0.5; this.y = - i; break;
1020 case 5: this.x = -ring*0.5 + i; this.y = -ring ; break;
1021 case 0: this.x = ring*0.5 + i*0.5; this.y = -ring + i; break;
1022 }
1023 this.d = function() { return this.x*this.x + this.y*this.y*3/4; }
1024}
1025
1026function drawFullCam(data)
1027{
1028 if (data.length!=40 && data.length!=160 && data.length!=320 && data.length!=1440)
1029 {
1030 alert("Camera - Received data has invalid size ("+data.length+"b)");
1031 return;
1032 }
1033
1034 var div = map.length/data.length;
1035 var off = data.length==320 ? 0.2 : 0;
1036
1037 var ctx = beginDrawCam(83);
1038 // ctx.rotate(Math.PI/3);
1039
1040 ctx.scale(1, Math.sqrt(3)/2);
1041 ctx.translate(-0.5, 0);
1042
1043 drawHex(ctx, 0, 0, data.charCodeAt(parseInt(map[0]/div+off, 10)));
1044
1045 var cnt = 1;
1046 for (var ring=1; ring<24; ring++)
1047 {
1048 for (var s=0; s<6; s++)
1049 {
1050 for (var i=1; i<=ring; i++)
1051 {
1052 var pos = new position(s, ring, i);
1053 if (pos.d() - pos.x > 395.75)
1054 continue;
1055
1056 var p = parseInt(map[cnt]/div+off, 10);
1057
1058 drawHex(ctx, pos.x, pos.y, data.charCodeAt(p));
1059 cnt++;
1060 }
1061 }
1062 }
1063
1064 drawHex(ctx, 7, -22, data.charCodeAt(parseInt(map[1438]/div+off, 10)));
1065 drawHex(ctx, 7, 22, data.charCodeAt(parseInt(map[1439]/div+off, 10)));
1066
1067 ctx.restore();
1068}
1069
1070function drawCam(data)
1071{
1072 var ctx = beginDrawCam(27);
1073 ctx.rotate(Math.PI/6);
1074 ctx.scale(1, Math.sqrt(3)/2);
1075
1076 drawHex(ctx, 0, 0, data.charCodeAt(0));
1077
1078 var cnt = 1;
1079 for (var ring=1; ring<=7; ring++)
1080 {
1081 for (var s=0; s<6; s++)
1082 {
1083 for (var i=1; i<=ring; i++)
1084 {
1085 var pos = new position(s, ring, i);
1086 if (pos.d() > 44)
1087 continue;
1088
1089 if (ring==7)
1090 {
1091 if (i==6 && (s==0 || s==3))
1092 continue;
1093 if (i==1 && (s==1 || s==4))
1094 continue;
1095 }
1096
1097 drawHex(ctx, pos.x, pos.y, data.charCodeAt(cnt++));
1098 }
1099 }
1100 }
1101
1102 ctx.restore();
1103}
1104
1105function drawCamLegend(canv, min, max)
1106{
1107 var unit = canv.getAttribute("data-data");//.split("/");
1108 if (unit.length>0)
1109 unit = " "+unit;
1110
1111 var v0 = parseFloat(min);
1112 var v1 = parseFloat(max);
1113
1114 var diff = v1-v0;
1115
1116 var cw = canv.width;
1117 var ch = canv.height;
1118
1119 var ctx = canv.getContext("2d");
1120
1121 ctx.font = "8pt Arial";
1122 ctx.textAlign = "right";
1123 ctx.textBaseline = "top";
1124
1125 for (var i=0; i<11; i++)
1126 {
1127 ctx.strokeStyle = "#"+color(16*i);
1128 ctx.strokeText((v0+diff*i/10)+unit, cw-5, 120-i*12);
1129 }
1130}
1131
1132function drawGraph(canv, min, max, data)
1133{
1134 var unit = canv.getAttribute("data-data");//.split("/");
1135 if (unit.length>0)
1136 unit = " "+unit;
1137
1138 var cw = canv.width;
1139 var ch = canv.height;
1140
1141 var ctx = canv.getContext("2d");
1142
1143 var dw = 3; // tick width
1144
1145 var fs = 8; // font size
1146
1147 ctx.font = fs+"pt Arial";
1148 ctx.textAlign = "right";
1149
1150 var dim0 = ctx.measureText(min+unit);
1151 var dim1 = ctx.measureText(max+unit);
1152
1153 var tw = Math.max(dim0.width, dim1.width)+dw+2;
1154
1155 var ml = 5+tw; // margin left
1156 var mr = 10; // margin right
1157
1158 var mt = fs/2+5; // margin top
1159 var mb = fs/2+4; // margin bottom
1160
1161 var nx = 20;
1162 var ny = 10;
1163
1164 var w = cw-ml-mr;
1165 var h = ch-mt-mb;
1166
1167 ctx.strokeStyle = "#666";
1168
1169 // --- data ---
1170 ctx.beginPath();
1171 ctx.moveTo(ml, ch-mb-data.charCodeAt(0)/128*h);
1172 for (var i=1; i<data.length; i++)
1173 ctx.lineTo(ml+w/(data.length-1)*i, ch-mb-data.charCodeAt(i)/128*h);
1174
1175 // --- finalize data ---
1176 ctx.lineTo(cw-mr, ch-mb);
1177 ctx.lineTo(ml, ch-mb);
1178 ctx.fillStyle = "#"+color(100);
1179 ctx.stroke();
1180 ctx.fill();
1181
1182 ctx.beginPath();
1183
1184 // --- grid ---
1185
1186 ctx.strokeStyle = "#eee";
1187
1188 for (var i=1; i<=nx; i++)
1189 {
1190 ctx.moveTo(ml+w/nx*i, ch-mb);
1191 ctx.lineTo(ml+w/nx*i, mt);
1192 }
1193 for (var i=0; i<ny; i++)
1194 {
1195 ctx.moveTo(ml, mb+h/ny*i);
1196 ctx.lineTo(ml+w, mb+h/ny*i);
1197 }
1198 ctx.stroke();
1199 ctx.closePath();
1200 ctx.beginPath();
1201
1202 ctx.strokeStyle = "#000";
1203
1204 // --- axes ---
1205 ctx.moveTo(ml, mt);
1206 ctx.lineTo(ml, ch-mb);
1207 ctx.lineTo(cw-mr, ch-mb);
1208
1209 for (var i=1; i<=nx; i++)
1210 {
1211 ctx.moveTo(ml+w/nx*i, ch-mb-dw);
1212 ctx.lineTo(ml+w/nx*i, ch-mb+dw);
1213 }
1214 for (var i=0; i<ny; i++)
1215 {
1216 ctx.moveTo(ml-dw, mb+h/ny*i);
1217 ctx.lineTo(ml+dw, mb+h/ny*i);
1218 }
1219 ctx.stroke();
1220 ctx.closePath();
1221
1222 ctx.textBaseline = "bottom";
1223 ctx.strokeText(min+unit, ml-dw-2, ch-1);
1224
1225 ctx.textBaseline = "top";
1226 ctx.strokeText(max+unit, ml-dw-2, 0);
1227}
1228
1229var gfxtime0 = null;
1230
1231function process_eventdata(result)
1232{
1233 if (result.length==0)
1234 return;
1235
1236 var z = $("body").getAttribute("data-visible");
1237 var canv = $("canvas"+z);
1238 if (canv == undefined)
1239 return;
1240
1241 var type = canv.getAttribute("data-type");
1242
1243 var ctx = canv.getContext("2d");
1244 ctx.clearRect(0, 0, canv.width, canv.height);
1245
1246 var data = result.split('\n');
1247 if (result.length<3)
1248 return;
1249
1250 var l = data[0].length+1+data[1].length+1;
1251
1252 switch (type)
1253 {
1254 //case "camera": drawCam(result); break;
1255 case "hist":
1256 drawGraph(canv, data[0], data[1], result.substr(l));
1257 break;
1258 case "camera":
1259 drawFullCam(result.substr(l));
1260 drawCamLegend(canv, data[0], data[1]);
1261 break;
1262 }
1263
1264 var date = new Date();
1265 if (gfxtime0 != null && gfxdate0.getTime()+60000>date.getTime())
1266 {
1267 ctx.fillStyle = "rgba(255, 255, 255, 0.75)";
1268 ctx.fillRect(0, 0, canv.width, canv.height);
1269 }
1270
1271 //$("image"+z).src = canv.toDataURL("image/png");
1272}
1273
1274function save()
1275{
1276 var z = $("body").getAttribute("data-visible");
1277
1278 var canvas = $("canvas"+z);
1279 var img = canvas.toDataURL("image/png");
1280
1281 img = img.replace("image/png", "image/octet-stream");
1282
1283 document.location.href = img;
1284}
1285
1286window['onload'] = onload;
Note: See TracBrowser for help on using the repository browser.