-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathwebsage.js
6152 lines (5656 loc) · 206 KB
/
websage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
//
// --------------------------------------------------------------------------------------------------------------
// This script looks for tagged objects inside an SVG file and animate them according to realtime tagged values.
// Real time values are obtained by requesting JSON from a realtime webserver.
//
// DEPENDENCIES : opc-codes.js, util.js, jquery.js, jquery.ui, core.js, shortcut.js, messages.js, config_viewers.js (must be include before this script)
// {json:scada} - Copyright 2020 - Ricardo L. Olsen
// Derived from OSHMI/Open Substation HMI - Copyright 2008-2020 - Ricardo L. Olsen
/*jslint browser: true, bitwise: true, devel: true */
/*jslint white: true */
/*jslint sloppy: true */
/*jslint plusplus: true */
/*jslint eqeq: true */
/*jslint continue: true */
/*global opener: false, self: false */
/*global $: false, Core: false, Titles: false, Imgs: false, Msg: false, LoadFavicon: false, shortcut: false */
/*global L: true, V: true, S: true, F: true, T: true, TAGS: true, NPTS: true, SUBS:true, BAYS:true, DCRS: true, ANOTS: true, DNOTES: true, STONS: true, STOFS: true, Data: true, NUM_VAR: true, NUM_VAR_ANT: true, ALARMBEEP: true */
/*global INVTAGS: true, T: true, SVGDoc: true, SVGSnap: true, NPTO: true, ID: true, ESTACAO: true */
/*global DESC: true, ST_ON: true, ST_OFF: true, CNPTO: true, CID: true, CDESC: true, CST_ON: true, CST_OFF: true */
/*global LIMSUPS: true, LIMINFS: true, LIMS: true, LIMI: true, HISTER: true, ALRIN: true, ANOT: true, VLNOR: true, ESTALM: true, UNIDADE: true */
/*global SIMULACAO: true, ComandoAck: true, ANIMA: true, CLICK_POSX: true, CLICK_POSY: true, WebSAGE: true */
/*global optgroup: true, optval: true, opttxt: true, PNTServer: true, TimePNTServer: true, ScreenViewer_RefreshTime: true */
/*global ScreenViewer_Background: true, ScreenViewer_ToolbarColor: true, ScreenViewer_RelationColor: true */
/*global ScreenViewer_TagFillColor: true, ScreenViewer_TagStrokeColor: true, ScreenViewer_TagInhAlmFillColor: true, ScreenViewer_TagInhAlmStrokeColor: true */
/*global ScreenViewer_DateColor: true, ScreenViewer_TimeMachineDateColor: true, ScreenViewer_TimeMachineBgColor: true, ScreenViewer_AlmBoxTableColor: true */
/*global ScreenViewer_AlmBoxGridColor: true, ScreenViewer_BarBreakerSwColor: true, ScreenViewer_ShowScreenNameTB: true */
// Server provide values
var L = []; // Event list
var V = []; // Point values
var S = []; // Point values as String
var F = []; // Point quality flags
var T = []; // Alarm time tags
var TAGS = []; // Point tag names
var NPTS = []; // Point numbers by tags names
var SUBS = []; // Grouping level 1 of points (e.g. substation)
var BAYS = []; // Grouping level 2 of points (e.g. bay)
var DCRS = []; // Point description
var ANOTS = []; // Point blocking annotation
var DNOTES = []; // Point documental annotations
var STONS = []; // On status texts
var STOFS = []; // Off status texts
var LIMSUPS = []; // Analog superior limits for points
var LIMINFS = []; // Analog inferior limits for points
var INVTAGS = []; // List of invalid tags (not found)
var NUM_VAR = 0; // Number of digital values changed
var ALARMBEEP = 0; // Indicates the presence of beep alarm
var NUM_VAR_ANT = 0; // Last state of NUM_VAR variable
var SVGDoc = null; // SVG Document
var SVGSnap = null; // SVG Snap surface object
var hvalues = [];
var ScreenTagFilter = ""; // Filter for alarm box and pinned annotations
// Variables to communicate with point access/command dialogs
var NPTO = 0,
ID,
ESTACAO,
MODULO,
DESC,
ST_ON,
ST_OFF,
VAL_STR,
CHANDLE,
CNPTO,
CID,
CDESC,
CST_ON,
CST_OFF,
LIMS,
LIMI,
HISTER,
ALRIN,
VLNOR,
ESTALM,
UNIDADE,
SIMULACAO = 0;
var ComandoAck = ""; // texto para confirmação do comando
var ANIMA = 0x01; // controla nível de animações (máscara de: 0x00=sem animação, 0x01=seleção, 0x02=etiqueta).
var CLICK_POSX = 0;
var CLICK_POSY = 0;
var BEEP_POINTKEY = -1;
var CNTUPDATES_POINTKEY = -2;
// carrega uma imagem no elemento
function LoadImage(elem, imgpath) {
elem.setAttributeNS("http://www.w3.org/1999/xlink", "href", imgpath);
}
// Remove todas as animações
function RemoveAnimate(elem) {
var i;
if (elem === null) {
return;
}
i = 0;
while (i < elem.childNodes.length) {
if (
elem.childNodes[i].nodeName == "animate" ||
elem.childNodes.nodeName == "animateTransform" ||
elem.childNodes.nodeName == "animateMotion"
) {
elem.removeChild(elem.childNodes[i]);
i = 0;
} else {
i++;
}
}
}
// Permite criar uma animação em SVG
// window.Animate( thisobj, "animate", {'attributeName': 'ry', 'from': 0, 'to': 10, 'fill': 'freeze', 'repeatCount': 5, 'dur': 5 } );
// window.Animate( thisobj, 'animate', {'attributeName': 'width', 'from': 45, 'to': 55, 'repeatCount':5,'dur': 1 });
function Animate(elem, animtype, params) {
var k, animation;
animation = document.createElementNS("http://www.w3.org/2000/svg", animtype);
for (k in params) {
if (params.hasOwnProperty(k)) {
animation.setAttributeNS(null, k, params[k]);
}
}
setTimeout(function() {
elem.appendChild(animation);
if (typeof animation.beginElement != "undefined") {
animation.endElement();
animation.beginElement();
}
}, 100);
}
function ShowHideTranslate(idorobj, xd, yd) {
var obj, svgdoc;
xd = xd || 0;
yd = yd || 0;
svgdoc = document.getElementById("svgdiv").firstElementChild;
if (svgdoc === null) {
return;
}
if (typeof idorobj === "object") obj = idorobj;
else obj = svgdoc.getElementById(idorobj);
if (obj === null) {
return;
}
if (obj.style.display === "none") {
obj.style.display = "block";
} else {
obj.style.display = "none";
}
if (typeof obj.inittransform === "undefined") {
obj.inittransform = obj.getAttributeNS(null, "transform");
}
if (obj.inittransform === null) {
obj.inittransform = "";
}
if (xd != 0 || yd != 0)
obj.setAttributeNS(
null,
"transform",
obj.inittransform +
" translate(" +
parseFloat(xd) +
" " +
parseFloat(yd) +
")"
);
}
var WebSAGE = {
RemoveAnimate: RemoveAnimate,
Animate: Animate,
ShowHideTranslate: ShowHideTranslate,
LoadImage: LoadImage,
g_docAnnotationServer: DocAnnotationServer,
g_isInkscape: false,
g_DirTelas: "./",
g_nponto_sup: 0,
g_win_cmd: {},
g_win_1stdraw: 0,
g_wait_win: 0,
g_timerID: 0,
g_timeoutFalhaID: 0,
g_timeoutSlideID: 0,
g_data_ant: "",
g_timeOutRefresh: 1000 * ScreenViewer_RefreshTime, // tempo de refresh dos dados
g_timeOutFalha: 30000, // tempo para falha dos dados, caso servidor não responda
g_toutID: 0,
g_toutStatusID: 0,
g_blinktimerID: 0,
g_blinkperiod: 1000,
g_blinkcnt: 0,
g_blinkList: [], // lista objetos piscantes digitais
g_blinkListAna: [], // lista objetos piscantes analógicos
g_blinkListOld: [], // lista objetos piscantes digitais (anterior)
g_blinkListAnaOld: [], // lista objetos piscantes analógicos (anterior)
C: [], // para as cores das medidas
T: [], // formato numérico das medidas
Pass: 0, // conta as chamadas de CallServer
g_showValsInterval: 0,
g_seltela: 0,
g_inicio: 1,
g_MostraQualAna: 0,
g_Evento: {}, // evento
g_travaInfo: 0,
g_tminfoID: 0,
g_cntTentativaInfo: 0,
g_hidetoolbar: 0,
g_timeOutPreview: 1500, // tempo para mostrar preview de tela linkada
g_timerPreviewID: 0, // timer para mostrar preview de tela linkada
g_retnok: "????", // return value when value can not be obtained
// tamanhos para zoom/pan
g_zpX: 0,
g_zpY: 0,
g_zpW: 0,
g_zpH: 0,
g_obj_onclick:
"{ /*CLICK_POSX=evt.clientX;CLICK_POSY=evt.clientY;*/ var pt=parseInt('PONTO'); if (isNaN(pt)) pt=window.NPTS['PONTO']; if( evt.ctrlKey || evt.which == 2 ) { window.WebSAGE.reconhece(pt); } else { window.WebSAGE.janelaInfo(pt); } }",
g_titulo_janela: "",
g_indSelPonto: -1, // indice do objeto selecionado pelo teclado
g_destaqList: [], // lista de pontos que possuem objetos associados que podem ser selecionados pelo teclado
g_loadtime: 0,
g_timeshift: 0, // control calls for historic data plot
g_idprefixes: [], // id prefixes to aggregate to TAGs when TAG in form $$#1_POINT_TAG (set from script or passed to by URL parameter IDPREFIX1, IDPREFIX2,...)
// Passa ao servidor uma lista de pontos cujos valores devem ser retornados
// o retorno vem na variável global V que é um array com chave numero do ponto com o valor do ponto
// Ex: V[8056]
lstpnt: "",
InkSage: [],
SetIniExtended: function() {},
SetExeExtended: function() {},
// Return value from tag or number
getValue: function(tagornumber) {
return V[tagornumber] || V[NPTS[tagornumber]] || 0;
},
// Return the string value from tag or number
getStringValue: function(tagornumber) {
return S[tagornumber] || S[NPTS[tagornumber]] || "";
},
// Return flags from tag or number
getFlags: function(tagornumber) {
var f = F[tagornumber] || F[NPTS[tagornumber]];
if (isNaN(f))
return 0xa0 | (WebSAGE.getValue(tagornumber) == 0 ? 0x02 : 0x01);
else return f;
},
// Return inferior limit from tag or number
getInfLim: function(tagornumber) {
return LIMINFS[tagornumber] || LIMINFS[NPTS[tagornumber]] || 0;
},
// Return superior limit from tag or number
getSupLim: function(tagornumber) {
return LIMSUPS[tagornumber] || LIMSUPS[NPTS[tagornumber]] || 0;
},
// Return substation from tag or number
getSubstation: function(tagornumber) {
return SUBS[tagornumber] || SUBS[NPTS[tagornumber]] || "";
},
// Return bay from tag or number
getBay: function(tagornumber) {
return BAYS[tagornumber] || BAYS[NPTS[tagornumber]] || "";
},
// Return description from tag or number
getDescription: function(tagornumber) {
return DCRS[tagornumber] || DCRS[NPTS[tagornumber]] || "";
},
// Return alarm time from tag or number
getTime: function(tagornumber) {
return T[tagornumber] || T[NPTS[tagornumber]] || "";
},
// Return annotation
getAnnotation: function(tagornumber) {
return ANOTS[tagornumber] || ANOTS[NPTS[tagornumber]] || "";
},
init_svg: function(filename) {
if (filename == "") {
WebSAGE.init();
document.getElementById("loader").style.display = "none";
return;
}
try {
fetchTimeout(filename, 3000)
.then(function(response) {
return response;
})
.then(response => response.text())
.then(data => {
//var ini = performance.now();
document.getElementById("svgdiv").innerHTML = data;
$(document.getElementById("svgdiv").children[0]).css(
"background-color",
VisorTelas_BackgroundSVG
);
document.getElementById("svgdiv").children[0].id = "svgid";
WebSAGE.init();
document.getElementById("loader").style.display = "none";
//console.log(performance.now()-ini);
var titu =
WebSAGE.g_seltela.options[WebSAGE.g_seltela.options.selectedIndex]
.text;
var pos = titu.indexOf("[");
if (pos <= 0) {
pos = 100;
}
titu = titu.substring(0, pos);
pos = titu.indexOf("{");
if (pos <= 0) {
pos = 100;
}
titu = titu.substring(0, pos);
titu = titu.replace(new RegExp("[\\s.]+$", "g"), "");
WebSAGE.g_titulo_janela =
titu +
" - " +
Msg.NomeVisorTelas +
" - " +
Msg.NomeProduto +
" - " +
Msg.VersaoProduto;
// document.title = "."; // necessário devido a um bug do chromium!
document.title = WebSAGE.g_titulo_janela;
// coloca o nome da tela na toolbar, se configurado
if (ScreenViewer_ShowScreenNameTB) {
$("#NOME_TELA").text(titu + " ");
$("#NOME_TELA").css("display", "");
}
})
.catch(function(error) {
console.log(error);
});
} catch (E) {
console.log(E.message);
}
},
// Process the list of screens
lista_telas: function(filename, indscr) {
var i, t, elOptNew, elSel, titu, pos, nohs, textolink, tmp, idtela;
WebSAGE.g_seltela = document.getElementById("SELTELA");
if (optionhtml !== "") {
$("#SELTELA").html(optionhtml);
} else
for (i = 0; i < optval.length; i++) {
elSel = document.getElementById("SELTELA");
elOptNew = document.createElement("option");
elOptNew.text = opttxt[i];
elOptNew.value = optval[i];
if (typeof optgroup[i] === "string") elOptNew.optg = optgroup[i];
if (typeof optfilt[i] === "string") {
elOptNew.filtroalmbox = optfilt[i];
} else {
elOptNew.filtroalmbox = "";
}
try {
elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
} catch (ex) {
elSel.add(elOptNew); // IE only
}
}
for (i = 0; i < WebSAGE.g_seltela.length; i++) {
if (indscr > 0 && indscr == i) {
// quando o parâmetro da URL INDTELA for um número, abre a tela correspondente
WebSAGE.g_seltela.selectedIndex = i;
return WebSAGE.g_seltela.options[i].value;
}
if (WebSAGE.g_seltela.options[i].value == filename) {
if (typeof WebSAGE.g_seltela.options[i].filtroalmbox != "undefined")
if (WebSAGE.g_seltela.options[i].filtroalmbox != "")
if (document.getElementById("almiframe").src == "") {
document.getElementById("almiframe").src =
"almbox.html?SUBST=" +
WebSAGE.g_seltela.options[i].filtroalmbox;
document.getElementById("almiframe").style.display = "";
}
// seleciona tela aberta no combo box
WebSAGE.g_seltela.selectedIndex = i;
break;
}
}
// prepara os links para as telas
try {
// Links para telas
if (SVGDoc != null) {
nohs = SVGDoc.getElementsByTagName("a");
for (i = 0; i < nohs.length; i++) {
textolink = nohs
.item(i)
.getAttributeNS("http://www.w3.org/1999/xlink", "href");
// mata o link original
nohs
.item(i)
.removeAttributeNS("http://www.w3.org/1999/xlink", "href");
nohs
.item(i)
.removeAttributeNS("http://www.w3.org/1999/xlink", "type");
nohs
.item(i)
.removeAttributeNS("http://www.w3.org/1999/xlink", "actuate");
nohs
.item(i)
.removeAttributeNS("http://www.w3.org/1999/xlink", "show");
nohs
.item(i)
.removeAttributeNS("http://www.w3.org/1999/xlink", "href");
for (t = 0; t < WebSAGE.g_seltela.length; t++) {
if (WebSAGE.g_seltela.options[t].value == "../svg/" + textolink) {
nohs
.item(i)
.setAttributeNS(
null,
"onclick",
"window.WebSAGE.g_seltela.selectedIndex=" +
t +
"; window.document.fmTELA.submit();"
);
if (nohs.item(i).style != null) {
nohs.item(i).style.cursor = "pointer";
}
}
}
}
// onde houver um texto ou grupo com id igual a nome de tela, linkar
nohs = [];
tmp = SVGDoc.getElementsByTagName("text");
for (i = 0; i < tmp.length; i++) {
nohs.push(tmp.item(i));
}
tmp = SVGDoc.getElementsByTagName("g");
for (i = 0; i < tmp.length; i++) {
nohs.push(tmp.item(i));
}
for (i = 0; i < nohs.length; i++) {
if (nohs[i].id != undefined) {
idtela = nohs[i].id;
// faz um trimleft dos caracteres espaço e '+' para permitir multiplos link para uma mesma tela
idtela = idtela.replace(/^[ \+]+/, "");
if (
idtela.substr(0, 3) == "PNT" ||
idtela.substr(0, 3) == "NPT" ||
idtela == ""
) {
// estou procurando nome de tela e não numero de ponto
continue;
}
for (t = 0; t < WebSAGE.g_seltela.length; t++) {
if (
WebSAGE.g_seltela.options[t].value == idtela ||
WebSAGE.g_seltela.options[t].value == "../svg/" + idtela ||
WebSAGE.g_seltela.options[t].value ==
"../svg/" + idtela + ".svg"
) {
nohs[i].setAttributeNS(
null,
"onclick",
"window.WebSAGE.g_seltela.selectedIndex=" +
t +
"; window.document.fmTELA.submit();"
);
if (nohs[i].style != null) {
nohs[i].style.cursor = "pointer";
}
}
}
}
}
}
} catch (err) {
$("#SP_STATUS").text(err.name + ": " + err.message + " [1]");
document.getElementById("SP_STATUS").title = err.stack;
}
return "";
},
tooltipRelac: function(item, pnt) {
if (pnt == 0 || pnt == 99999 || pnt == 99989 || item.hasTooltip) return;
// dá um tempo para receber as descrições, etc. do ponto
setTimeout(function() {
if (item.hasTooltip || item.parentNode.hasTooltip) return;
var p = pnt;
if (isNaN(parseInt(pnt))) p = NPTS[pnt];
var tooltip = document.createElementNS(
"http://www.w3.org/2000/svg",
"title"
);
tooltip.textContent =
BAYS[p] + "-" + DCRS[p] + "\n" + "Id: " + TAGS[p] + "\n" + "Pnt: " + p;
item.appendChild(tooltip);
item.hasTooltip = 1;
}, 5000);
},
// cria atalhos para as telas com base na letra entre { } no texto da tela
atalhosTela: function() {
var i, pos;
for (i = 0; i < WebSAGE.g_seltela.length; i++) {
pos = WebSAGE.g_seltela.options[i].text.indexOf("{");
if (pos != -1) {
shortcut.add(
"",
function(e) {
// procura a tela com o keycode do evento e abre
for (var i = 0; i < WebSAGE.g_seltela.length; i++) {
var pos = WebSAGE.g_seltela.options[i].text.indexOf("{");
if (
pos != -1 &&
WebSAGE.g_seltela.options[i].text.charCodeAt(pos + 1) ==
e.keyCode
) {
WebSAGE.g_seltela.selectedIndex = i;
document.fmTELA.submit();
}
}
},
{
type: "keydown",
propagate: false,
target: document,
keycode: WebSAGE.g_seltela.options[i].text.charCodeAt(pos + 1)
}
);
}
}
},
// função auxiliar para escrever dados na janela de comando pelo id do objeto
writeElemByIdWnd: function(win, id, txt) {
if ("$" in win)
win.$("#" + id).text(txt);
},
// add point to the list of points to be requested from the server, removing special codes like !ALM !TMP
acrescentaPontoLista: function(tag) {
tag = tag.trim();
if (tag.indexOf("#") === 0 || tag.indexOf("%") === 0 || tag == "") return 0;
/*
if ( tag.indexOf('ALM') === 0 ||
tag.indexOf('TMP') === 0 )
{
tag = tag.substr( 3 ).trim();
}
else
*/
if (
tag.indexOf("!ALM") === 0 ||
tag.indexOf("!TMP") === 0 ||
tag.indexOf("!ALR") === 0 ||
tag.indexOf("!ALR") === 0 ||
tag.indexOf("!TAG") === 0 ||
tag.indexOf("!DCR") === 0
) {
tag = tag.substr(4).trim();
} else if (
tag.indexOf("!SLIM") === 0 ||
tag.indexOf("!ILIM") === 0 ||
tag.indexOf("!STON") === 0
) {
tag = tag.substr(5).trim();
} else if (tag.indexOf("!STOFF") === 0 || tag.indexOf("!STVAL") === 0) {
tag = tag.substr(6).trim();
}
if (isNaN(parseInt(tag))) {
if (typeof NPTS[tag] !== "undefined") {
tag = NPTS[tag];
} else {
if (tag.indexOf("!") === 0)
// must not begin with a '!' or '#'
return 0;
}
}
if (
WebSAGE.lstpnt.indexOf("," + tag + ",") < 0 &&
!(WebSAGE.lstpnt.indexOf(tag + ",") === 0)
) {
// se já não tem na lista, acrescenta | append if not already in the list
WebSAGE.lstpnt = WebSAGE.lstpnt + tag + ",";
}
return tag;
},
// busca dados do servidor e prepara chamada temporizada de showValsCmd para
janelaInfo: function(nponto) {
// faz um bloqueio de 1,5s
if (WebSAGE.g_travaInfo) {
return;
}
WebSAGE.g_travaInfo = 1;
setTimeout("WebSAGE.g_travaInfo=0", 1500);
if (nponto != 0) {
WebSAGE.g_nponto_sup = nponto;
WebSAGE.g_cntTentativaInfo = 3;
} else {
WebSAGE.g_cntTentativaInfo--;
}
if (WebSAGE.g_cntTentativaInfo <= 0) {
return;
}
LIMS = 0;
LIMI = 0;
HISTER = 0;
ALRIN = 0;
if (NPTO != 0) {
WebSAGE.escondeDestaqPonto(NPTO);
}
NPTO = 0;
CNPTO = 0;
CHANDLE = "";
ID = "";
DESC = "";
if (typeof WebSAGE.g_win_cmd.window == "object")
if (WebSAGE.g_win_cmd.window) {
// fecha janela info
WebSAGE.g_win_cmd.window.close();
}
setTimeout(WebSAGE.showValsInfo0, 50);
},
// busca dado do ponto tempo real
showValsInfo0: function() {
var arrpnt = [WebSAGE.g_nponto_sup];
WebSAGE.getRealtimeData( arrpnt, true,
prop => {
NPTO = WebSAGE.g_nponto_sup;
VAL_STR = S[WebSAGE.g_nponto_sup];
ESTACAO = SUBS[WebSAGE.g_nponto_sup];
ST_ON = STONS[WebSAGE.g_nponto_sup];
ST_OFF = STOFS[WebSAGE.g_nponto_sup];
UNIDADE = prop.unit;
DESC = BAYS[WebSAGE.g_nponto_sup] + "-" + DCRS[WebSAGE.g_nponto_sup];
LIMS = LIMSUPS[WebSAGE.g_nponto_sup];
LIMI = LIMINFS[WebSAGE.g_nponto_sup];
HISTER = prop.hysteresis;
ALRIN = prop.alarmDisabled;
CNPTO = prop.commandOfSupervised;
ID = TAGS[WebSAGE.g_nponto_sup];
setTimeout(WebSAGE.showValsInfo1, 50);
}
);
},
// Abre uma janela popup com dados sobre o ponto
showValsInfo1: function() {
// esconde o destaque anterior, imediatamente
WebSAGE.escondeDestaqPonto(WebSAGE.g_destaqList[WebSAGE.g_indSelPonto]);
// abre nova janela, dá um tempo e vai preencher os dados da nova janela em outra funcao
// (para dar tempo de abrir a janela)
WebSAGE.g_win_1stdraw = 1;
WebSAGE.g_win_cmd = window.open(
"dlginfo.html",
"wsinfo",
"dependent=yes,height=620,width=400,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes"
);
WebSAGE.g_tminfoID = setTimeout("WebSAGE.g_win_cmd.close()", 6000);
WebSAGE.g_wait_win = 0; // contador para esperar abrir a janela
// showValsInfo2 será chamado pela própria nova janela aberta em onload
},
// Mostra os dados sobre o ponto em janela popup
showValsInfo2: function() {
try {
// test for dialog window opened
if (
NPTO === 0 ||
typeof WebSAGE.g_win_cmd.window !== "object" ||
WebSAGE.g_win_cmd.window === null ||
typeof WebSAGE.g_win_cmd.window.closed === "undefined" ||
WebSAGE.g_win_cmd.window.closed ||
!WebSAGE.g_win_cmd.document.getElementById("TABULAR")
) {
return; // give up
}
// on closing info window, cancel point and hide object highlight
WebSAGE.g_win_cmd.addEventListener("unload", function() {
WebSAGE.escondeDestaqPonto(NPTO);
NPTO = 0;
})
// janela carregada
var se = ESTACAO;
se = se + "-";
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"VALOR_SUP",
roundnum(WebSAGE.getValue(NPTO), 4) + " " + UNIDADE
);
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"ESTADO_SUP",
WebSAGE.getValue(NPTO)==0?ST_ON:ST_OFF
);
var SQ = "";
var Q = WebSAGE.getFlags(NPTO);
/*
if ((Q & 0x03) == 0x00) {
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"ESTADO_SUP",
Msg.QDPIntermed + " (" + Msg.EstadoAtual + ")"
);
} else if ((Q & 0x03) == 0x03) {
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"ESTADO_SUP",
Msg.QDPInvalido + " (" + Msg.EstadoAtual + ")"
);
} else if (V[NPTO] & (0x01 != 0)) {
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"ESTADO_SUP",
ST_OFF + " (" + Msg.EstadoAtual + ")"
);
} // não zero é off
else {
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"ESTADO_SUP",
ST_ON + " (" + Msg.EstadoAtual + ")"
);
} // zero é on
*/
if (Q & 0x80) {
SQ += Msg.QFalhado + " ";
}
if (Q & 0x10) {
SQ += Msg.QSubst + " ";
}
if ((Q & 0x0c) == 0x04) {
SQ += Msg.QCalculado + " ";
} else if ((Q & 0x0c) == 0x0c) {
SQ += Msg.QManual + " ";
} else if ((Q & 0x0c) == 0x08) {
SQ += Msg.QNuncaAtu + " ";
}
if (Q & 0x100) {
SQ += Msg.QAlarmado + " ";
}
//if ( Q&0x200 )
// SQ += Msg.QAnotacao+' ';
if (Q & 0x400) {
SQ += Msg.QAlmInib + " ";
}
if (Q & 0x800) {
SQ += Msg.QNaoNormal + " ";
}
if (Q & 0x1000) {
SQ += Msg.QCongelado + " ";
}
if (SQ == "") {
SQ = Msg.QNormal + " ";
}
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"QUALIF",
Msg.Qualific + ": " + SQ
);
if (WebSAGE.g_win_1stdraw) {
// escreve parâmetros só na primeira vez que abriu a janela
clearTimeout(WebSAGE.g_tminfoID);
WebSAGE.g_win_1stdraw = 0;
WebSAGE.writeElemByIdWnd(WebSAGE.g_win_cmd, "NPONTO_SUP", NPTO + ":" + ID);
WebSAGE.writeElemByIdWnd(WebSAGE.g_win_cmd, "DESCR_SUP", se + DESC);
WebSAGE.writeElemByIdWnd(
WebSAGE.g_win_cmd,
"SPCMDINTERTRAV",
Titles.SPCMDINTERTRAV
);
WebSAGE.g_win_cmd.document.getElementById("TABULAR").style.display = "";
//WebSAGE.g_win_cmd.document.getElementById("TABULAR").href="tabular.html?SELMODULO="+ID.substring(0,9);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("TABULAR"),
"click",
WebSAGE.tabular
);
if (ID.charAt(21) == "M") {
// Manual não apresenta opção de inibir
WebSAGE.g_win_cmd.document.getElementById("DIVINIB").style.display =
"none";
}
WebSAGE.g_win_cmd.document.getElementById("CURVAS").style.display = "";
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("CURVAS"),
"click",
WebSAGE.curvas
);
if (Q & 0x20) {
// mostra parâmetros de limites só para pontos analógicos
WebSAGE.g_win_cmd.document.getElementById(
"TENDENCIAS"
).style.display = "";
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("TENDENCIAS"),
"click",
WebSAGE.tendencias
);
WebSAGE.g_win_cmd.document.getElementById("VALOR_HID").style.display =
"";
WebSAGE.g_win_cmd.document.getElementById("LIMCTRLS").style.display =
"";
WebSAGE.g_win_cmd.document.getElementById("LIMSUP").value = LIMS;
WebSAGE.g_win_cmd.document.getElementById("LIMINF").value = LIMI;
WebSAGE.g_win_cmd.document.getElementById("HISTER").value = HISTER;
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("LIMSUP"),
"blur",
WebSAGE.writeProperties
);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("LIMINF"),
"blur",
WebSAGE.writeProperties
);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("HISTER"),
"blur",
WebSAGE.writeProperties
);
if (ID.charAt(21) == "M" || SIMULACAO == 1 || SIMULACAO == 2) {
// permite alterar valor de ponto manual
WebSAGE.g_win_cmd.document.getElementById(
"DIVALTVALOR"
).style.display = "";
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("CBALTVALOR"),
"click",
function() {
WebSAGE.g_win_cmd.document.getElementById(
"CBALTVALOR"
).style.display = "none";
WebSAGE.g_win_cmd.document.getElementById(
"NOVOVALOR"
).style.display = "";
}
);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("NOVOVALOR"),
"blur",
WebSAGE.writeProperties
);
}
}
WebSAGE.g_win_cmd.document.getElementById(
"ANOTACAO"
).value = ANOTS[NPTO].replace(/\|\^/g, "\n");
WebSAGE.g_win_cmd.document.getElementById("CBALRIN").checked =
ALRIN != "0";
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("CBALRIN"),
"click",
WebSAGE.writeProperties
);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("ANOTACAO"),
"blur",
WebSAGE.writeProperties
);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("CBBLKCMD"),
"click",
WebSAGE.writeProperties
);
if (!(Q & 0x20)) {
// ponto digital
WebSAGE.g_win_cmd.document.getElementById(
"ESTADO_HID"
).style.display = "";
if (ID.charAt(21) == "M" || SIMULACAO == 1 || SIMULACAO == 2) {
// permite alterar valor de ponto manual
WebSAGE.g_win_cmd.document.getElementById(
"DIVALTVALOR"
).style.display = "";
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("CBALTVALOR"),
"click",
function() {
WebSAGE.g_win_cmd.document.getElementById(
"CBALTVALOR"
).style.display = "none";
WebSAGE.g_win_cmd.document.getElementById(
"DIVALTVALORDIG"
).style.display = "";
}
);
WebSAGE.g_win_cmd.document.getElementById(
"rbNovoValor"
).nextSibling.data = ST_ON;
WebSAGE.g_win_cmd.document.getElementById(
"rbNovoValorOff"
).nextSibling.data = ST_OFF;
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("rbNovoValor"),
"click",
WebSAGE.writeProperties
);
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("rbNovoValorOff"),
"click",
WebSAGE.writeProperties
);
}
}
// torna visível botão de comandar, caso haja comando associado
if (CNPTO != 0) {
WebSAGE.g_win_cmd.document.getElementById("COMANDAR").style.display =
"";
Core.addEventListener(
WebSAGE.g_win_cmd.document.getElementById("COMANDAR"),
"click",
function(){WebSAGE.g_win_cmd.close();WebSAGE.prejanelaComando();}
);
}
WebSAGE.mostraDestaqPonto(NPTO);
// get nonblocking annotation
WebSAGE.g_win_cmd.document.getElementById("ANOTACAODOC").value = DNOTES[NPTO];
Core.addEventListener(