-
Notifications
You must be signed in to change notification settings - Fork 2
/
widget.js
109 lines (90 loc) · 3.91 KB
/
widget.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
jlab = jlab || {};
jlab.wedm = jlab.wedm || {};
jlab.wedm.classToObserverMap = jlab.wedm.classToObserverMap || {};
jlab.wedm.classToObserverMap['ActiveRectangle'] = 'jlab.wedm.ShapePvObserver';
jlab.wedm.classToObserverMap['ActiveCircle'] = 'jlab.wedm.ShapePvObserver';
jlab.wedm.classToObserverMap['ActiveLine'] = 'jlab.wedm.ShapePvObserver';
jlab.wedm.classToObserverMap['ActiveArc'] = 'jlab.wedm.ShapePvObserver';
jlab.wedm.ShapePvObserverInit = function () {
jlab.wedm.ShapePvObserver = function (id, pvSet) {
jlab.wedm.PvObserver.call(this, id, pvSet);
};
jlab.wedm.ShapePvObserver.prototype = Object.create(jlab.wedm.PvObserver.prototype);
jlab.wedm.ShapePvObserver.prototype.constructor = jlab.wedm.ShapePvObserver;
jlab.wedm.ShapePvObserver.prototype.handleInfo = function (info) {
jlab.wedm.PvObserver.prototype.handleInfo.call(this, info);
var $obj = $("#" + this.id),
$shape = $obj.find("rect, ellipse, path");
/*Disconnected Shape always has disconnectedAlarmColor border and transparent fill regardless of fillAlarm or lineAlarm*/
if (!info.connected) {
$shape.attr("fill", "transparent");
$shape.attr("stroke", "transparent");
}
};
jlab.wedm.ShapePvObserver.prototype.handleAlarmUpdate = function (update) {
var $obj = $("#" + this.id),
sevr = update.value,
$shape = $obj.find("rect, ellipse, path"),
fillAlarm = $obj.attr("data-fill-alarm") === "true",
lineAlarm = $obj.attr("data-line-alarm") === "true",
invalid = false;
$obj.attr("data-sevr", sevr);
$obj[0].classList.remove("waiting-for-state");
if (typeof sevr !== 'undefined') {
if (sevr === 0) { // NO_ALARM
if (fillAlarm) {
$shape.attr("fill", jlab.wedm.noAlarmColor);
}
if (lineAlarm) {
$shape.attr("stroke", jlab.wedm.noAlarmColor);
}
} else if (sevr === 1) { // MINOR
if (fillAlarm) {
$shape.attr("fill", jlab.wedm.minorAlarmColor);
}
if (lineAlarm) {
$shape.attr("stroke", jlab.wedm.minorAlarmColor);
}
} else if (sevr === 2) { // MAJOR
if (fillAlarm) {
$shape.attr("fill", jlab.wedm.majorAlarmColor);
}
if (lineAlarm) {
$shape.attr("stroke", jlab.wedm.majorAlarmColor);
}
} else if (sevr === 3) { // INVALID
invalid = true;
}
} else {
invalid = true;
}
if (invalid) {
if (fillAlarm) {
$shape.attr("fill", jlab.wedm.invalidAlarmColor);
}
if (lineAlarm) {
$shape.attr("stroke", jlab.wedm.invalidAlarmColor);
}
}
};
jlab.wedm.ShapePvObserver.prototype.handleColorUpdate = function (update) {
var $obj = $("#" + this.id),
$shape = $obj.find("rect, ellipse, path"),
color,
stmt,
lineRuleIndex = $obj.attr("data-line-color-rule"),
fillRuleIndex = $obj.attr("data-fill-color-rule");
$obj[0].classList.remove("waiting-for-state");
if (lineRuleIndex !== undefined) {
stmt = jlab.wedm.colorRules[lineRuleIndex];
color = jlab.wedm.evalColorExpr.call(this, stmt, update.value);
$shape.attr("stroke", color);
}
if (fillRuleIndex !== undefined) {
stmt = jlab.wedm.colorRules[fillRuleIndex];
color = jlab.wedm.evalColorExpr.call(this, stmt, update.value);
$shape.attr("fill", color);
}
};
};
jlab.wedm.initPvObserver('jlab.wedm.ShapePvObserver', 'jlab.wedm.PvObserver');