/* global NotificationFx */
/* Magic Mirror
* Module: alert
*
* By Paul-Vincent Roll https://paulvincentroll.com/
* MIT Licensed.
*/
Module.register("alert", {
alerts: {},
defaults: {
effect: "slide", // scale|slide|genie|jelly|flip|bouncyflip|exploader
alert_effect: "jelly", // scale|slide|genie|jelly|flip|bouncyflip|exploader
display_time: 3500, // time a notification is displayed in seconds
position: "center",
welcome_message: false // shown at startup
},
getScripts() {
return ["notificationFx.js"];
},
getStyles() {
return ["notificationFx.css", "font-awesome.css", this.file(`./styles/${this.config.position}.css`)];
},
getTranslations() {
return {
bg: "translations/bg.json",
da: "translations/da.json",
de: "translations/de.json",
en: "translations/en.json",
es: "translations/es.json",
fr: "translations/fr.json",
hu: "translations/hu.json",
nl: "translations/nl.json",
ru: "translations/ru.json"
};
},
start() {
Log.info(`Starting module: ${this.name}`);
if (this.config.effect === "slide") {
this.config.effect = `${this.config.effect}-${this.config.position}`;
}
if (this.config.welcome_message) {
const message = this.config.welcome_message === true ? this.translate("welcome") : this.config.welcome_message;
this.showNotification({ title: this.translate("sysTitle"), message });
}
},
showNotification(message) {
let msg = "";
if (message.title) {
msg += "" + message.title + "";
}
if (message.message) {
if (msg !== "") {
msg += "
";
}
msg += "" + message.message + "";
}
new NotificationFx({
message: msg,
layout: "growl",
effect: this.config.effect,
ttl: message.timer !== undefined ? message.timer : this.config.display_time
}).show();
},
showAlert(params, sender) {
let image = "";
//Set standard params if not provided by module
if (typeof params.timer === "undefined") {
params.timer = null;
}
if (typeof params.imageHeight === "undefined") {
params.imageHeight = "80px";
}
if (typeof params.imageUrl === "undefined" && typeof params.imageFA === "undefined") {
params.imageUrl = null;
} else if (typeof params.imageFA === "undefined") {
image = "
";
} else if (typeof params.imageUrl === "undefined") {
image = "
";
}
//Create overlay
const overlay = document.createElement("div");
overlay.id = "overlay";
overlay.innerHTML += '