-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-ScriptScheduler.js
executable file
·82 lines (71 loc) · 2.66 KB
/
MMM-ScriptScheduler.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
/* global Module */
/* MMM-ScriptScheduler.js
*
* Magic Mirror
* Module: MMM-VolumeControl
* MIT Licensed.
*
* See README.md for details on this.
*/
Module.register("MMM-ScriptScheduler", {
getStyles: function() {
return [ "font-awesome.css" ];
},
getDom: function() {
var imageDiv = document.createElement("div");
this.config.schedules.forEach(function(schedule, index) {
if (schedule.icon) {
var icon = document.createElement("span");
icon.id = "scriptsched_" + index;
icon.className = "fa-stack fa-lg";
icon.style.display = "none";
icon.style.margin = "20px";
icon.style.color = schedule.color;
if (schedule.icon) {
icon.innerHTML = "<i class='fa fa-circle fa-stack-2x'></i>" +
"<i class='fa fa-" + schedule.icon + " fa-fw fa-stack-1x fa-inverse'></i>";
}
imageDiv.appendChild(icon);
} else if (schedule.imageurl) {
var img = document.createElement("img");
img.id = "scriptsched_" + index;
img.src = schedule.imageurl;
img.style.display = "none";
img.style.margin = "20px";
imageDiv.appendChild(img);
}
});
return imageDiv;
},
notificationReceived: function(notification, payload, sender) {
switch(notification) {
case "DOM_OBJECTS_CREATED":
this.sendSocketNotification("SCHEDULE", this.config);
break;
case "SCRIPTSCHEDULER_ALL_OFF":
for (var i = 0; i < this.config.schedules.length; i++)
this.setImageVisible(i, false);
break;
case "SCRIPTSCHEDULER_SHOW_ICON":
for (var i = 0; i < this.config.schedules.length; i++)
this.setImageVisible(i, false);
this.setImageVisible(payload.index, true);
break;
}
},
socketNotificationReceived: function(notification, payload) {
switch(notification) {
case "UPDATE":
for (var i = 0; i < this.config.schedules.length; i++)
this.setImageVisible(i, false);
this.setImageVisible(payload.index, true);
break;
}
},
setImageVisible: function(index, shouldBeVisible) {
var id = "scriptsched_" + index;
var span = document.getElementById(id);
if (!!span) // may not be a span if no imageurl or icon in config.js for this schedule
span.style.display = shouldBeVisible ? "block" : "none";
}
});