-
Notifications
You must be signed in to change notification settings - Fork 3
/
MMM-bringList.js
75 lines (75 loc) · 3.32 KB
/
MMM-bringList.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
/* global Module */
Module.register("MMM-bringList", {
defaults: {
listname: "",
email: "",
password: "",
columns: 4,
maxrows: 4,
updateInterval: 60000,
verboseLogging: false
},
listData: null,
requiresVersion: "2.1.0",
start: function () {
this.sendSocketNotification("bringList-REGISTER", this.config);
},
socketNotificationReceived: function (notification, payload) {
if (notification === "bringList-LISTUPDATE") {
// set dataNotification
if (payload.listName.toLowerCase() === this.config.listname.toLowerCase()) {
this.listData = payload;
this.updateDom(100);
}
}
if (notification == "ALL_MODULES_STARTED") {
this.updateDom();
}
},
getDom: function () {
var htmlTemplate = "\n\t\t<div class=\"bringitemcontainer\">\n\t\t\t<div class=\"bringitem\">\n\t\t\t\t<div class=\"itemupper\">\n\t\t\t\t\t<div class=\"indicators-container\"></div>\n\t\t\t\t\t<div class=\"image-container\">\n\t\t\t\t\t\t<img src=\"{iconUrl}\" class=\"itemimage\"/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"indicators-container\"></div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"itemlower\">\n\t\t\t\t\t<div class=\"itemtext-name bright\">{itemName}</div>\n\t\t\t\t\t<div class=\"itemtext-spec normal\">{itemSpec}</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>";
var self = this;
// create element wrapper for show into the module
var wrapper = document.createElement("div");
// If this.dataRequest is not empty
var width = (self.config.columns * 101) + 1;
var height = (self.config.maxrows * 119);
var lastrowstartpercent = Math.round(((self.config.maxrows - 1) / self.config.maxrows) * 100);
var contentHtml = '<div style="max-width:' + width + 'px;max-height:' + height + 'px;position:relative;overflow-y:hidden;">';
if (self.listData) {
var listContent = self.listData;
listContent.items.forEach(function (element) {
var itemHtml = htmlTemplate
.replace(/\{iconUrl\}/g, element.imagePath)
.replace(/\{itemName\}/g, element.localName)
.replace(/\{itemSpec\}/g, element.specification);
contentHtml += itemHtml;
});
wrapper.innerHTML = contentHtml + ("<div style=\"clear:both\"></div>\n\t\t\t\t<div style=\"position:absolute;top:0px;left:0px;height:100%;width:100%;background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0) " + lastrowstartpercent + "%,rgba(0,0,0,1) 100%);\"></div> \n\t\t\t</div>");
}
return wrapper;
},
getScripts: function () {
return [];
},
getStyles: function () {
return [
"mmm-bring-list.css",
];
},
// Load translations files
getTranslations: function () {
//FIXME: This can be load a one file javascript definition
//return {
// en: "translations/en.json",
// es: "translations/es.json"
//};
return false;
},
suspend: function () {
this.sendSocketNotification("bringList-SUSPEND", this.config);
},
resume: function () {
this.sendSocketNotification("bringList-REGISTER", this.config);
}
});