-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidgets.js
66 lines (61 loc) · 2.45 KB
/
widgets.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
class widgetFactory {
constructor(id, item, childType, icon, clickHandler) {
this.id = id;
this.displayName = item.displayName;
this.typeName = item.typeName.toLowerCase();
this.instanceId = item.id;
this.smipData = item;
this.childType = childType;
this.icon = icon;
this.statusId = null;
this.clickHandler = clickHandler;
};
build(self) {
var newWidget = document.createElement("li");
newWidget.id = this.id;
newWidget.className = "widget machine " + this.typeName;
newWidget.widget = self;
var widgetTitle = document.createElement("p");
widgetTitle.innerText = this.displayName;
newWidget.appendChild(widgetTitle);
var widgetIcon = document.createElement("img");
widgetIcon.src = this.icon;
if (config.app.logLevel != "trace")
widgetIcon.addEventListener("error", this.loadDefaultImage);
widgetIcon.height = 64;
widgetIcon.width = 64;
newWidget.appendChild(widgetIcon);
newWidget.addEventListener("click", this.clickHandler);
if (this.typeName == this.childType) {
var widgetStatus = document.createElement("li");
widgetStatus.id = this.id.replace("station", "status");
widgetStatus.className = "machine_status";
widgetStatus.innerText = "<No Status>";
newWidget.appendChild(widgetStatus);
}
return newWidget;
};
select(items) {
for (var i=0;i<items.childNodes.length;i++) { //unselect everything
var widget = items.childNodes[i].widget;
document.getElementById(widget.id).classList.remove("selected");
}
//select the specified item
document.getElementById(this.id).classList.add("selected");
};
deSelect() {
document.getElementById(this.id).classList.remove("selected");
};
loadDefaultImage() {
logger.info("Widget icon could not be found for specified type. Substituting default image.");
this.src='unknown.png';
};
update(item) {
document.getElementById(this.id).classList.remove("updating");
var refresh = Math.floor(Math.random()*(4-1+1)+1);
refresh = 1000 + (refresh * 100);
setTimeout(() => {
document.getElementById(this.id).classList.add("updating");
}, refresh);
};
}